From 473ffd9eae9594fdbf281d1f5297d4d6cea32503 Mon Sep 17 00:00:00 2001
From: Ronny Esterluss <ronny@daogames.com>
Date: Tue, 16 Sep 2014 08:33:29 +0200
Subject: [PATCH] extended gitolite service to take custom hooks

Closes #4160
---
 nixos/modules/services/misc/gitolite.nix | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/nixos/modules/services/misc/gitolite.nix b/nixos/modules/services/misc/gitolite.nix
index 84435f92c11d..961af48e0f86 100644
--- a/nixos/modules/services/misc/gitolite.nix
+++ b/nixos/modules/services/misc/gitolite.nix
@@ -5,6 +5,7 @@ with lib;
 let
   cfg = config.services.gitolite;
   pubkeyFile = pkgs.writeText "gitolite-admin.pub" cfg.adminPubkey;
+  hooks = lib.concatMapStrings (hook: "${hook} ") cfg.commonHooks;
 in
 {
   options = {
@@ -30,6 +31,14 @@ in
           once, upon the first initialization of the Gitolite user.
         '';
       };
+
+      commonHooks = mkOption {
+        type = types.listOf types.path;
+        default = [];
+        description = ''
+          A list of custom git hooks that get copied to <literal>~/.gitolite/hooks/common</literal>.
+        '';
+      };
     };
   };
 
@@ -57,6 +66,10 @@ in
         if [ ! -d repositories ]; then
           gitolite setup -pk ${pubkeyFile}
         fi
+        if [ -n "${hooks}" ]; then
+          cp ${hooks} .gitolite/hooks/common/
+          chmod +x .gitolite/hooks/common/*
+        fi
         gitolite setup # Upgrade if needed
       '';
     };