Skip to content

Commit

Permalink
files: make sure the target file name is escaped
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rycee authored and aakropotkin committed Sep 9, 2020
1 parent eb43b5d commit 1911b0c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
15 changes: 9 additions & 6 deletions modules/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,15 @@ in
}
'' + concatStrings (
mapAttrsToList (n: v: ''
insertFile "${sourceStorePath v}" \
"${v.target}" \
"${if v.executable == null
then "inherit"
else builtins.toString v.executable}" \
"${builtins.toString v.recursive}"
insertFile ${
escapeShellArgs [
(sourceStorePath v)
v.target
(if v.executable == null
then "inherit"
else toString v.executable)
(toString v.recursive)
]}
'') cfg
));
};
Expand Down
1 change: 1 addition & 0 deletions tests/modules/files/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
files-hidden-source = ./hidden-source.nix;
files-out-of-store-symlink = ./out-of-store-symlink.nix;
files-source-with-spaces = ./source-with-spaces.nix;
files-target-with-shellvar = ./target-with-shellvar.nix;
files-text = ./text.nix;
}
15 changes: 15 additions & 0 deletions tests/modules/files/target-with-shellvar.nix
Original file line number Diff line number Diff line change
@@ -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"}
'';
};
}

0 comments on commit 1911b0c

Please sign in to comment.