stockholm/krebs/3modules/solanum.nix

105 lines
2.2 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
let
inherit (lib) mkEnableOption mkIf mkOption singleton types;
2021-05-18 21:59:41 +00:00
inherit (pkgs) coreutils solanum;
cfg = config.krebs.solanum;
2021-05-18 21:59:41 +00:00
configFile = pkgs.writeText "solanum.conf" ''
${cfg.config}
'';
in
{
###### interface
options = {
2021-05-18 21:59:41 +00:00
krebs.solanum = {
2021-05-18 21:59:41 +00:00
enable = mkEnableOption "Solanum IRC daemon";
config = mkOption {
2020-01-14 19:37:58 +00:00
type = types.str;
description = ''
2021-05-18 21:59:41 +00:00
Solanum IRC daemon configuration file.
'';
};
statedir = mkOption {
2021-05-18 21:59:41 +00:00
type = types.path;
default = "/var/lib/solanum";
description = ''
2021-05-18 21:59:41 +00:00
Location of the state directory of solanum.
'';
};
user = mkOption {
2020-01-14 19:37:58 +00:00
type = types.str;
default = "ircd";
description = ''
2021-05-18 21:59:41 +00:00
Solanum IRC daemon user.
'';
};
group = mkOption {
2020-01-14 19:37:58 +00:00
type = types.str;
default = "ircd";
description = ''
2021-05-18 21:59:41 +00:00
Solanum IRC daemon group.
'';
};
motd = mkOption {
type = types.nullOr types.lines;
default = null;
description = ''
2021-05-18 21:59:41 +00:00
Solanum MOTD text.
2021-05-18 21:59:41 +00:00
Solanum will read its MOTD from /etc/solanum/ircd.motd .
If set, the value of this option will be written to this path.
'';
};
};
};
###### implementation
config = mkIf cfg.enable (lib.mkMerge [
{
users.users.${cfg.user} = {
2021-05-18 21:59:41 +00:00
description = "Solanum IRC daemon user";
uid = config.ids.uids.ircd;
group = cfg.group;
};
users.groups.${cfg.group} = {
gid = config.ids.gids.ircd;
};
2021-05-18 21:59:41 +00:00
systemd.tmpfiles.rules = [
"d ${cfg.statedir} - ${cfg.user} ${cfg.group} - -"
];
systemd.services.solanum = {
description = "Solanum IRC daemon";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
2021-05-18 21:59:41 +00:00
ExecStart = "${solanum}/bin/solanum -foreground -logfile /dev/stdout -configfile ${configFile} -pidfile ${cfg.statedir}/ircd.pid";
Group = cfg.group;
User = cfg.user;
};
};
}
(mkIf (cfg.motd != null) {
2021-05-18 21:59:41 +00:00
environment.etc."solanum/ircd.motd".text = cfg.motd;
})
]);
}