From e671a4bd465cbef817859c4463081fb819cd2fcc Mon Sep 17 00:00:00 2001 From: Shay Bergmann Date: Thu, 4 Nov 2021 12:59:16 -0400 Subject: [PATCH] Add test to demonstrate --- tests/flakes-with-submodules.sh | 120 ++++++++++++++++++++++++++++++++ tests/local.mk | 1 + 2 files changed, 121 insertions(+) create mode 100644 tests/flakes-with-submodules.sh diff --git a/tests/flakes-with-submodules.sh b/tests/flakes-with-submodules.sh new file mode 100644 index 000000000000..ee8f5e694711 --- /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 8d454ee1962e..54f38a27390a 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 \