From 6c7ad5e732428a4e8063144312d77544a867e08c Mon Sep 17 00:00:00 2001 From: emilylange Date: Wed, 1 Nov 2023 14:16:59 +0100 Subject: [PATCH] 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`. --- nixos/lib/systemd-lib.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix index fc95ab01289f..7b600464bb41 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" ]; } ''