diff options
| -rw-r--r-- | pkgs/populate/default.nix | 18 | ||||
| -rw-r--r-- | tests/scenarios.nix | 19 |
2 files changed, 37 insertions, 0 deletions
diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index 708e7a3..66c88c1 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -158,6 +158,17 @@ let mkdir -p ${quote flakesDir} ${concatMapStrings flake sorted.result} ''} + # Remove roots of flake inputs of sources that are neither flake nor + # flake-input sources anymore. + ${concatMapStrings (name: /* sh */ '' + rm -fR ${quote "${target.path}/.populate/flake-inputs/${name}"} + '') (attrNames (filterAttrs + (_: source: !elem source.type [ "flake" "flake-input" ]) + sources))} + if test -d ${quote "${target.path}/.populate/flake-inputs"} && + test -z "$(ls -A ${quote "${target.path}/.populate/flake-inputs"})"; then + rmdir ${quote "${target.path}/.populate/flake-inputs"} + fi # Remove flakes of sources that no longer draw inputs from other sources. if test -d ${quote flakesDir}; then ls -A ${quote flakesDir} | while read -r name; do @@ -767,6 +778,13 @@ let ''; rsync' = target: config: sourcePath: /* sh */ '' + # rsync writes through a symlink at the target path, e.g. one a symlink or + # flake source left there, into what it points to. + ${runShell target /* sh */ '' + if test -L ${quote target.path}; then + rm ${quote target.path} + fi + ''} source_path=${sourcePath} if test -d "$source_path"; then source_path=$source_path/ diff --git a/tests/scenarios.nix b/tests/scenarios.nix index a738eca..38f8736 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -808,6 +808,25 @@ assert !(krops.isLocalTarget (targets.remote "/")); check = checkFlake { attr = "msg"; expected = "rel:lib"; }; }; }) + (s "flake-to-file" { + phases = [ + { + sources.x.flake = { flake = "/fixtures/top"; inherit fetchOnTarget; }; + check = roots 3; + mutate = '' + readlink "$T"/x > "$T"/old + ''; + } + { + sources.x.file = "/fixtures/alt"; + check = '' + test ! -L "$T"/x || fail "x is still a link to $(readlink "$T"/x)" + test -e "$T"/x/flake.nix || fail "flake.nix missing" + nix-store --verify-path "$(cat "$T"/old)" || fail "store path changed" + '' + roots 0; + } + ]; + }) ] ++ lib.optional (targetKind == "local") # The target has the path the input is locked to. (s "uselocal" { |
