Skip to content

Commit b5b6055

Browse files
authored
Merge pull request #8064 from knedlsepp/flake-in-submodule
Add a test with flake.nix in a git submodule
2 parents 790dd25 + bf0c8c3 commit b5b6055

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

tests/flakes/flake-in-submodule.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
source common.sh
2+
3+
# Tests that:
4+
# - flake.nix may reside inside of a git submodule
5+
# - the flake can access content outside of the submodule
6+
#
7+
# rootRepo
8+
# ├── root.nix
9+
# └── submodule
10+
# ├── flake.nix
11+
# └── sub.nix
12+
13+
14+
requireGit
15+
16+
clearStore
17+
18+
# Submodules can't be fetched locally by default.
19+
# See fetchGitSubmodules.sh
20+
export XDG_CONFIG_HOME=$TEST_HOME/.config
21+
git config --global protocol.file.allow always
22+
23+
24+
rootRepo=$TEST_ROOT/rootRepo
25+
subRepo=$TEST_ROOT/submodule
26+
27+
28+
createGitRepo $subRepo
29+
cat > $subRepo/flake.nix <<EOF
30+
{
31+
outputs = { self }: {
32+
sub = import ./sub.nix;
33+
root = import ../root.nix;
34+
};
35+
}
36+
EOF
37+
echo '"expression in submodule"' > $subRepo/sub.nix
38+
git -C $subRepo add flake.nix sub.nix
39+
git -C $subRepo commit -m Initial
40+
41+
createGitRepo $rootRepo
42+
43+
git -C $rootRepo submodule init
44+
git -C $rootRepo submodule add $subRepo submodule
45+
echo '"expression in root repo"' > $rootRepo/root.nix
46+
git -C $rootRepo add root.nix
47+
git -C $rootRepo commit -m "Add root.nix"
48+
49+
# Flake can live inside a submodule and can be accessed via ?dir=submodule
50+
[[ $(nix eval --json git+file://$rootRepo\?submodules=1\&dir=submodule#sub ) = '"expression in submodule"' ]]
51+
# The flake can access content outside of the submodule
52+
[[ $(nix eval --json git+file://$rootRepo\?submodules=1\&dir=submodule#root ) = '"expression in root repo"' ]]

tests/local.mk

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ nix_tests = \
1313
flakes/unlocked-override.sh \
1414
flakes/absolute-paths.sh \
1515
flakes/build-paths.sh \
16+
flakes/flake-in-submodule.sh \
1617
ca/gc.sh \
1718
gc.sh \
1819
remote-store.sh \

0 commit comments

Comments
 (0)