about summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2014-11-20 02:13:41 +0100
committeraszlig <aszlig@redmoonstudios.org>2014-11-20 02:13:41 +0100
commit50e0c139949809880c2bbf571546b39840898da6 (patch)
tree3a12d85e314af96a7529aa2ece64658ddf19f0ae /modules
parent47a13e1b9297fab8c82edb8349e0c87acd3fcfa1 (diff)
modules: Add "git" module for system-wide config.
Allows to declaratively specify the Git configuration options using
nested attribute sets.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'modules')
-rw-r--r--modules/git/default.nix68
-rw-r--r--modules/module-list.nix1
2 files changed, 69 insertions, 0 deletions
diff --git a/modules/git/default.nix b/modules/git/default.nix
new file mode 100644
index 00000000..06df124b
--- /dev/null
+++ b/modules/git/default.nix
@@ -0,0 +1,68 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  genConf = attrs: let
+    escStr = s: "\"${escape [ "\"" "\\" ] s}\"";
+    mkVal = v: if isBool v && v  then "true"
+          else if isBool v && !v then "false"
+          else escStr (toString v);
+    mkLine = key: val: "${key} = ${mkVal val}";
+
+    filterNull = filterAttrs (_: v: !(isNull v));
+
+    mkSection = sect: subsect: vals: ''
+      [${sect}${optionalString (subsect != null) " ${escStr subsect}"}]
+      ${concatStringsSep "\n" (mapAttrsToList mkLine (filterNull vals))}
+    '';
+
+    mkConf = sect: content: let
+      subs = filterAttrs (_: isAttrs) content;
+      nonSubs = filterAttrs (_: s: !isAttrs s) content;
+      hasPlain = (attrNames nonSubs) != [];
+      plainSects = singleton (mkSection sect null nonSubs);
+    in mapAttrsToList (mkSection sect) subs ++ optional hasPlain plainSects;
+
+    text = concatStringsSep "\n" (flatten (mapAttrsToList mkConf attrs));
+  in pkgs.writeText "gitconfig" text;
+
+  gitPatched = overrideDerivation pkgs.gitFull (git: {
+    makeFlags = let
+      oldFlags = git.makeFlags or [];
+      newVal = "ETC_GITCONFIG=${config.vuizvui.git.config}";
+    in if isList oldFlags
+       then oldFlags ++ [ newVal ]
+       else "${oldFlags} ${newVal}";
+  });
+in {
+  options.vuizvui.git = {
+    enable = mkEnableOption "Git";
+
+    config = mkOption {
+      description = "System-wide default config for Git";
+
+      type = let
+        superType = types.attrsOf types.unspecified;
+      in mkOptionType {
+        name = "attribute set of either plain values or "
+             + "attribute sets of values (if it is a subsection)";
+        inherit (superType) check merge;
+        inherit (superType) getSubOptions getSubModules substSubModules;
+      };
+
+      default = {};
+      example = {
+        color.ui = "auto";
+        merge.tool = "vimdiff";
+        guitool.foobar.noconsole = true;
+      };
+
+      apply = genConf;
+    };
+  };
+
+  config = mkIf config.vuizvui.git.enable {
+    environment.systemPackages = singleton gitPatched;
+  };
+}
diff --git a/modules/module-list.nix b/modules/module-list.nix
index 16387fdf..916e0efe 100644
--- a/modules/module-list.nix
+++ b/modules/module-list.nix
@@ -1,4 +1,5 @@
 [
+  ./git
   ./i3
   ./slim
   ./vlock