stockholm/krebs/3modules/konsens.nix

88 lines
2.3 KiB
Nix
Raw Normal View History

2018-08-25 14:54:13 +00:00
{ config, lib, pkgs, ... }:
2023-06-10 10:50:53 +00:00
with import ../../lib/pure.nix { inherit lib; };
2018-08-25 14:54:13 +00:00
let
cfg = config.krebs.konsens;
out = {
options.krebs.konsens = api;
config = lib.mkIf cfg.enable imp;
};
api = {
enable = mkEnableOption "git konsens finder";
repos = mkOption {
type = types.attrsOf (types.submodule ({ config, ...}: {
options = {
url = mkOption {
type = types.str;
default = "git@localhost:${config._module.args.name}";
};
branchesToCheck = mkOption {
type = types.listOf types.str;
default = [ "lassulus" "makefu" "tv" ];
};
target = mkOption {
type = types.str;
default = "master";
};
timerConfig = mkOption {
type = types.attrsOf types.str;
default = {
OnCalendar = "*:00,15,30,45";
};
};
};
}));
};
};
imp = {
2023-04-15 14:26:59 +00:00
users.groups.konsens.gid = genid "konsens";
2018-08-25 14:54:13 +00:00
users.users.konsens = rec {
name = "konsens";
2023-04-15 14:26:59 +00:00
group = "konsens";
2018-08-25 14:54:13 +00:00
uid = genid name;
home = "/var/lib/konsens";
2023-04-15 14:26:59 +00:00
isSystemUser = true;
2018-08-25 14:54:13 +00:00
createHome = true;
};
systemd.timers = mapAttrs' (name: repo:
nameValuePair "konsens-${name}" {
description = "konsens timer";
wantedBy = [ "timers.target" ];
timerConfig = repo.timerConfig;
}
) cfg.repos;
systemd.services = mapAttrs' (name: repo:
nameValuePair "konsens-${name}" {
2020-08-04 18:28:04 +00:00
after = [ "network.target" ];
2023-05-02 19:28:13 +00:00
path = [
pkgs.git
pkgs.openssh
];
2018-08-25 14:54:13 +00:00
restartIfChanged = false;
serviceConfig = {
Type = "simple";
PermissionsStartOnly = true;
2023-06-10 10:50:53 +00:00
ExecStart = pkgs.writers.writeDash "konsens-${name}" ''
2023-05-02 18:39:46 +00:00
set -efu
git config --global --replace-all safe.directory *
2018-08-25 14:54:13 +00:00
if ! test -e ${name}; then
git clone ${repo.url} ${name}
fi
cd ${name}
git fetch origin
2018-09-08 19:26:03 +00:00
git push origin $(git merge-base --octopus ${concatMapStringsSep " " (branch: "origin/${branch}") repo.branchesToCheck}):refs/heads/master
2018-08-25 14:54:13 +00:00
'';
WorkingDirectory = /var/lib/konsens;
User = "konsens";
};
}
) cfg.repos;
};
in out