Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,18 @@ let
src:
if isGit then
let
res = builtins.fetchGit src;
# Peek at flake.nix to check for submodule settings, mirroring
# what Nix does (lazy fetch of flake.nix before full fetch).
flake = import (src + "/flake.nix");
submodules = flake.inputs.self.submodules or false;
lfs = flake.inputs.self.lfs or false;
res = builtins.fetchGit (
{
url = src;
}
// (if submodules then { inherit submodules; } else { })
// (if lfs then { inherit lfs; } else { })
);
in
if res.rev == "0000000000000000000000000000000000000000" then
removeAttrs res [
Expand Down
90 changes: 90 additions & 0 deletions dev/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,96 @@

echo "All tests passed!"
'';

# Integration test: submodule content is accessible through flake-compat
submodules =
pkgs.runCommand "submodule-test"
{
nativeBuildInputs = [
pkgs.git
pkgs.nix
];
}
''
export HOME=$TMPDIR
git config --global user.email "test@test"
git config --global user.name "test"
git config --global protocol.file.allow always

# Create a repo to use as a submodule
mkdir -p $TMPDIR/sub
cd $TMPDIR/sub
git init
echo "hello from submodule" > sub-file.txt
git add . && git commit -m "init sub"

# Invoke flake-compat using an alternative store so this
# works in sandboxed builds on both Linux and darwin.
export NIX_STORE_DIR=$TMPDIR/store
export NIX_STATE_DIR=$TMPDIR/state

# Without inputs.self.submodules, submodule content should
# not be accessible.
mkdir -p $TMPDIR/main-no-sub
cd $TMPDIR/main-no-sub
git init
git submodule add $TMPDIR/sub sub
cat > flake.nix << 'EOF'
{
outputs = { self, ... }: {
subFileExists = builtins.pathExists (self + "/sub/sub-file.txt");
};
}
EOF
git add . && git commit -m "init main-no-sub"

result=$(nix-instantiate --eval --strict --expr '
let
r = import ${../.} { src = '"$TMPDIR/main-no-sub"'; };
in
r.defaultNix.subFileExists
')

if [ "$result" = "false" ]; then
echo "PASS: submodule content not accessible without flag"
else
echo "FAIL: expected false, got: $result"
exit 1
fi

# With inputs.self.submodules = true, submodule content
# should be accessible.
mkdir -p $TMPDIR/main
cd $TMPDIR/main
git init
git submodule add $TMPDIR/sub sub
cat > flake.nix << 'EOF'
{
inputs.self.submodules = true;
outputs = { self, ... }: {
subFileExists = builtins.pathExists (self + "/sub/sub-file.txt");
subFileContent = builtins.readFile (self + "/sub/sub-file.txt");
};
}
EOF
git add . && git commit -m "init main"

result=$(nix-instantiate --eval --strict --expr '
let
r = import ${../.} { src = '"$TMPDIR/main"'; };
in
r.defaultNix.subFileContent
')

if [ "$result" = '"hello from submodule\n"' ]; then
echo "PASS: submodule content accessible"
else
echo "FAIL: expected submodule content, got: $result"
exit 1
fi

touch $out
'';
};

# Development shell
Expand Down