Merge pull request #306074 from leona-ya/vmagent-cleanup
nixos/vmagent: use dynamic user and cache directory, cleanup
This commit is contained in:
commit
ac693bd806
@ -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.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).
|
||||
|
||||
- `services.nginx` will no longer advertise HTTP/3 availability automatically. This must now be manually added, preferably to each location block.
|
||||
|
@ -1,63 +1,62 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.vmagent;
|
||||
settingsFormat = pkgs.formats.json { };
|
||||
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 = {
|
||||
enable = mkEnableOption "vmagent";
|
||||
enable = lib.mkEnableOption "vmagent";
|
||||
|
||||
user = mkOption {
|
||||
default = "vmagent";
|
||||
type = types.str;
|
||||
package = lib.mkPackageOption pkgs "vmagent" { };
|
||||
|
||||
remoteWrite = {
|
||||
url = lib.mkOption {
|
||||
default = null;
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
description = ''
|
||||
User account under which vmagent runs.
|
||||
Endpoint for prometheus compatible remote_write
|
||||
'';
|
||||
};
|
||||
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = "vmagent";
|
||||
basicAuthUsername = lib.mkOption {
|
||||
default = null;
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
description = ''
|
||||
Group under which vmagent runs.
|
||||
Basic Auth username used to connect to remote_write endpoint
|
||||
'';
|
||||
};
|
||||
|
||||
package = mkPackageOption pkgs "vmagent" { };
|
||||
|
||||
dataDir = mkOption {
|
||||
type = types.str;
|
||||
default = "/var/lib/vmagent";
|
||||
basicAuthPasswordFile = lib.mkOption {
|
||||
default = null;
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
description = ''
|
||||
The directory where vmagent stores its data files.
|
||||
File that contains the Basic Auth password used to connect to remote_write endpoint
|
||||
'';
|
||||
};
|
||||
|
||||
remoteWriteUrl = mkOption {
|
||||
default = "http://localhost:8428/api/v1/write";
|
||||
type = types.str;
|
||||
description = ''
|
||||
The storage endpoint such as VictoriaMetrics
|
||||
'';
|
||||
};
|
||||
|
||||
prometheusConfig = mkOption {
|
||||
prometheusConfig = lib.mkOption {
|
||||
type = lib.types.submodule { freeformType = settingsFormat.type; };
|
||||
description = ''
|
||||
Config for prometheus style metrics
|
||||
'';
|
||||
};
|
||||
|
||||
openFirewall = mkOption {
|
||||
type = types.bool;
|
||||
openFirewall = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to open the firewall for the default ports.
|
||||
'';
|
||||
};
|
||||
|
||||
extraArgs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
extraArgs = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [];
|
||||
description = ''
|
||||
Extra args to pass to `vmagent`. See the docs:
|
||||
@ -67,37 +66,36 @@ in {
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
users.groups = mkIf (cfg.group == "vmagent") { vmagent = { }; };
|
||||
|
||||
users.users = mkIf (cfg.user == "vmagent") {
|
||||
vmagent = {
|
||||
group = cfg.group;
|
||||
description = "vmagent daemon user";
|
||||
home = cfg.dataDir;
|
||||
isSystemUser = true;
|
||||
};
|
||||
};
|
||||
|
||||
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 8429 ];
|
||||
config = lib.mkIf cfg.enable {
|
||||
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ 8429 ];
|
||||
|
||||
systemd.services.vmagent = let
|
||||
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 {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
description = "vmagent system service";
|
||||
serviceConfig = {
|
||||
User = cfg.user;
|
||||
Group = cfg.group;
|
||||
DynamicUser = true;
|
||||
User = "vmagent";
|
||||
Group = "vmagent";
|
||||
Type = "simple";
|
||||
Restart = "on-failure";
|
||||
WorkingDirectory = cfg.dataDir;
|
||||
ExecStart = "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig} ${escapeShellArgs cfg.extraArgs}";
|
||||
CacheDirectory = "vmagent";
|
||||
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} -" ];
|
||||
};
|
||||
}
|
||||
|
@ -22,6 +22,6 @@ buildGoModule rec {
|
||||
mainProgram = "vmagent";
|
||||
license = licenses.asl20;
|
||||
platforms = platforms.linux;
|
||||
maintainers = with maintainers; [ nullx76 ];
|
||||
maintainers = with maintainers; [ nullx76 leona ];
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user