]> Git — Sourcephile - sourcephile-nix.git/blob - servers/mermet/gitolite.nix
apparmor: fix/rewrite security.apparmor
[sourcephile-nix.git] / servers / mermet / gitolite.nix
1 { pkgs, lib, config, ... }:
2 let
3 inherit (builtins) readFile;
4 inherit (lib) types;
5 inherit (config) networking;
6 inherit (config.services) gitolite;
7 inherit (config.users) users groups;
8 gitolite-admin = "julm";
9 in
10 {
11 # Make confortable to call gitolite from a shell
12 # (but mind to prefix it by sudo -u git)
13 environment.systemPackages = [ pkgs.gitolite ];
14
15 services = {
16 gitolite = {
17 enable = true;
18 user = "git";
19 group = users."git-daemon".name;
20 adminPubkey = (readFile ../../../sec/ssh/julm.pub);
21 extraGitoliteRc = ''
22 $RC{UMASK} = 0027; # NOTE: no quote around in Perl, so it's octal
23 $RC{LOG_DEST} = 'repo-log,syslog';
24 $RC{LOG_FACILITY} = 'local0';
25 #$RC{GIT_CONFIG_KEYS} = 'hooks.* gitweb.*';
26 $RC{GIT_CONFIG_KEYS} = '.*';
27 #$RC{LOCAL_CODE} = "$rc{GL_ADMIN_BASE}/local"
28 # if -d "$rc{GL_ADMIN_BASE}/local";
29 $RC{LOCAL_CODE} = "$ENV{HOME}/local";
30 push(@{$RC{ENABLE}}, ( 'Alias'
31 , 'cgit'
32 # NOTE: without this "cgit" option,
33 # the repositories' "description" files are not modified
34 , 'D'
35 , 'Shell ${gitolite-admin}'
36 , 'create'
37 , 'expand-deny-messages'
38 , 'fork'
39 , 'keysubdirs-as-groups'
40 , 'readme'
41 , (-d "$ENV{HOME}/local" ? 'repo-specific-hooks' : ())
42 , 'ssh-authkeys-split'
43 ));
44 '';
45 };
46 };
47 systemd.services.gitolite-init = {
48 preStart = ''
49 # Allow git-daemon to enter ~git
50 chmod g+x "${gitolite.dataDir}"
51 install -D -d -o ${gitolite.user} -g ${gitolite.group} -m 750 \
52 ${gitolite.dataDir}/local \
53 ${gitolite.dataDir}/local/hooks \
54 ${gitolite.dataDir}/local/hooks/common \
55 ${gitolite.dataDir}/local/hooks/repo-specific
56 '';
57 };
58 networking.nftables.ruleset = ''
59 add rule inet filter net2fw tcp dport 9418 counter accept comment "Git"
60 '';
61 systemd.services.git-daemon = {
62 # NOTE: not using nixpkgs' gitDaemon, to avoid running it as root.
63 after = [ "network.target" ];
64 wantedBy = [ "multi-user.target" ];
65 serviceConfig = {
66 User = users."git-daemon".name;
67 Group = groups."git-daemon".name;
68 Restart = "always";
69 RestartSec = 5;
70 };
71 script = "${pkgs.git}/bin/git daemon --verbose --reuseaddr"
72 + " --base-path=${gitolite.dataDir}/repositories"
73 #+ (optionalString (cfg.listenAddress != "") "--listen=${cfg.listenAddress} ")
74 #+ "--port=${toString cfg.port} "
75 ;
76 };
77 users.users."git-daemon" = {
78 uid = config.ids.uids.git;
79 description = "Git daemon user";
80 };
81 }