2015-07-19 14:04:28 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with builtins;
|
|
|
|
with lib;
|
|
|
|
let
|
2015-07-24 10:03:51 +00:00
|
|
|
cfg = config.krebs.github-hosts-sync;
|
2015-07-19 14:04:28 +00:00
|
|
|
|
|
|
|
out = {
|
2015-07-24 10:03:51 +00:00
|
|
|
options.krebs.github-hosts-sync = api;
|
2015-07-19 14:04:28 +00:00
|
|
|
config = mkIf cfg.enable imp;
|
|
|
|
};
|
|
|
|
|
|
|
|
api = {
|
2015-07-24 10:03:51 +00:00
|
|
|
enable = mkEnableOption "krebs.github-hosts-sync";
|
2015-07-19 14:04:28 +00: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.str; # TODO must be named *.ssh.{id_rsa,id_ed25519}
|
|
|
|
default = "/root/src/secrets/github-hosts-sync.ssh.id_rsa";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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";
|
|
|
|
ExecStartPre = pkgs.writeScript "github-hosts-sync-init" ''
|
|
|
|
#! /bin/sh
|
|
|
|
set -euf
|
|
|
|
|
|
|
|
ssh_identity_file_target=$(
|
|
|
|
case ${cfg.ssh-identity-file} in
|
|
|
|
*.ssh.id_rsa|*.ssh.id_ed25519) echo ${cfg.dataDir}/.ssh/id_rsa;;
|
|
|
|
*.ssh.id_ed25519) echo ${cfg.dataDir}/.ssh/id_ed25519;;
|
|
|
|
*)
|
|
|
|
echo "bad identity file name: ${cfg.ssh-identity-file}" >&2
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
)
|
|
|
|
|
|
|
|
mkdir -p ${cfg.dataDir}
|
|
|
|
chown ${user.name}: ${cfg.dataDir}
|
|
|
|
|
|
|
|
install \
|
|
|
|
-o ${user.name} \
|
|
|
|
-m 0400 \
|
|
|
|
${cfg.ssh-identity-file} \
|
|
|
|
"$ssh_identity_file_target"
|
|
|
|
|
2015-08-28 22:17:25 +00:00
|
|
|
ln -snf ${pkgs.github-known_hosts} ${cfg.dataDir}/.ssh/known_hosts
|
2015-07-19 14:04:28 +00:00
|
|
|
'';
|
2015-08-28 22:17:25 +00:00
|
|
|
ExecStart = "${pkgs.github-hosts-sync}/bin/github-hosts-sync";
|
2015-07-19 14:04:28 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraUsers = singleton {
|
|
|
|
inherit (user) name uid;
|
|
|
|
home = cfg.dataDir;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
user = {
|
|
|
|
name = "github-hosts-sync";
|
2015-07-22 17:25:51 +00:00
|
|
|
uid = 3220554646; # genid github-hosts-sync
|
2015-07-19 14:04:28 +00:00
|
|
|
};
|
|
|
|
in
|
|
|
|
out
|