stockholm/krebs/3modules/github-hosts-sync.nix

67 lines
1.7 KiB
Nix
Raw Normal View History

2015-07-19 16:04:28 +02:00
{ config, lib, pkgs, ... }:
2016-10-20 20:54:38 +02:00
with import <stockholm/lib>;
2015-07-19 16:04:28 +02:00
let
2015-07-24 12:03:51 +02:00
cfg = config.krebs.github-hosts-sync;
2015-07-19 16:04:28 +02:00
out = {
2015-07-24 12:03:51 +02:00
options.krebs.github-hosts-sync = api;
2016-02-14 16:43:44 +01:00
config = lib.mkIf cfg.enable imp;
2015-07-19 16:04:28 +02:00
};
api = {
2015-07-24 12:03:51 +02:00
enable = mkEnableOption "krebs.github-hosts-sync";
2015-07-19 16:04:28 +02:00
port = mkOption {
type = types.int; # TODO port type
default = 1028;
};
dataDir = mkOption {
type = types.str; # TODO path (but not just into store)
default = "/var/lib/github-hosts-sync";
};
ssh-identity-file = mkOption {
type = types.suffixed-str [".ssh.id_ed25519" ".ssh.id_rsa"];
2015-09-27 00:22:50 +02:00
default = toString <secrets/github-hosts-sync.ssh.id_rsa>;
2015-07-19 16:04:28 +02:00
};
};
imp = {
systemd.services.github-hosts-sync = {
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
environment = {
port = toString cfg.port;
};
serviceConfig = {
PermissionsStartOnly = "true";
SyslogIdentifier = "github-hosts-sync";
User = user.name;
Restart = "always";
2016-06-13 02:04:22 +02:00
ExecStartPre = pkgs.writeDash "github-hosts-sync-init" ''
2015-07-19 16:04:28 +02:00
set -euf
install -m 0711 -o ${user.name} -d ${cfg.dataDir}
install -m 0700 -o ${user.name} -d ${cfg.dataDir}/.ssh
install -m 0400 -o ${user.name} \
2015-07-19 16:04:28 +02:00
${cfg.ssh-identity-file} \
${cfg.dataDir}/.ssh/${fileExtension cfg.ssh-identity-file}
2015-07-19 16:04:28 +02:00
'';
2015-08-29 00:17:25 +02:00
ExecStart = "${pkgs.github-hosts-sync}/bin/github-hosts-sync";
2015-07-19 16:04:28 +02:00
};
};
users.extraUsers = singleton {
inherit (user) name uid;
home = cfg.dataDir;
};
};
2015-12-26 05:55:13 +01:00
user = rec {
2015-07-19 16:04:28 +02:00
name = "github-hosts-sync";
2015-12-26 05:55:13 +01:00
uid = genid name;
2015-07-19 16:04:28 +02:00
};
# TODO move to lib?
fileExtension = s: last (splitString "." s);
in out