aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/populate')
-rw-r--r--pkgs/populate/src/populate.rs2
-rw-r--r--pkgs/populate/src/sh.rs14
-rw-r--r--pkgs/populate/tests/scenarios.nix22
3 files changed, 34 insertions, 4 deletions
diff --git a/pkgs/populate/src/populate.rs b/pkgs/populate/src/populate.rs
index 1aaf064..0659fe7 100644
--- a/pkgs/populate/src/populate.rs
+++ b/pkgs/populate/src/populate.rs
@@ -489,7 +489,7 @@ struct Symlink;
impl Kind for Symlink {
fn deliver(&self, d: &Delivery) -> Result<Outcome> {
let target = d.string("target")?;
- let output = d.context.output(sh::SYMLINK, &[d.path, target])?;
+ let output = d.context.output(&sh::symlink(), &[d.path, target])?;
Ok(Outcome::changed(output.contains("changed")).with("target", target))
}
}
diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs
index 71f5ebf..7f179e4 100644
--- a/pkgs/populate/src/sh.rs
+++ b/pkgs/populate/src/sh.rs
@@ -343,14 +343,22 @@ fi
}
/// symlink PATH TARGET: makes PATH a symlink to TARGET, printing changed
-/// if it wasn't one.
-pub const SYMLINK: &str = r#"
+/// if it wasn't one. What else is at PATH, e.g. the Git work tree of a
+/// source that had another type, gets removed first: ln -f replaces files
+/// and links, but not directories.
+pub fn symlink() -> String {
+ REMOVE_TREE.to_string()
+ + r#"
old=$(readlink "$1") || old=
+if ! test -L "$1" && test -e "$1"; then
+ remove_tree "$1"
+fi
ln -fnsT -- "$2" "$1"
if test "$old" != "$2"; then
echo changed
fi
-"#;
+"#
+}
/// Defines git_problems PATH, which prints why populate can't use the .git
/// directory of the Git work tree at PATH, or nothing. A .git directory
diff --git a/pkgs/populate/tests/scenarios.nix b/pkgs/populate/tests/scenarios.nix
index 33a2171..0c0ce9e 100644
--- a/pkgs/populate/tests/scenarios.nix
+++ b/pkgs/populate/tests/scenarios.nix
@@ -1096,6 +1096,28 @@ in
}
];
}))
+ # A symlink source where a directory is, e.g. a source that had another
+ # type: ln -f doesn't replace directories.
+ (s "symlink-replaces-directory" {
+ phases = [
+ {
+ sources.x.file = "/fixtures/alt";
+ check = ''
+ test -d "$T"/x || fail "x isn't a directory"
+ '';
+ }
+ {
+ sources = {
+ a.file = "/fixtures/alt";
+ x.symlink = "a";
+ };
+ check = ''
+ expect_eq x "$(readlink "$T"/x)" a
+ test -e "$T"/x/flake.nix || fail "flake.nix missing"
+ '';
+ }
+ ];
+ })
(s "cycle" {
phases = [{
sources = {