server-configuration/services/glauth.nix

74 lines
1.6 KiB
Nix
Raw Normal View History

2024-01-07 13:43:00 -07:00
{config, pkgs, lib, ...}:
let
cfg = config.services.glauth;
settingsFormat = pkgs.formats.toml {};
in
with lib;
{
options = {
services.glauth = {
enable = mkOption {
default = false;
type = with types; bool;
description = ''
Enable the glauth system service
'';
};
package = mkPackageOption pkgs "glauth" { };
user = mkOption {
default = "glauth";
type = types.str;
description = ''
Name of the user.
'';
};
group = mkOption {
default = "glauth";
type = types.str;
description = ''
Name of the group.
'';
};
settings = mkOption {
type = settingsFormat.type;
default = {};
description = ''
Configuration for glauth.cfg, see
<link xlink:href="https://github.com/glauth/glauth/blob/master/v2/sample-simple.cfg"
for supported settings.
'';
};
};
};
config = mkIf cfg.enable {
# Add user for glauth
users.users."${cfg.user}" = {
isSystemUser = true;
group = cfg.group;
home = "/var/empty";
};
users.groups."${cfg.group}" = {};
# Add systemd service
2024-01-07 13:43:00 -07:00
systemd.services.glauth = {
wantedBy = [ "multi-user.target" ];
2024-01-07 13:43:00 -07:00
after = [ "network.target" ];
description = "Start a glauth server.";
serviceConfig = {
Type = "exec";
User = "${cfg.user}";
Group = "${cfg.group}";
ExecStart = ''${cfg.package}/bin/glauth -c ${settingsFormat.generate "glauth.cfg" cfg.settings}'';
};
};
};
}