From 904a107d16b69f28b9d61c677eb27b953d421a54 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 9 Feb 2023 22:10:30 +0100 Subject: [PATCH] flakes: Ensure that `self.outPath == ./.` Users expect `self` to refer to the directory where the `flake.nix` file resides. --- src/libexpr/flake/call-flake.nix | 8 +++- tests/flakes/inputs.sh | 79 ++++++++++++++++++++++++++++++++ tests/local.mk | 1 + 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 tests/flakes/inputs.sh diff --git a/src/libexpr/flake/call-flake.nix b/src/libexpr/flake/call-flake.nix index 8061db3df..7dc03e7f5 100644 --- a/src/libexpr/flake/call-flake.nix +++ b/src/libexpr/flake/call-flake.nix @@ -9,14 +9,18 @@ let (key: node: let - sourceInfo = + rawSourceInfo = if key == lockFile.root then rootSrc else fetchTree (node.info or {} // removeAttrs node.locked ["dir"]); subdir = if key == lockFile.root then rootSubdir else node.locked.dir or ""; - flake = import (sourceInfo + (if subdir != "" then "/" else "") + subdir + "/flake.nix"); + outPath = rawSourceInfo + ((if subdir == "" then "" else "/") + subdir); + + sourceInfo = rawSourceInfo // { inherit outPath; }; + + flake = import (outPath + "/flake.nix"); inputs = builtins.mapAttrs (inputName: inputSpec: allNodes.${resolveInput inputSpec}) diff --git a/tests/flakes/inputs.sh b/tests/flakes/inputs.sh new file mode 100644 index 000000000..d6269fc59 --- /dev/null +++ b/tests/flakes/inputs.sh @@ -0,0 +1,79 @@ +source ./common.sh + +requireGit + + +test_subdir_self_path() { + baseDir=$TEST_ROOT/$RANDOM + flakeDir=$baseDir/b-low + mkdir -p $flakeDir + writeSimpleFlake $baseDir + writeSimpleFlake $flakeDir + + echo all good > $flakeDir/message + cat > $flakeDir/flake.nix < $flakeDir/message + cat > $flakeDir/flake.nix < $clientDir/flake.nix <