pots/module.nix

92 lines
2.1 KiB
Nix
Raw Normal View History

2023-01-10 18:30:48 -07:00
{ lib, config, pkgs, inputs, ... }:
let cfg = config.services.pots;
in {
options = with lib; {
services.pots = {
enable = lib.mkEnableOption "Enable pots";
port = mkOption {
type = types.int;
default = 8888;
description = ''
Port to listen on string.
'';
};
user = mkOption {
type = with types; oneOf [ str int ];
default = "pots";
description = ''
The user the service will use.
'';
};
group = mkOption {
type = with types; oneOf [ str int ];
default = "pots";
description = ''
The group the service will use.
'';
};
keyPath = mkOption {
type = types.path;
default = "";
description = ''
Path to the GitHub API key file
'';
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/pots";
description = "Path pots home directory";
};
package = mkOption {
type = types.package;
default = pkgs.pots;
defaultText = literalExpression "pkgs.pots";
description = "The package to use for pots";
};
envFile = mkOption {
type = types.path;
default = "/run/secrets/pots_env_file";
description = ''
Path to a file containing the pots token information
'';
};
};
};
config = lib.mkIf (cfg.enable) {
users.groups.${cfg.group} = { };
users.users.${cfg.user} = {
description = "pots service user";
isSystemUser = true;
home = "${cfg.dataDir}";
createHome = true;
group = "${cfg.group}";
};
systemd.services.pots = {
enable = true;
description = "pots server";
wantedBy = [ "network-online.target" ];
after = [ "network-online.target" ];
environment = { HOME = "${cfg.dataDir}"; };
serviceConfig = {
User = cfg.user;
Group = cfg.group;
ExecStart =
2023-01-10 18:33:16 -07:00
"${cfg.package}/bin/pots -port ${toString cfg.port}";
2023-01-10 18:30:48 -07:00
EnvironmentFile = cfg.envFile;
};
};
};
}