You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitwatch/module.nix

85 lines
2.3 KiB
Nix

{ 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" ];
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"} ${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";
};
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;
};
branch = lib.mkOption {
description = "Optional branch in remote repository";
type = nullOr str;
default = null;
};
};
});
};
config.systemd.services =
lib.mapAttrs' mkSystemdService config.services.gitwatch;
}