2014-06-26 04:32:45 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.gitolite;
|
2017-09-12 09:44:21 +01:00
|
|
|
# Use writeTextDir to not leak Nix store hash into file name
|
|
|
|
pubkeyFile = (pkgs.writeTextDir "gitolite-admin.pub" cfg.adminPubkey) + "/gitolite-admin.pub";
|
2014-09-16 07:33:29 +01:00
|
|
|
hooks = lib.concatMapStrings (hook: "${hook} ") cfg.commonHooks;
|
2014-06-26 04:32:45 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.gitolite = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable gitolite management under the
|
2014-11-01 23:24:41 +00:00
|
|
|
<literal>gitolite</literal> user. After
|
2014-06-26 04:32:45 +01:00
|
|
|
switching to a configuration with Gitolite enabled, you can
|
|
|
|
then run <literal>git clone
|
2014-06-26 04:55:43 +01:00
|
|
|
gitolite@host:gitolite-admin.git</literal> to manage it further.
|
2014-06-26 04:32:45 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-11-01 23:24:41 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/gitolite";
|
|
|
|
description = ''
|
|
|
|
Gitolite home directory (used to store all the repositories).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-06-26 04:32:45 +01:00
|
|
|
adminPubkey = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Initial administrative public key for Gitolite. This should
|
|
|
|
be an SSH Public Key. Note that this key will only be used
|
|
|
|
once, upon the first initialization of the Gitolite user.
|
2015-01-13 05:49:33 +00:00
|
|
|
The key string cannot have any line breaks in it.
|
2014-06-26 04:32:45 +01:00
|
|
|
'';
|
|
|
|
};
|
2014-09-16 07:33:29 +01:00
|
|
|
|
|
|
|
commonHooks = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
A list of custom git hooks that get copied to <literal>~/.gitolite/hooks/common</literal>.
|
|
|
|
'';
|
|
|
|
};
|
2014-11-14 15:07:17 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitolite";
|
|
|
|
description = ''
|
|
|
|
Gitolite user account. This is the username of the gitolite endpoint.
|
|
|
|
'';
|
|
|
|
};
|
2014-06-26 04:32:45 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2014-11-14 15:07:17 +00:00
|
|
|
users.extraUsers.${cfg.user} = {
|
2014-06-26 04:32:45 +01:00
|
|
|
description = "Gitolite user";
|
2014-11-01 23:24:41 +00:00
|
|
|
home = cfg.dataDir;
|
2014-06-26 04:32:45 +01:00
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.gitolite;
|
|
|
|
useDefaultShell = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services."gitolite-init" = {
|
|
|
|
description = "Gitolite initialization";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2017-09-11 20:03:51 +01:00
|
|
|
unitConfig.RequiresMountsFor = cfg.dataDir;
|
2014-06-26 04:32:45 +01:00
|
|
|
|
2014-11-14 15:07:17 +00:00
|
|
|
serviceConfig.User = "${cfg.user}";
|
2014-06-26 04:32:45 +01:00
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
|
2015-06-27 01:09:58 +01:00
|
|
|
path = [ pkgs.gitolite pkgs.git pkgs.perl pkgs.bash config.programs.ssh.package ];
|
2014-06-26 04:32:45 +01:00
|
|
|
script = ''
|
2014-11-01 23:24:41 +00:00
|
|
|
cd ${cfg.dataDir}
|
2014-06-26 04:32:45 +01:00
|
|
|
mkdir -p .gitolite/logs
|
|
|
|
if [ ! -d repositories ]; then
|
|
|
|
gitolite setup -pk ${pubkeyFile}
|
|
|
|
fi
|
2014-09-16 07:33:29 +01:00
|
|
|
if [ -n "${hooks}" ]; then
|
|
|
|
cp ${hooks} .gitolite/hooks/common/
|
|
|
|
chmod +x .gitolite/hooks/common/*
|
|
|
|
fi
|
2014-06-26 04:32:45 +01:00
|
|
|
gitolite setup # Upgrade if needed
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.gitolite pkgs.git ];
|
|
|
|
};
|
|
|
|
}
|