summary refs log tree commit diff
path: root/nixos/lib/systemd-lib.nix
diff options
context:
space:
mode:
authoremilylange <git@emilylange.de>2023-11-01 14:16:59 +0100
committeremilylange <git@emilylange.de>2023-11-02 01:18:46 +0100
commit6c7ad5e732428a4e8063144312d77544a867e08c (patch)
tree26defe4c7ec61a28be39d97e6914b404ffd03313 /nixos/lib/systemd-lib.nix
parent90b0f71e5dde473bff380aa1776015da194556bd (diff)
downloadnixpkgs-6c7ad5e732428a4e8063144312d77544a867e08c.tar
nixpkgs-6c7ad5e732428a4e8063144312d77544a867e08c.tar.gz
nixpkgs-6c7ad5e732428a4e8063144312d77544a867e08c.tar.bz2
nixpkgs-6c7ad5e732428a4e8063144312d77544a867e08c.tar.lz
nixpkgs-6c7ad5e732428a4e8063144312d77544a867e08c.tar.xz
nixpkgs-6c7ad5e732428a4e8063144312d77544a867e08c.tar.zst
nixpkgs-6c7ad5e732428a4e8063144312d77544a867e08c.zip
nixos/systemd-lib: fix building of empty unit files
This is a fixup for c1ae82f448b10b278dc77e02518775175b463a27.

nix' `passAsFile` does not create empty files for variables that are
`null`.

This results in the following error for units that have no overrides or
content, but are, e.g. `wantedBy`:
`mv: cannot stat '': No such file or directory`.

Minimal reproducer:
`systemd.units.empty.wantedBy = [ "multi-user.target" ];`

This is often necessary when a unit is loaded in via `systemd.packages`.
Diffstat (limited to 'nixos/lib/systemd-lib.nix')
-rw-r--r--nixos/lib/systemd-lib.nix5
1 files changed, 4 insertions, 1 deletions
diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix
index fc95ab01289..7b600464bb4 100644
--- a/nixos/lib/systemd-lib.nix
+++ b/nixos/lib/systemd-lib.nix
@@ -20,7 +20,10 @@ in rec {
       pkgs.runCommand "unit-${mkPathSafeName name}"
         { preferLocalBuild = true;
           allowSubstitutes = false;
-          inherit (unit) text;
+          # unit.text can be null. But variables that are null listed in
+          # passAsFile are ignored by nix, resulting in no file being created,
+          # making the mv operation fail.
+          text = optionalString (unit.text != null) unit.text;
           passAsFile = [ "text" ];
         }
         ''