Created
January 12, 2022 06:51
-
-
Save thufschmitt/5ad00ed77d751b4db309b666d448f779 to your computer and use it in GitHub Desktop.
Nix path&git behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
set -x | |
rm -rf A B | |
mkdir -p A B | |
pushd A | |
echo foo > foo | |
cat <<EOF > flake.nix | |
{ outputs = { self }: { foo = builtins.readFile "\${self}/foo"; }; } | |
EOF | |
git init | |
git add flake.nix | |
popd | |
pushd B | |
cat <<EOF > flake.nix | |
{ | |
inputs.A.url = "$(realpath ../A)"; | |
outputs = { self, A }: { | |
foo = A.foo; | |
}; | |
} | |
EOF | |
popd | |
# A#foo evaluatis iff A is taken as a `path:` input and not a `git+file:`input | |
nix eval "path:$(realpath A)"\#foo | |
( ! nix eval "git+file:$(realpath A)"\#foo ) | |
# Cli arguments resolve a plain path pointing to a git repo to git+file | |
(! nix eval ./A\#foo) | |
# Same for flake inputs | |
(! nix eval ./B\#foo) | |
# builtins.getFlake don’t | |
nix eval --impure --expr '(builtins.getFlake "'$(realpath A)'").foo' | |
# Neither do the registry | |
nix registry add A "$(realpath A)" --option flake-registry "$PWD/registry.json" | |
nix eval ./B\#foo --option flake-registry "$PWD/registry.json" --override-input A A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment