From 437b0d1f95b73830b401968e4b326c1a7babab11 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 19 Apr 2026 10:38:05 +0100 Subject: [PATCH 1/2] feat: support inputs.self.submodules Peek at flake.nix before fetching the root source tree, similar to what Nix does; Nix models it with a lazy fetch, whereas we access the file directly. --- default.nix | 11 +++++- dev/config.nix | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/default.nix b/default.nix index a97b910..2316e26 100644 --- a/default.nix +++ b/default.nix @@ -133,7 +133,16 @@ 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; + res = builtins.fetchGit ( + { + url = src; + } + // (if submodules then { inherit submodules; } else { }) + ); in if res.rev == "0000000000000000000000000000000000000000" then removeAttrs res [ diff --git a/dev/config.nix b/dev/config.nix index 46f92d2..91b92f4 100644 --- a/dev/config.nix +++ b/dev/config.nix @@ -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 From 9680a5107f974df5a01d7fcd77a1ebe90cf5a8ee Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 19 Apr 2026 10:41:10 +0100 Subject: [PATCH 2/2] feat: support inputs.self.lfs Pass through lfs flag from flake.nix to builtins.fetchGit, same approach as submodules, but not tested. --- default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/default.nix b/default.nix index 2316e26..f681043 100644 --- a/default.nix +++ b/default.nix @@ -137,11 +137,13 @@ let # 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