diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-20 07:43:02 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-20 07:43:02 +0000 |
| commit | f93fc0a691544cc3ddda322a7e99d0534d636dcc (patch) | |
| tree | b6822c0499b4f838601182d4609536d586da6d0f /nix | |
| parent | 1d58ee5b01e28f77f736c9f415e0cc869a244cc6 (diff) | |
fix(nix): auto-create data directories with ExecStartPre
Add ExecStartPre directives to ensure data directories exist before
service starts. This fixes service failures when using custom dataDir
paths that don't exist yet.
The tmpfiles.rules weren't automatically executed during nixos-rebuild
switch, causing 'status=226/NAMESPACE' errors. ExecStartPre runs as
root (+ prefix) to create directories with proper ownership/permissions.
Diffstat (limited to 'nix')
| -rw-r--r-- | nix/module.nix | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/nix/module.nix b/nix/module.nix index 5debc9e..40bc868 100644 --- a/nix/module.nix +++ b/nix/module.nix | |||
| @@ -326,6 +326,20 @@ let | |||
| 326 | # Working directory where .relay-owner.nsec will be created if needed | 326 | # Working directory where .relay-owner.nsec will be created if needed |
| 327 | WorkingDirectory = cfg.dataDir; | 327 | WorkingDirectory = cfg.dataDir; |
| 328 | 328 | ||
| 329 | # Ensure data directories exist before service starts | ||
| 330 | # The + prefix runs these commands as root | ||
| 331 | # This is necessary because tmpfiles.rules aren't automatically executed | ||
| 332 | # during nixos-rebuild switch, causing service failures with custom dataDirs | ||
| 333 | ExecStartPre = [ | ||
| 334 | "+${pkgs.coreutils}/bin/mkdir -p '${cfg.dataDir}'" | ||
| 335 | "+${pkgs.coreutils}/bin/mkdir -p '${cfg.dataDir}/git'" | ||
| 336 | "+${pkgs.coreutils}/bin/mkdir -p '${cfg.dataDir}/relay'" | ||
| 337 | "+${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} '${cfg.dataDir}'" | ||
| 338 | "+${pkgs.coreutils}/bin/chmod 750 '${cfg.dataDir}'" | ||
| 339 | "+${pkgs.coreutils}/bin/chmod 750 '${cfg.dataDir}/git'" | ||
| 340 | "+${pkgs.coreutils}/bin/chmod 750 '${cfg.dataDir}/relay'" | ||
| 341 | ]; | ||
| 342 | |||
| 329 | # Add git, openssh, and coreutils to PATH for purgatory sync operations | 343 | # Add git, openssh, and coreutils to PATH for purgatory sync operations |
| 330 | Environment = | 344 | Environment = |
| 331 | "PATH=${pkgs.git}/bin:${pkgs.openssh}/bin:${pkgs.coreutils}/bin"; | 345 | "PATH=${pkgs.git}/bin:${pkgs.openssh}/bin:${pkgs.coreutils}/bin"; |
| @@ -373,7 +387,9 @@ let | |||
| 373 | SystemCallErrorNumber = "EPERM"; | 387 | SystemCallErrorNumber = "EPERM"; |
| 374 | }; | 388 | }; |
| 375 | 389 | ||
| 376 | # Directory creation handled by systemd tmpfiles (see config section below) | 390 | # Directory creation handled by both ExecStartPre (above) and tmpfiles (below) |
| 391 | # ExecStartPre ensures directories exist at service start time | ||
| 392 | # tmpfiles provides boot-time setup and consistency | ||
| 377 | }; | 393 | }; |
| 378 | 394 | ||
| 379 | enabledInstances = | 395 | enabledInstances = |