2016-02-15 13:01:20 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
2016-06-13 00:04:22 +00:00
|
|
|
with config.krebs.lib;
|
2016-02-15 13:01:20 +00:00
|
|
|
let
|
|
|
|
cfg = config.krebs.repo-sync;
|
|
|
|
|
|
|
|
out = {
|
|
|
|
options.krebs.repo-sync = api;
|
2016-06-13 00:04:22 +00:00
|
|
|
config = lib.mkIf cfg.enable imp;
|
2016-02-15 13:01:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
api = {
|
|
|
|
enable = mkEnableOption "repo-sync";
|
2016-06-24 13:24:42 +00:00
|
|
|
repos = mkOption {
|
|
|
|
type = with types;attrsOf (attrsOf (attrsOf (attrsOf str)));
|
2016-02-15 13:01:20 +00:00
|
|
|
example = literalExample ''
|
|
|
|
# see `repo-sync --help`
|
|
|
|
# `ref` provides sane defaults and can be omitted
|
|
|
|
|
|
|
|
# attrset will be converted to json and be used as config
|
2016-06-24 13:24:42 +00:00
|
|
|
{ repo = {
|
2016-02-15 13:01:20 +00:00
|
|
|
makefu = {
|
2016-06-24 13:24:42 +00:00
|
|
|
origin = {
|
|
|
|
url = http://github.com/makefu/repo ;
|
|
|
|
ref = "heads/dev" ;
|
|
|
|
};
|
|
|
|
mirror = {
|
|
|
|
url = "git@internal:mirror" ;
|
|
|
|
ref = "heads/github-mirror-dev" ;
|
|
|
|
};
|
2016-02-15 13:01:20 +00:00
|
|
|
};
|
|
|
|
lass = {
|
2016-06-24 13:24:42 +00:00
|
|
|
origin = {
|
|
|
|
url = http://github.com/lass/repo ;
|
|
|
|
};
|
|
|
|
mirror = {
|
|
|
|
url = "git@internal:mirror" ;
|
|
|
|
};
|
2016-02-15 13:01:20 +00:00
|
|
|
};
|
|
|
|
"@latest" = {
|
2016-06-24 13:24:42 +00:00
|
|
|
mirror = {
|
|
|
|
url = "git@internal:mirror";
|
|
|
|
ref = "heads/master";
|
|
|
|
};
|
2016-02-15 13:01:20 +00:00
|
|
|
};
|
2016-06-24 13:24:42 +00:00
|
|
|
};
|
2016-02-15 13:01:20 +00:00
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
timerConfig = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {
|
|
|
|
OnCalendar = "*:00,15,30,45";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/repo-sync";
|
|
|
|
};
|
2016-06-24 13:24:42 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.user;
|
|
|
|
default = {
|
|
|
|
name = "repo-sync";
|
|
|
|
home = cfg.stateDir;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-02-15 13:01:20 +00:00
|
|
|
privateKeyFile = mkOption {
|
2016-06-24 13:24:42 +00:00
|
|
|
type = types.secret-file;
|
|
|
|
default = {
|
|
|
|
path = "${cfg.stateDir}/ssh.priv";
|
|
|
|
owner = cfg.user;
|
|
|
|
source-path = toString <secrets> + "/repo-sync.ssh.key";
|
|
|
|
};
|
2016-02-15 13:01:20 +00:00
|
|
|
};
|
2016-06-24 13:24:42 +00:00
|
|
|
|
2016-06-26 15:53:11 +00:00
|
|
|
unitConfig = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
description = "Extra unit configuration for fetchWallpaper to define conditions and assertions for the unit";
|
|
|
|
example = literalExample ''
|
|
|
|
# do not start when running on umts
|
|
|
|
{ ConditionPathExists = "!/var/run/ppp0.pid"; }
|
|
|
|
'';
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
|
2016-02-15 13:01:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
imp = {
|
2016-06-24 13:24:42 +00:00
|
|
|
users.users.${cfg.user.name} = {
|
|
|
|
inherit (cfg.user) home name uid;
|
2016-02-15 13:01:20 +00:00
|
|
|
createHome = true;
|
2016-06-24 13:24:42 +00:00
|
|
|
description = "repo-sync user";
|
2016-02-15 13:01:20 +00:00
|
|
|
};
|
|
|
|
|
2016-06-24 13:24:42 +00:00
|
|
|
systemd.timers = mapAttrs' (name: repo:
|
|
|
|
nameValuePair "repo-sync-${name}" {
|
|
|
|
description = "repo-sync timer";
|
|
|
|
wantedBy = [ "timers.target" ];
|
2016-02-15 13:01:20 +00:00
|
|
|
|
2016-06-24 13:24:42 +00:00
|
|
|
timerConfig = cfg.timerConfig;
|
|
|
|
}
|
|
|
|
) cfg.repos;
|
2016-02-15 13:01:20 +00:00
|
|
|
|
2016-06-24 13:24:42 +00:00
|
|
|
systemd.services = mapAttrs' (name: repo:
|
|
|
|
let
|
|
|
|
repo-sync-config = pkgs.writeText "repo-sync-config-${name}.json"
|
|
|
|
(builtins.toJSON repo);
|
|
|
|
in nameValuePair "repo-sync-${name}" {
|
|
|
|
description = "repo-sync";
|
|
|
|
after = [ "network.target" "secret.service" ];
|
2016-02-15 13:01:20 +00:00
|
|
|
|
2016-06-24 13:24:42 +00:00
|
|
|
environment = {
|
|
|
|
GIT_SSH_COMMAND = "${pkgs.openssh}/bin/ssh -i ${cfg.stateDir}/ssh.priv";
|
2016-06-24 14:04:04 +00:00
|
|
|
REPONAME = "${name}.git";
|
2016-06-24 13:24:42 +00:00
|
|
|
};
|
2016-02-15 13:01:20 +00:00
|
|
|
|
2016-06-24 13:24:42 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
ExecStart = "${pkgs.repo-sync}/bin/repo-sync ${repo-sync-config}";
|
|
|
|
WorkingDirectory = cfg.stateDir;
|
|
|
|
User = "repo-sync";
|
|
|
|
};
|
2016-06-26 15:53:11 +00:00
|
|
|
unitConfig = cfg.unitConfig;
|
2016-06-24 13:24:42 +00:00
|
|
|
}
|
|
|
|
) cfg.repos;
|
2016-02-15 13:01:20 +00:00
|
|
|
};
|
|
|
|
in out
|