about summary refs log tree commit diff
path: root/modules/user/aszlig
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2021-07-06 08:59:40 +0200
committeraszlig <aszlig@nix.build>2021-07-09 17:48:25 +0200
commit709e45c2a8c231201d3f67c6a954021ca2a5f796 (patch)
treed8bc11e17029507d31b4df38b56a65d340669d27 /modules/user/aszlig
parentff940a210a4676bac305ff0ea8eed5a933d51443 (diff)
modules/git: Switch to RFC-0042
In RFC-0042[1], the structural settings are exposed via a "settings"
attribute, while in our module it's called "config". To make this less
ambiguous (since there is already a "config" attribute passed to
modules) and more in line with best practices, I renamed it accordingly.

Additionally, the configuration file is now generated via *defining*
another (read-only) option, which can be used by other modules to
reference the path. The previous way this has been done was using the
apply attribute to mkOption, which makes it really hard to access the
original attributes for these settings.

[1]: https://git.io/JcXmU

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'modules/user/aszlig')
-rw-r--r--modules/user/aszlig/profiles/workstation/default.nix2
-rw-r--r--modules/user/aszlig/programs/git/default.nix66
2 files changed, 40 insertions, 28 deletions
diff --git a/modules/user/aszlig/profiles/workstation/default.nix b/modules/user/aszlig/profiles/workstation/default.nix
index b8724668..3914ab2d 100644
--- a/modules/user/aszlig/profiles/workstation/default.nix
+++ b/modules/user/aszlig/profiles/workstation/default.nix
@@ -78,7 +78,7 @@ in {
     vuizvui.user.aszlig.programs.mpv.enable = true;
 
     vuizvui.user.aszlig.programs.git.enable = true;
-    vuizvui.user.aszlig.programs.git.config = {
+    vuizvui.user.aszlig.programs.git.settings = {
       color.ui = "auto";
       merge.tool = "vimdiff3";
       user.email = "aszlig@nix.build";
diff --git a/modules/user/aszlig/programs/git/default.nix b/modules/user/aszlig/programs/git/default.nix
index 8965e5dc..e809077b 100644
--- a/modules/user/aszlig/programs/git/default.nix
+++ b/modules/user/aszlig/programs/git/default.nix
@@ -4,30 +4,6 @@ let
   inherit (lib) types;
   cfg = config.vuizvui.user.aszlig.programs.git;
 
-  genConf = attrs: let
-    escStr = s: "\"${lib.escape [ "\"" "\\" ] s}\"";
-    mkVal = v: if lib.isBool v && v  then "true"
-          else if lib.isBool v && !v then "false"
-          else escStr (toString v);
-    mkLine = key: val: "${key} = ${mkVal val}";
-
-    joinLines = lib.concatStringsSep "\n";
-    filterNull = lib.filterAttrs (lib.const (v: !(isNull v)));
-
-    mkSection = sect: subsect: vals: ''
-      [${sect}${lib.optionalString (subsect != null) " ${escStr subsect}"}]
-      ${joinLines (lib.mapAttrsToList mkLine (filterNull vals))}
-    '';
-
-    mkConf = sect: content: let
-      subs = lib.filterAttrs (lib.const lib.isAttrs) content;
-      nonSubs = lib.filterAttrs (lib.const (s: !lib.isAttrs s)) content;
-      maybePlain = lib.optional (nonSubs != {});
-      plainSects = lib.singleton (mkSection sect null nonSubs);
-    in lib.mapAttrsToList (mkSection sect) subs ++ maybePlain plainSects;
-
-    lines = lib.flatten (lib.mapAttrsToList mkConf attrs);
-  in pkgs.writeText "gitconfig" (joinLines lines);
 
   gitPatched = pkgs.gitFull.overrideAttrs (git: {
     makeFlags = let
@@ -41,9 +17,15 @@ in {
   options.vuizvui.user.aszlig.programs.git = {
     enable = lib.mkEnableOption "Git";
 
-    config = lib.mkOption {
-      description = "System-wide default config for Git";
+    configFile = lib.mkOption {
+      type = types.path;
+      readOnly = true;
+      description = ''
+        The path to the system-wide configuration file.
+      '';
+    };
 
+    settings = lib.mkOption {
       type = let
         scalar = types.oneOf [ types.bool types.int types.str ];
         section = types.either (types.attrsOf scalar) scalar;
@@ -56,11 +38,41 @@ in {
         guitool.foobar.noconsole = true;
       };
 
-      apply = genConf;
+      description = ''
+        System-wide Git options as described in <citerefentry>
+          <refentrytitle>git-config</refentrytitle>
+          <manvolnum>1</manvolnum>
+        </citerefentry>.
+      '';
     };
   };
 
   config = lib.mkIf cfg.enable {
+    vuizvui.user.aszlig.programs.git.configFile = let
+      escStr = s: "\"${lib.escape [ "\"" "\\" ] s}\"";
+      mkVal = v: if lib.isBool v && v  then "true"
+            else if lib.isBool v && !v then "false"
+            else escStr (toString v);
+      mkLine = key: val: "${key} = ${mkVal val}";
+
+      joinLines = lib.concatStringsSep "\n";
+      filterNull = lib.filterAttrs (lib.const (v: !(isNull v)));
+
+      mkSection = sect: subsect: vals: ''
+        [${sect}${lib.optionalString (subsect != null) " ${escStr subsect}"}]
+        ${joinLines (lib.mapAttrsToList mkLine (filterNull vals))}
+      '';
+
+      mkConf = sect: content: let
+        subs = lib.filterAttrs (lib.const lib.isAttrs) content;
+        nonSubs = lib.filterAttrs (lib.const (s: !lib.isAttrs s)) content;
+        maybePlain = lib.optional (nonSubs != {});
+        plainSects = lib.singleton (mkSection sect null nonSubs);
+      in lib.mapAttrsToList (mkSection sect) subs ++ maybePlain plainSects;
+
+      lines = lib.flatten (lib.mapAttrsToList mkConf cfg.settings);
+    in pkgs.writeText "gitconfig" (joinLines lines);
+
     environment.systemPackages = [
       gitPatched
       pkgs.gitAndTools.git-remote-hg