Skip to content

Instantly share code, notes, and snippets.

@thufschmitt
Created January 12, 2022 06:51
Show Gist options
  • Save thufschmitt/5ad00ed77d751b4db309b666d448f779 to your computer and use it in GitHub Desktop.
Save thufschmitt/5ad00ed77d751b4db309b666d448f779 to your computer and use it in GitHub Desktop.
Nix path&git behavior
#!/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