Skip to content

Commit e4c2561

Browse files
authored
fix: victoriametrics (#172)
* chore: update aqua's host key * fix: victoriametrics * feat: adjust order of nix cache mirrors * feat: update mysecrets * fix: use bind mount - Failed at step STATE_DIRECTORY
1 parent 7c18b85 commit e4c2561

File tree

5 files changed

+30
-23
lines changed

5 files changed

+30
-23
lines changed

flake.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hosts/idols-aquamarine/monitoring/module/default.nix

+12-15
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,23 @@ with lib; let
88
cfg = config.services.my-victoriametrics;
99
settingsFormat = pkgs.formats.yaml {};
1010

11-
workingDir = "/var/lib/" + cfg.stateDir;
12-
startCommandLine =
13-
lib.escapeShellArgs [
11+
startCLIList =
12+
[
1413
"${cfg.package}/bin/victoria-metrics"
15-
"-storageDataPath=${workingDir}"
14+
"-storageDataPath=/var/lib/${cfg.stateDir}"
1615
"-httpListenAddr=${cfg.listenAddress}"
1716
"-retentionPeriod=${cfg.retentionPeriod}"
1817
]
19-
++ lib.optional (cfg.prometheusConfig != null) "-promscrape.config=${prometheusConfigYml}"
2018
++ cfg.extraOptions;
2119
prometheusConfigYml = checkedConfig (
2220
settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig
2321
);
2422

2523
checkedConfig = file:
26-
if cfg.checkConfig
27-
then
28-
pkgs.runCommand "checked-config" {nativeBuildInputs = [cfg.package];} ''
29-
ln -s ${file} $out
30-
${startCommandLine} -dryRun
31-
''
32-
else file;
24+
pkgs.runCommand "checked-config" {nativeBuildInputs = [cfg.package];} ''
25+
ln -s ${file} $out
26+
${lib.escapeShellArgs startCLIList} -promscrape.config=${file} -dryRun
27+
'';
3328
in {
3429
options.services.my-victoriametrics = {
3530
enable = mkEnableOption "VictoriaMetrics, a time series database.";
@@ -130,15 +125,17 @@ in {
130125
startLimitBurst = 5;
131126

132127
serviceConfig = {
133-
ExecStart = startCommandLine;
128+
ExecStart = lib.escapeShellArgs (
129+
startCLIList
130+
++ lib.optional (cfg.prometheusConfig != null) ["-promscrape.config=${prometheusConfigYml}"]
131+
);
132+
134133
DynamicUser = true;
135134
User = "victoriametrics";
136-
Group = "victoriametrics";
137135
RestartSec = 1;
138136
Restart = "on-failure";
139137
RuntimeDirectory = "victoriametrics";
140138
RuntimeDirectoryMode = "0700";
141-
WorkingDirectory = workingDir;
142139
StateDirectory = cfg.stateDir;
143140
StateDirectoryMode = "0700";
144141

hosts/idols-aquamarine/monitoring/victoriametrics.nix

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@
33
myvars,
44
...
55
}: {
6+
# Since victoriametrics use DynamicUser, the user & group do not exists before the service starts.
7+
# this group is used as a supplementary Unix group for the service to access our data dir(/data/apps/xxx)
8+
users.groups.victoriametrics-data = {};
9+
610
# Workaround for victoriametrics to store data in another place
711
# https://www.freedesktop.org/software/systemd/man/latest/tmpfiles.d.html#Type
812
systemd.tmpfiles.rules = [
9-
"D /data/apps/victoriametrics 0751 victoriametrics victoriametrics - -"
10-
"L+ /var/lib/victoriametrics - - - - /data/apps/victoriametrics"
13+
"D /data/apps/victoriametrics 0770 root victoriametrics-data - -"
1114
];
1215

16+
# Symlinks do not work with DynamicUser, so we should use bind mount here.
17+
# https://github.com/systemd/systemd/issues/25097#issuecomment-1929074961
18+
systemd.services.victoriametrics.serviceConfig = {
19+
SupplementaryGroups = ["victoriametrics-data"];
20+
BindPaths = ["/data/apps/victoriametrics:/var/lib/victoriametrics:rbind"];
21+
};
22+
1323
# https://victoriametrics.io/docs/victoriametrics/latest/configuration/configuration/
1424
services.my-victoriametrics = {
1525
enable = true;

modules/base.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@
9090
# substituers that will be considered before the official ones(https://cache.nixos.org)
9191
substituters = [
9292
# cache mirror located in China
93-
# status: https://mirror.sjtu.edu.cn/
94-
"https://mirror.sjtu.edu.cn/nix-channels/store"
9593
# status: https://mirrors.ustc.edu.cn/status/
9694
"https://mirrors.ustc.edu.cn/nix-channels/store"
9795
"https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
96+
# status: https://mirror.sjtu.edu.cn/
97+
"https://mirror.sjtu.edu.cn/nix-channels/store"
9898

9999
"https://nix-community.cachix.org"
100100
# my own cache server

vars/networking.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
publicKey = value.publicKey;
194194
})
195195
{
196-
aquamarine.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIbIecyrmrBpjD497lA2adJeTpsubZ3dozEraLGCcgVi root@aquamarine";
196+
aquamarine.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEOXFhFu9Duzp6ZBE288gDZ6VLrNaeWL4kDrFUh9Neic root@aquamarine";
197197
# ruby.publicKey = "";
198198
# kana.publicKey = "";
199199
};

0 commit comments

Comments
 (0)