stockholm/krebs/3modules/htgen.nix

69 lines
1.5 KiB
Nix
Raw Normal View History

2017-03-16 19:56:28 +00:00
{ config, lib, pkgs, ... }:
with import <stockholm/lib>;
let
cfg = config.krebs.htgen;
out = {
options.krebs.htgen = api;
config = imp;
};
api = mkOption {
2017-03-16 21:12:11 +00:00
default = {};
2017-03-16 19:56:28 +00:00
type = types.attrsOf (types.submodule ({ config, ... }: {
options = {
enable = mkEnableOption "krebs.htgen-${config.name}";
name = mkOption {
type = types.username;
default = config._module.args.name;
};
port = mkOption {
type = types.uint;
};
script = mkOption {
type = types.str;
};
user = mkOption {
type = types.user;
default = {
name = "htgen-${config.name}";
home = "/var/lib/htgen-${config.name}";
};
};
};
}));
};
imp = {
systemd.services = mapAttrs' (name: htgen:
nameValuePair "htgen-${name}" {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
environment = {
HTGEN_PORT = toString htgen.port;
2017-03-16 20:53:34 +00:00
HTGEN_SCRIPT = htgen.script;
2017-03-16 19:56:28 +00:00
};
serviceConfig = {
SyslogIdentifier = "htgen";
User = htgen.user.name;
PrivateTmp = true;
Restart = "always";
2017-03-16 20:53:34 +00:00
ExecStart = "${pkgs.htgen}/bin/htgen --serve";
2017-03-16 19:56:28 +00:00
};
}
) cfg;
users.users = mapAttrs' (name: htgen:
nameValuePair htgen.user.name {
inherit (htgen.user) home name uid;
createHome = true;
}
) cfg;
};
in out