lib: ensure directories of linkFarm links exist (#45628)

There's no reason `linkFarm` can't be used for symlinks in
subdirectories, except that currently it doesn't ensure the directory
of the link exists. This backwards-compatible change expands the utility
of the function.
This commit is contained in:
Alyssa Ross 2018-09-01 14:53:23 +02:00 committed by xeji
parent 173e48d5dd
commit 4af7278bc9

View File

@ -145,7 +145,10 @@ rec {
# entries is a list of attribute sets like { name = "name" ; path = "/nix/store/..."; }
linkFarm = name: entries: runCommand name { preferLocalBuild = true; }
("mkdir -p $out; cd $out; \n" +
(lib.concatMapStrings (x: "ln -s '${x.path}' '${x.name}';\n") entries));
(lib.concatMapStrings (x: ''
mkdir -p "$(dirname '${x.name}')"
ln -s '${x.path}' '${x.name}'
'') entries));
# Print an error message if the file with the specified name and