forked from gitwatch/gitwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.nix
More file actions
95 lines (95 loc) · 2.67 KB
/
module.nix
File metadata and controls
95 lines (95 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
lib,
pkgs,
config,
...
}:
let
gitwatch = pkgs.callPackage ./gitwatch.nix { };
mkSystemdService =
name: cfg:
lib.nameValuePair "gitwatch-${name}" (
let
getvar = flag: var: if cfg."${var}" != null then "${flag} ${cfg."${var}"}" else "";
branch = getvar "-b" "branch";
fetcher = if cfg.remote == null then "true" else '''';
in
{
inherit (cfg) enable;
after = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
description = "gitwatch for ${name}";
path = with pkgs; [
gitwatch
git
openssh
];
script = ''
if [ -n "${cfg.remote}" ] && ! [ -d "${cfg.path}" ]; then
git clone ${branch} "${cfg.remote}" "${cfg.path}"
fi
${fetcher}
gitwatch ${getvar "-r" "remote"} ${getvar "-m" "message"} ${branch} ${cfg.path}
'';
serviceConfig.User = cfg.user;
}
);
in
{
options.services.gitwatch = lib.mkOption {
description = ''
A set of git repositories to watch for.
See
[gitwatch](https://github.com/gitwatch/gitwatch) for more.
'';
default = { };
example = {
my-repo = {
enable = true;
user = "user";
path = "/home/user/watched-project";
remote = "git@github.com:me/my-project.git";
message = "Auto-commit by gitwatch on %d";
};
disabled-repo = {
enable = false;
user = "user";
path = "/home/user/disabled-project";
remote = "git@github.com:me/my-old-project.git";
branch = "autobranch";
};
};
type =
with lib.types;
attrsOf (submodule {
options = {
enable = lib.mkEnableOption "watching for repo";
path = lib.mkOption {
description = "The path to repo in local machine";
type = str;
};
user = lib.mkOption {
description = "The name of services's user";
type = str;
default = "root";
};
remote = lib.mkOption {
description = "Optional url of remote repository";
type = nullOr str;
default = null;
};
message = lib.mkOption {
description = "Optional message to use in as commit message.";
type = nullOr str;
default = null;
};
branch = lib.mkOption {
description = "Optional branch in remote repository";
type = nullOr str;
default = null;
};
};
});
};
config.systemd.services = lib.mapAttrs' mkSystemdService config.services.gitwatch;
}