nixos/vmagent: use dynamic user and cache directory
This commit is contained in:
parent
e0638909ae
commit
6c69cfb804
|
@ -319,6 +319,10 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m
|
||||||
|
|
||||||
- `services.vikunja.setupNginx` setting has been removed. Users now need to setup the webserver configuration on their own with a proxy pass to the vikunja service.
|
- `services.vikunja.setupNginx` setting has been removed. Users now need to setup the webserver configuration on their own with a proxy pass to the vikunja service.
|
||||||
|
|
||||||
|
- `services.vmagent` module deprecates `dataDir`, `group` and `user` setting in favor of systemd provided CacheDirectory and DynamicUser.
|
||||||
|
|
||||||
|
- `services.vmagent.remoteWriteUrl` setting has been renamed to `services.vmagent.remoteWrite.url` and now defaults to `null`.
|
||||||
|
|
||||||
- `woodpecker-*` packages have been updated to v2 which includes [breaking changes](https://woodpecker-ci.org/docs/next/migrations#200).
|
- `woodpecker-*` packages have been updated to v2 which includes [breaking changes](https://woodpecker-ci.org/docs/next/migrations#200).
|
||||||
|
|
||||||
- `services.nginx` will no longer advertise HTTP/3 availability automatically. This must now be manually added, preferably to each location block.
|
- `services.nginx` will no longer advertise HTTP/3 availability automatically. This must now be manually added, preferably to each location block.
|
||||||
|
|
|
@ -4,41 +4,40 @@ let
|
||||||
cfg = config.services.vmagent;
|
cfg = config.services.vmagent;
|
||||||
settingsFormat = pkgs.formats.json { };
|
settingsFormat = pkgs.formats.json { };
|
||||||
in {
|
in {
|
||||||
|
imports = [
|
||||||
|
(lib.mkRemovedOptionModule [ "services" "vmagent" "dataDir" ] "dataDir has been deprecated in favor of systemd provided CacheDirectory")
|
||||||
|
(lib.mkRemovedOptionModule [ "services" "vmagent" "user" ] "user has been deprecated in favor of systemd DynamicUser")
|
||||||
|
(lib.mkRemovedOptionModule [ "services" "vmagent" "group" ] "group has been deprecated in favor of systemd DynamicUser")
|
||||||
|
(lib.mkRenamedOptionModule [ "services" "vmagent" "remoteWriteUrl" ] [ "services" "vmagent" "remoteWrite" "url" ])
|
||||||
|
];
|
||||||
|
|
||||||
options.services.vmagent = {
|
options.services.vmagent = {
|
||||||
enable = lib.mkEnableOption "vmagent";
|
enable = lib.mkEnableOption "vmagent";
|
||||||
|
|
||||||
user = lib.mkOption {
|
|
||||||
default = "vmagent";
|
|
||||||
type = lib.types.str;
|
|
||||||
description = ''
|
|
||||||
User account under which vmagent runs.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
group = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "vmagent";
|
|
||||||
description = ''
|
|
||||||
Group under which vmagent runs.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "vmagent" { };
|
package = lib.mkPackageOption pkgs "vmagent" { };
|
||||||
|
|
||||||
dataDir = lib.mkOption {
|
remoteWrite = {
|
||||||
type = lib.types.str;
|
url = lib.mkOption {
|
||||||
default = "/var/lib/vmagent";
|
default = null;
|
||||||
description = ''
|
type = lib.types.nullOr lib.types.str;
|
||||||
The directory where vmagent stores its data files.
|
description = ''
|
||||||
'';
|
Endpoint for prometheus compatible remote_write
|
||||||
};
|
'';
|
||||||
|
};
|
||||||
remoteWriteUrl = lib.mkOption {
|
basicAuthUsername = lib.mkOption {
|
||||||
default = "http://localhost:8428/api/v1/write";
|
default = null;
|
||||||
type = lib.types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
description = ''
|
description = ''
|
||||||
The storage endpoint such as VictoriaMetrics
|
Basic Auth username used to connect to remote_write endpoint
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
basicAuthPasswordFile = lib.mkOption {
|
||||||
|
default = null;
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
description = ''
|
||||||
|
File that contains the Basic Auth password used to connect to remote_write endpoint
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
prometheusConfig = lib.mkOption {
|
prometheusConfig = lib.mkOption {
|
||||||
|
@ -68,36 +67,35 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
users.groups = lib.mkIf (cfg.group == "vmagent") { vmagent = { }; };
|
|
||||||
|
|
||||||
users.users = lib.mkIf (cfg.user == "vmagent") {
|
|
||||||
vmagent = {
|
|
||||||
group = cfg.group;
|
|
||||||
description = "vmagent daemon user";
|
|
||||||
home = cfg.dataDir;
|
|
||||||
isSystemUser = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ 8429 ];
|
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ 8429 ];
|
||||||
|
|
||||||
systemd.services.vmagent = let
|
systemd.services.vmagent = let
|
||||||
prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig;
|
prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig;
|
||||||
|
startCommandLine = lib.concatStringsSep " " ([
|
||||||
|
"${cfg.package}/bin/vmagent"
|
||||||
|
"-promscrape.config=${prometheusConfig}"
|
||||||
|
] ++ cfg.extraArgs
|
||||||
|
++ lib.optionals (cfg.remoteWrite.url != null) [
|
||||||
|
"-remoteWrite.url=${cfg.remoteWrite.url}"
|
||||||
|
"-remoteWrite.tmpDataPath=%C/vmagent/remote_write_tmp"
|
||||||
|
] ++ lib.optional (cfg.remoteWrite.basicAuthUsername != null) "-remoteWrite.basicAuth.username=${cfg.remoteWrite.basicAuthUsername}"
|
||||||
|
++ lib.optional (cfg.remoteWrite.basicAuthPasswordFile != null) "-remoteWrite.basicAuth.passwordFile=\${CREDENTIALS_DIRECTORY}/remote_write_basic_auth_password");
|
||||||
in {
|
in {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
description = "vmagent system service";
|
description = "vmagent system service";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
User = cfg.user;
|
DynamicUser = true;
|
||||||
Group = cfg.group;
|
User = "vmagent";
|
||||||
|
Group = "vmagent";
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
WorkingDirectory = cfg.dataDir;
|
CacheDirectory = "vmagent";
|
||||||
ExecStart = "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig} ${lib.escapeShellArgs cfg.extraArgs}";
|
ExecStart = startCommandLine;
|
||||||
|
LoadCredential = lib.optional (cfg.remoteWrite.basicAuthPasswordFile != null) [
|
||||||
|
"remote_write_basic_auth_password:${cfg.remoteWrite.basicAuthPasswordFile}"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.tmpfiles.rules =
|
|
||||||
[ "d '${cfg.dataDir}' 0755 ${cfg.user} ${cfg.group} -" ];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user