about summary refs log tree commit diff
path: root/modules/user/aszlig/programs/git
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2015-03-18 03:07:20 +0100
committeraszlig <aszlig@redmoonstudios.org>2015-03-18 03:07:20 +0100
commit187c673adf3c6a9a7afd8934ee41df7941f28cbf (patch)
tree3dee57d93c9c8a5fe4b7bd855b1cf33728142acc /modules/user/aszlig/programs/git
parent19e3e263610406fca8ca1ed6ecf283deb03d8334 (diff)
modules: Move my modules into category dirs.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'modules/user/aszlig/programs/git')
-rw-r--r--modules/user/aszlig/programs/git/default.nix74
1 files changed, 74 insertions, 0 deletions
diff --git a/modules/user/aszlig/programs/git/default.nix b/modules/user/aszlig/programs/git/default.nix
new file mode 100644
index 00000000..0090b617
--- /dev/null
+++ b/modules/user/aszlig/programs/git/default.nix
@@ -0,0 +1,74 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.vuizvui.user.aszlig.programs.git;
+
+  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=${cfg.config}";
+    in if isList oldFlags
+       then oldFlags ++ [ newVal ]
+       else "${oldFlags} ${newVal}";
+  });
+in {
+  options.vuizvui.user.aszlig.programs.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 cfg.enable {
+    environment.systemPackages = [
+      gitPatched
+      pkgs.gitAndTools.git-remote-hg
+      pkgs.gitAndTools.hub
+    ];
+  };
+}