1 { config, lib, pkgs, ... }:
5 cfg = config.services.gitDaemon;
13 services.gitDaemon = {
18 description = lib.mdDoc ''
19 Enable Git daemon, which allows public hosting of git repositories
20 without any access controls. This is mostly intended for read-only access.
22 You can allow write access by setting daemon.receivepack configuration
23 item of the repository to true. This is solely meant for a closed LAN setting
24 where everybody is friendly.
26 If you need any access controls, use something else.
33 example = "/srv/git/";
34 description = lib.mdDoc ''
35 Remap all the path requests as relative to the given path. For example,
36 if you set base-path to /srv/git, then if you later try to pull
37 git://example.com/hello.git, Git daemon will interpret the path as /srv/git/hello.git.
41 exportAll = mkOption {
44 description = lib.mdDoc ''
45 Publish all directories that look like Git repositories (have the objects
46 and refs subdirectories), even if they do not have the git-daemon-export-ok file.
48 If disabled, you need to touch .git/git-daemon-export-ok in each repository
49 you want the daemon to publish.
51 Warning: enabling this without a repository whitelist or basePath
52 publishes every git repository you have.
56 repositories = mkOption {
57 type = types.listOf types.str;
59 example = [ "/srv/git" "/home/user/git/repo2" ];
60 description = lib.mdDoc ''
61 A whitelist of paths of git repositories, or directories containing repositories
62 all of which would be published. Paths must not end in "/".
64 Warning: leaving this empty and enabling exportAll publishes all
65 repositories in your filesystem or basePath if specified.
69 listenAddress = mkOption {
72 example = "example.com";
73 description = lib.mdDoc "Listen on a specific IP address or hostname.";
79 description = lib.mdDoc "Port to listen on.";
85 description = lib.mdDoc "Extra configuration options to be passed to Git daemon.";
91 description = lib.mdDoc "User under which Git daemon would be running.";
97 description = lib.mdDoc "Group under which Git daemon would be running.";
103 ###### implementation
105 config = mkIf cfg.enable {
107 users.users = optionalAttrs (cfg.user == "git") {
109 uid = config.ids.uids.git;
111 description = "Git daemon user";
115 users.groups = optionalAttrs (cfg.group == "git") {
116 git.gid = config.ids.gids.git;
119 systemd.services.git-daemon = {
120 after = [ "network.target" ];
121 wantedBy = [ "multi-user.target" ];
122 script = "${pkgs.git}/bin/git daemon --reuseaddr "
123 + (optionalString (cfg.basePath != "") "--base-path=${cfg.basePath} ")
124 + (optionalString (cfg.listenAddress != "") "--listen=${cfg.listenAddress} ")
125 + "--port=${toString cfg.port} --user=${cfg.user} --group=${cfg.group} ${cfg.options} "
126 + "--verbose " + (optionalString cfg.exportAll "--export-all ") + concatStringsSep " " cfg.repositories;