files: make sure the target file name is escaped
The previous implementation would allow variables to sneak into the file names. This commit makes sure the resulting target file path exactly matches the expected path.
This commit is contained in:
parent
209fb62d49
commit
4fe5afa755
|
@ -316,12 +316,15 @@ in
|
||||||
}
|
}
|
||||||
'' + concatStrings (
|
'' + concatStrings (
|
||||||
mapAttrsToList (n: v: ''
|
mapAttrsToList (n: v: ''
|
||||||
insertFile "${sourceStorePath v}" \
|
insertFile ${
|
||||||
"${v.target}" \
|
escapeShellArgs [
|
||||||
"${if v.executable == null
|
(sourceStorePath v)
|
||||||
then "inherit"
|
v.target
|
||||||
else builtins.toString v.executable}" \
|
(if v.executable == null
|
||||||
"${builtins.toString v.recursive}"
|
then "inherit"
|
||||||
|
else toString v.executable)
|
||||||
|
(toString v.recursive)
|
||||||
|
]}
|
||||||
'') cfg
|
'') cfg
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,5 +3,6 @@
|
||||||
files-hidden-source = ./hidden-source.nix;
|
files-hidden-source = ./hidden-source.nix;
|
||||||
files-out-of-store-symlink = ./out-of-store-symlink.nix;
|
files-out-of-store-symlink = ./out-of-store-symlink.nix;
|
||||||
files-source-with-spaces = ./source-with-spaces.nix;
|
files-source-with-spaces = ./source-with-spaces.nix;
|
||||||
|
files-target-with-shellvar = ./target-with-shellvar.nix;
|
||||||
files-text = ./text.nix;
|
files-text = ./text.nix;
|
||||||
}
|
}
|
||||||
|
|
15
tests/modules/files/target-with-shellvar.nix
Normal file
15
tests/modules/files/target-with-shellvar.nix
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
home.file."$HOME/$FOO/bar baz".text = "blah";
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileExists 'home-files/$HOME/$FOO/bar baz';
|
||||||
|
assertFileContent 'home-files/$HOME/$FOO/bar baz' \
|
||||||
|
${pkgs.writeText "expected" "blah"}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue