linkFarm: allow files/directories with leading dashes

Calling linkFarm with leading dashes, makes the used coreutils commands
misidentify a filename, like "-foo", as a list of options, instead of
an positional argument.
This commit is contained in:
ItsBasi 2025-06-14 11:29:48 +02:00
parent 18d794dd01
commit b1a3c47018
2 changed files with 11 additions and 2 deletions

View File

@ -671,8 +671,8 @@ rec {
throw "linkFarm entries must be either attrs or a list!";
linkCommands = lib.mapAttrsToList (name: path: ''
mkdir -p "$(dirname ${lib.escapeShellArg "${name}"})"
ln -s ${lib.escapeShellArg "${path}"} ${lib.escapeShellArg "${name}"}
mkdir -p -- "$(dirname -- ${lib.escapeShellArg "${name}"})"
ln -s -- ${lib.escapeShellArg "${path}"} ${lib.escapeShellArg "${name}"}
'') entries';
in
runCommand name

View File

@ -39,6 +39,11 @@ let
linkFarmFromAttrs = linkFarm "linkFarmFromAttrs" {
inherit foo hello;
};
linkFarmDelimitOptionList = linkFarm "linkFarmDelimitOptionList" {
"-foo" = foo;
"-hello" = hello;
};
in
runCommand "test-linkFarm" { } ''
function assertPathEquals() {
@ -61,5 +66,9 @@ runCommand "test-linkFarm" { } ''
assertPathEquals "${linkFarmFromAttrs}/foo" "${foo}"
assertPathEquals "${linkFarmFromAttrs}/hello" "${hello}"
assertPathEquals "${linkFarmDelimitOptionList}/-foo" "${foo}"
assertPathEquals "${linkFarmDelimitOptionList}/-hello" "${hello}"
touch $out
''