2023-07-11 09:12:50 -06:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with pkgs; let
|
2022-12-01 21:00:23 -07:00
|
|
|
cfg = config.services.golink;
|
2023-07-11 09:12:50 -06:00
|
|
|
golink = callPackage ../pkgs/golink.nix {};
|
2022-12-01 21:00:23 -07:00
|
|
|
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];
|
2022-12-01 21:00:23 -07:00
|
|
|
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 {
|
2022-12-01 21:00:23 -07:00
|
|
|
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];
|
2022-12-01 21:00:23 -07:00
|
|
|
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} = {};
|
2022-12-01 21:00:23 -07:00
|
|
|
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"];
|
2022-12-01 21:00:23 -07:00
|
|
|
|
2023-07-11 09:12:50 -06:00
|
|
|
path = [pkgs.vnstat];
|
2022-12-01 21:00:23 -07:00
|
|
|
|
|
|
|
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";
|
2022-12-01 21:00:23 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|