1{ pkgs, ... }:
2
3let
4 hashes = pkgs.writeText "hashes" ''
5 b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c /project/bar
6 '';
7in
8{
9 name = "gitdaemon";
10
11 meta = with pkgs.lib.maintainers; {
12 maintainers = [ tilpner ];
13 };
14
15 nodes = {
16 server =
17 { config, ... }:
18 {
19 networking.firewall.allowedTCPPorts = [ config.services.gitDaemon.port ];
20
21 environment.systemPackages = [ pkgs.git ];
22
23 systemd.tmpfiles.rules = [
24 # type path mode user group age arg
25 " d /git 0755 git git - -"
26 ];
27
28 services.gitDaemon = {
29 enable = true;
30 basePath = "/git";
31 };
32 };
33
34 client =
35 { pkgs, ... }:
36 {
37 environment.systemPackages = [ pkgs.git ];
38 };
39 };
40
41 testScript = ''
42 start_all()
43
44 with subtest("create project.git"):
45 server.succeed(
46 "git init --bare /git/project.git",
47 "touch /git/project.git/git-daemon-export-ok",
48 )
49
50 with subtest("add file to project.git"):
51 server.succeed(
52 "git clone /git/project.git /project",
53 "echo foo > /project/bar",
54 "git config --global user.email 'you@example.com'",
55 "git config --global user.name 'Your Name'",
56 "git -C /project add bar",
57 "git -C /project commit -m 'quux'",
58 "git -C /project push",
59 "rm -r /project",
60 )
61
62 # Change user/group to default daemon user/group from module
63 # to avoid "fatal: detected dubious ownership in repository at '/git/project.git'"
64 server.succeed("chown git:git -R /git/project.git")
65
66 with subtest("git daemon starts"):
67 server.wait_for_unit("git-daemon.service")
68
69
70 server.systemctl("start network-online.target")
71 client.systemctl("start network-online.target")
72 server.wait_for_unit("network-online.target")
73 client.wait_for_unit("network-online.target")
74
75 with subtest("client can clone project.git"):
76 client.succeed(
77 "git clone git://server/project.git /project",
78 "sha256sum -c ${hashes}",
79 )
80 '';
81}