xin/modules/golink.nix

95 lines
2.1 KiB
Nix
Raw Permalink Normal View History

2023-07-11 09:12:50 -06:00
{
config,
lib,
pkgs,
...
}:
with pkgs; let
cfg = config.services.golink;
2023-07-11 09:12:50 -06:00
golink = callPackage ../pkgs/golink.nix {};
in {
options = with lib; {
services.golink = {
enable = mkEnableOption "Enable golink";
user = mkOption {
2023-07-11 09:12:50 -06:00
type = with types; oneOf [str int];
default = "golink";
description = ''
The user the service will use.
'';
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/golink";
description = ''
Path to the golink sqlite database
'';
};
2022-12-12 06:45:26 -07:00
envFile = mkOption {
type = types.path;
default = "/run/secrets/golink";
description = ''
Path to a file containing the golink tailscale auth token
'';
};
group = mkOption {
2023-07-11 09:12:50 -06:00
type = with types; oneOf [str int];
default = "golink";
description = ''
The user the service will use.
'';
};
package = mkOption {
type = types.package;
default = golink;
defaultText = literalExpression "pkgs.golink";
description = "The package to use for golink";
};
};
};
config = lib.mkIf cfg.enable {
2023-07-11 09:12:50 -06:00
users.groups.${cfg.group} = {};
users.users.${cfg.user} = {
description = "golink service user";
isSystemUser = true;
home = cfg.dataDir;
createHome = true;
group = "${cfg.group}";
};
systemd.services.golink = {
enable = true;
description = "golink server";
2023-07-11 09:12:50 -06:00
wantedBy = ["network-online.target"];
after = ["network-online.target"];
2023-07-11 09:12:50 -06:00
path = [pkgs.vnstat];
environment = {
HOME = cfg.dataDir;
HOSTNAME = config.networking.hostName;
};
serviceConfig = {
User = cfg.user;
Group = cfg.group;
RuntimeDirectory = "golink";
StateDirectory = "golink";
StateDirectoryMode = "0755";
CacheDirectory = "golink";
CacheDirectoryMode = "0755";
2022-12-12 06:45:26 -07:00
EnvironmentFile = cfg.envFile;
2023-07-11 09:12:50 -06:00
ExecStart = "${cfg.package}/bin/golink -sqlitedb ${cfg.dataDir}/golink.db";
};
};
};
}