diff options
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | pkgs/populate/default.nix | 10 | ||||
| -rw-r--r-- | tests/scenarios.nix | 45 |
4 files changed, 59 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3875460..d71c57e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - `git` sources also refuse work trees whose `.git` directory contains hooks, or in which a submodule's `.git` isn't a file naming a repository in `.git/modules`, unless `reclone` is set. +- Drawing inputs refers to a source in a Git work tree as `git+file:` only + if a `git` source would use its `.git` directory, and else as `path:`. - `git` sources with a branch or tag as `ref` follow it: populate fetches the branch or tag on every run, and resets the work tree to what it fetched. @@ -707,7 +707,10 @@ drawing an input from a source with a generated flake uses that flake. automatically. Sources in a Git work tree are referred to as `git+file:` (with submodules if -there are any), all other sources as `path:`, with symlinks resolved. Lock +there are any), all other sources as `path:`, with symlinks resolved. Nix +runs Git in a `git+file:` flake, so that's only for work trees whose `.git` +directory a `git` source would use, see +[The target directory](#the-target-directory). Lock files get rewritten or generated on every run, so they match the sources. Copies of `flake` and `flake-input` sources get made again only if the delivered store path, the patches, or the sources they draw inputs from diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index b724b23..7b22662 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -608,14 +608,20 @@ let fi } - # Prints the flake URL of the source named $1. + ${gitProblems} + # Prints the flake URL of the source named $1: git+file: if it has a + # .git directory git_problems finds nothing wrong with, else path:. + # Nix runs Git in a git+file: flake, with the repository's + # configuration and hooks. flake_url() { path=$(readlink -f ${quote target.path}/"$1") if ! test -d "$path"; then >&2 printf 'error: source %s is not a directory\n' "$1" exit 1 fi - if test -e "$path"/.git; then + if ! test -L "$path"/.git && test -d "$path"/.git && + problems=$(git_problems "$path" 2>/dev/null) && + test -z "$problems"; then if test -e "$path"/.gitmodules; then printf 'git+file:%s?submodules=1' "$(url_path "$path")" else diff --git a/tests/scenarios.nix b/tests/scenarios.nix index 5d08e2e..43b63b4 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -2187,6 +2187,51 @@ assert !(krops.isLocalTarget (targets.remote "/")); } ]; })) + # A .git that a materialized flake got, and one that a file source + # keeps, which Nix uses for the git+file: URL of the flake there: writing + # its lock file, Nix runs Git, with that repository's configuration. + (s "lock-foreign-git" (let + elsewhere = "/var/krops-elsewhere"; + sources = alt // { + x.flake-input = { + url = "/fixtures/top"; name = "dep"; inherit fetchOnTarget; + materialize = true; + inputs.inner.follows = "alt"; + }; + y.file = { + path = "/fixtures/filesrc"; + deleteExcluded = false; + filters = [ { type = "exclude"; pattern = "/.git"; } ]; + inputs.dep.follows = "alt"; + }; + }; + in { + isolate = true; + prepare = '' + rm -fR ${elsewhere} + mkdir -p ${elsewhere} + ''; + phases = [ + { + inherit sources; + # Repositories tracking only flake.nix, so the lock file changes. + mutate = '' + for name in x y; do + git -C "$T"/$name init -q + git -C "$T"/$name add flake.nix + git -C "$T"/$name -c user.name=x -c user.email=x@x commit -q -m x + git -C "$T"/$name config core.fsmonitor "touch ${elsewhere}/ran; false" + done + ''; + } + { + inherit sources; + check = '' + test ! -e ${elsewhere}/ran || fail "a command in a .git directory ran" + ''; + } + ]; + })) # A file in populate's state replaced by a symlink to a file outside. (s "state-key" (let sources.x.flake-input = { |
