nixos/systemd.tmpfiles.packages: fix an edge case

symlinkJoin can break (silently) when the passed paths contain symlinks
to directories.  This should work now.

Down-side: when lib/tmpfiles.d doesn't exist for some passed package,
the error message is a little less explicit, because we never get
to the postBuild phase (and symlinkJoin doesn't provide a better way):
/nix/store/HASH-NAME/lib/tmpfiles.d: No such file or directory

Also, it seemed pointless to create symlinks for whole package trees
and using only a part of the result (usually very small part).
This commit is contained in:
Vladimír Čunát 2020-08-16 10:14:21 +02:00
parent 3ab2bf69ce
commit 3937923f81
No known key found for this signature in database
GPG key ID: E747DF1F9575A3AA
2 changed files with 7 additions and 5 deletions

View file

@ -1012,18 +1012,18 @@ in
"sysctl.d/50-coredump.conf".source = "${systemd}/example/sysctl.d/50-coredump.conf"; "sysctl.d/50-coredump.conf".source = "${systemd}/example/sysctl.d/50-coredump.conf";
"sysctl.d/50-default.conf".source = "${systemd}/example/sysctl.d/50-default.conf"; "sysctl.d/50-default.conf".source = "${systemd}/example/sysctl.d/50-default.conf";
"tmpfiles.d".source = (pkgs.symlinkJoin { "tmpfiles.d".source = pkgs.symlinkJoin {
name = "tmpfiles.d"; name = "tmpfiles.d";
paths = cfg.tmpfiles.packages; paths = map (p: p + "/lib/tmpfiles.d") cfg.tmpfiles.packages;
postBuild = '' postBuild = ''
for i in $(cat $pathsPath); do for i in $(cat $pathsPath); do
(test -d $i/lib/tmpfiles.d && test $(ls $i/lib/tmpfiles.d/*.conf | wc -l) -ge 1) || ( (test -d "$i" && test $(ls "$i"/*.conf | wc -l) -ge 1) || (
echo "ERROR: The path $i was passed to systemd.tmpfiles.packages but either does not contain the folder lib/tmpfiles.d or if it contains that folder, there are no files ending in .conf in it." echo "ERROR: The path '$i' from systemd.tmpfiles.packages contains no *.conf files."
exit 1 exit 1
) )
done done
''; '';
}) + "/lib/tmpfiles.d"; };
"systemd/system-generators" = { source = hooks "generators" cfg.generators; }; "systemd/system-generators" = { source = hooks "generators" cfg.generators; };
"systemd/system-shutdown" = { source = hooks "shutdown" cfg.shutdown; }; "systemd/system-shutdown" = { source = hooks "shutdown" cfg.shutdown; };

View file

@ -240,6 +240,8 @@ rec {
* This creates a single derivation that replicates the directory structure * This creates a single derivation that replicates the directory structure
* of all the input paths. * of all the input paths.
* *
* BEWARE: it may not "work right" when the passed paths contain symlinks to directories.
*
* Examples: * Examples:
* # adds symlinks of hello to current build. * # adds symlinks of hello to current build.
* symlinkJoin { name = "myhello"; paths = [ pkgs.hello ]; } * symlinkJoin { name = "myhello"; paths = [ pkgs.hello ]; }