at 25.11-pre 2.5 kB view raw
1{ 2 lib, 3 pkgs, 4 config, 5 ... 6}: 7let 8 inherit (lib) 9 maintainers 10 mapAttrs' 11 mkEnableOption 12 mkOption 13 nameValuePair 14 optionalString 15 types 16 ; 17 mkSystemdService = 18 name: cfg: 19 nameValuePair "gitwatch-${name}" ( 20 let 21 getvar = flag: var: optionalString (cfg."${var}" != null) "${flag} ${cfg."${var}"}"; 22 branch = getvar "-b" "branch"; 23 remote = getvar "-r" "remote"; 24 in 25 rec { 26 inherit (cfg) enable; 27 after = [ "network-online.target" ]; 28 wants = after; 29 wantedBy = [ "multi-user.target" ]; 30 description = "gitwatch for ${name}"; 31 path = with pkgs; [ 32 gitwatch 33 git 34 openssh 35 ]; 36 script = '' 37 if [ -n "${cfg.remote}" ] && ! [ -d "${cfg.path}" ]; then 38 git clone ${branch} "${cfg.remote}" "${cfg.path}" 39 fi 40 gitwatch ${remote} ${branch} ${cfg.path} 41 ''; 42 serviceConfig.User = cfg.user; 43 } 44 ); 45in 46{ 47 options.services.gitwatch = mkOption { 48 description = '' 49 A set of git repositories to watch for. See 50 [gitwatch](https://github.com/gitwatch/gitwatch) for more. 51 ''; 52 default = { }; 53 example = { 54 my-repo = { 55 enable = true; 56 user = "user"; 57 path = "/home/user/watched-project"; 58 remote = "git@github.com:me/my-project.git"; 59 }; 60 disabled-repo = { 61 enable = false; 62 user = "user"; 63 path = "/home/user/disabled-project"; 64 remote = "git@github.com:me/my-old-project.git"; 65 branch = "autobranch"; 66 }; 67 }; 68 type = 69 with types; 70 attrsOf (submodule { 71 options = { 72 enable = mkEnableOption "watching for repo"; 73 path = mkOption { 74 description = "The path to repo in local machine"; 75 type = str; 76 }; 77 user = mkOption { 78 description = "The name of services's user"; 79 type = str; 80 default = "root"; 81 }; 82 remote = mkOption { 83 description = "Optional url of remote repository"; 84 type = nullOr str; 85 default = null; 86 }; 87 branch = mkOption { 88 description = "Optional branch in remote repository"; 89 type = nullOr str; 90 default = null; 91 }; 92 }; 93 }); 94 }; 95 config.systemd.services = mapAttrs' mkSystemdService config.services.gitwatch; 96 meta.maintainers = with maintainers; [ shved ]; 97}