nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at master 107 lines 2.9 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 message = getvar "-m" "message"; 25 in 26 rec { 27 inherit (cfg) enable; 28 after = [ "network-online.target" ]; 29 wants = after; 30 wantedBy = [ "multi-user.target" ]; 31 description = "gitwatch for ${name}"; 32 path = with pkgs; [ 33 gitwatch 34 git 35 openssh 36 ]; 37 script = '' 38 if [ -n "${cfg.remote}" ] && ! [ -d "${cfg.path}" ]; then 39 git clone ${branch} "${cfg.remote}" "${cfg.path}" 40 fi 41 gitwatch ${remote} ${message} ${branch} ${cfg.path} 42 ''; 43 serviceConfig.User = cfg.user; 44 } 45 ); 46in 47{ 48 options.services.gitwatch = mkOption { 49 description = '' 50 A set of git repositories to watch for. See 51 [gitwatch](https://github.com/gitwatch/gitwatch) for more. 52 ''; 53 default = { }; 54 example = { 55 my-repo = { 56 enable = true; 57 user = "user"; 58 path = "/home/user/watched-project"; 59 remote = "git@github.com:me/my-project.git"; 60 message = "Auto-commit by gitwatch on %d"; 61 }; 62 disabled-repo = { 63 enable = false; 64 user = "user"; 65 path = "/home/user/disabled-project"; 66 remote = "git@github.com:me/my-old-project.git"; 67 branch = "autobranch"; 68 }; 69 }; 70 type = 71 with types; 72 attrsOf (submodule { 73 options = { 74 enable = mkEnableOption "watching for repo"; 75 path = mkOption { 76 description = "The path to repo in local machine"; 77 type = str; 78 }; 79 user = mkOption { 80 description = "The name of services's user"; 81 type = str; 82 default = "root"; 83 }; 84 remote = mkOption { 85 description = "Optional url of remote repository"; 86 type = nullOr str; 87 default = null; 88 }; 89 message = lib.mkOption { 90 description = "Optional text to use in as commit message; all occurrences of `%d` will be replaced by formatted date/time"; 91 type = nullOr str; 92 default = null; 93 }; 94 branch = mkOption { 95 description = "Optional branch in remote repository"; 96 type = nullOr str; 97 default = null; 98 }; 99 }; 100 }); 101 }; 102 config.systemd.services = mapAttrs' mkSystemdService config.services.gitwatch; 103 meta.maintainers = with maintainers; [ 104 shved 105 zareix 106 ]; 107}