diff --git a/tests/flakes-with-submodules.sh b/tests/flakes-with-submodules.sh new file mode 100644 index 00000000000..ee8f5e69471 --- /dev/null +++ b/tests/flakes-with-submodules.sh @@ -0,0 +1,120 @@ +source common.sh + +if [[ -z $(type -p git) ]]; then + echo "Git not installed; skipping flake tests" + exit 99 +fi + +clearStore +rm -rf $TEST_HOME/.cache $TEST_HOME/.config + +registry=$TEST_ROOT/registry.json + +nonFlakeDir=$TEST_ROOT/nonFlake +flakeDir=$TEST_ROOT/flake +flakeWithSubmodules=$TEST_ROOT/flakeWithSubmodules + +for repo in $flakeDir $nonFlakeDir $flakeWithSubmodules; do + rm -rf $repo $repo.tmp + mkdir -p $repo + git -C $repo init + git -C $repo config user.email "foobar@example.com" + git -C $repo config user.name "Foobar" +done + +for dir in $nonFlakeDir $flakeDir; do +cat > $dir/README.md < $flakeDir/flake.nix < \$bin + echo '\${script}' >> \$bin + /bin/chmod +x \$bin + '') + ]; + }; + in { + packages.$system = { + cat-own-readme = writeShellScriptBin "cat-own-readme" '' + cat \${self}/README.md + ''; + }; + + defaultPackage.$system = self.packages.$system.cat-own-readme; + }; +} +EOF + +git -C $flakeDir add . +git -C $flakeDir commit -m'add flake.nix' + +[[ $(nix run $flakeDir#cat-own-readme) == "FNORD" ]] + +git -C $flakeWithSubmodules submodule add $nonFlakeDir +git -C $flakeWithSubmodules submodule add $flakeDir +git -C $flakeWithSubmodules add . +git -C $flakeWithSubmodules commit -m'add submodules' + +cat > $flakeWithSubmodules/flake.nix < \$bin + echo '\${script}' >> \$bin + /bin/chmod +x \$bin + '') + ]; + }; + in { + packages.$system = { + cat-submodule-readme = writeShellScriptBin "cat-submodule-readme" '' + cat \${nonFlake}/README.md + ''; + use-submodule-as-flake = flake.packages.$system.cat-own-readme; + }; + + defaultPackage.$system = self.packages.$system.cat-submodule-readme; + }; +} +EOF + +git -C $flakeWithSubmodules add . +git -C $flakeWithSubmodules commit -m'add flake.nix' + +[[ $(nix run $flakeWithSubmodules#cat-submodule-readme) == "FNORD" ]] +[[ $(nix run $flakeWithSubmodules#use-submodule-as-flake) == "FNORD" ]] + +# TODO make the dirty case do the Right Thing as well. +#echo FSOUTH > $flakeWithSubmodules/nonFlake/README.md +#[[ $(nix run $flakeWithSubmodules#cat-submodule-readme) == "FSOUTH" ]] +# [[ $(nix run $flakeWithSubmodules#use-submodule-as-flake) == "FSOUTH" ]] +# nix run -vv $flakeWithSubmodules#cat-submodule-readme diff --git a/tests/local.mk b/tests/local.mk index 8d454ee1962..54f38a27390 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -46,6 +46,7 @@ nix_tests = \ recursive.sh \ describe-stores.sh \ flakes.sh \ + flakes-with-submodules.sh \ build.sh \ compute-levels.sh \ repl.sh \