forked from lix-project/lix
Merge pull request #7796 from hercules-ci/fix-7263
Ensure that `self.outPath == ./.`
This commit is contained in:
commit
995bfeef3b
4 changed files with 105 additions and 2 deletions
|
@ -3,6 +3,12 @@
|
|||
* A new function `builtins.readFileType` is available. It is similar to
|
||||
`builtins.readDir` but acts on a single file or directory.
|
||||
|
||||
* In flakes, the `.outPath` attribute of a flake now always refers to the
|
||||
directory containing the `flake.nix`. This was not the case for when
|
||||
`flake.nix` was in a subdirectory of e.g. a git repository.
|
||||
The root of the source of a flake in a subdirectory is still available in
|
||||
`.sourceInfo.outPath`.
|
||||
|
||||
* The `builtins.readDir` function has been optimized when encountering not-yet-known
|
||||
file types from POSIX's `readdir`. In such cases the type of each file is/was
|
||||
discovered by making multiple syscalls. This change makes these operations
|
||||
|
|
|
@ -16,7 +16,9 @@ let
|
|||
|
||||
subdir = if key == lockFile.root then rootSubdir else node.locked.dir or "";
|
||||
|
||||
flake = import (sourceInfo + (if subdir != "" then "/" else "") + subdir + "/flake.nix");
|
||||
outPath = sourceInfo + ((if subdir == "" then "" else "/") + subdir);
|
||||
|
||||
flake = import (outPath + "/flake.nix");
|
||||
|
||||
inputs = builtins.mapAttrs
|
||||
(inputName: inputSpec: allNodes.${resolveInput inputSpec})
|
||||
|
@ -43,7 +45,21 @@ let
|
|||
|
||||
outputs = flake.outputs (inputs // { self = result; });
|
||||
|
||||
result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; _type = "flake"; };
|
||||
result =
|
||||
outputs
|
||||
# We add the sourceInfo attribute for its metadata, as they are
|
||||
# relevant metadata for the flake. However, the outPath of the
|
||||
# sourceInfo does not necessarily match the outPath of the flake,
|
||||
# as the flake may be in a subdirectory of a source.
|
||||
# This is shadowed in the next //
|
||||
// sourceInfo
|
||||
// {
|
||||
# This shadows the sourceInfo.outPath
|
||||
inherit outPath;
|
||||
|
||||
inherit inputs; inherit outputs; inherit sourceInfo; _type = "flake";
|
||||
};
|
||||
|
||||
in
|
||||
if node.flake or true then
|
||||
assert builtins.isFunction flake.outputs;
|
||||
|
|
80
tests/flakes/inputs.sh
Normal file
80
tests/flakes/inputs.sh
Normal file
|
@ -0,0 +1,80 @@
|
|||
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 <<EOF
|
||||
{
|
||||
outputs = inputs: rec {
|
||||
packages.$system = rec {
|
||||
default =
|
||||
assert builtins.readFile ./message == "all good\n";
|
||||
assert builtins.readFile (inputs.self + "/message") == "all good\n";
|
||||
import ./simple.nix;
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
(
|
||||
nix build $baseDir?dir=b-low --no-link
|
||||
)
|
||||
}
|
||||
test_subdir_self_path
|
||||
|
||||
|
||||
test_git_subdir_self_path() {
|
||||
repoDir=$TEST_ROOT/repo-$RANDOM
|
||||
createGitRepo $repoDir
|
||||
flakeDir=$repoDir/b-low
|
||||
mkdir -p $flakeDir
|
||||
writeSimpleFlake $repoDir
|
||||
writeSimpleFlake $flakeDir
|
||||
|
||||
echo all good > $flakeDir/message
|
||||
cat > $flakeDir/flake.nix <<EOF
|
||||
{
|
||||
outputs = inputs: rec {
|
||||
packages.$system = rec {
|
||||
default =
|
||||
assert builtins.readFile ./message == "all good\n";
|
||||
assert builtins.readFile (inputs.self + "/message") == "all good\n";
|
||||
assert inputs.self.outPath == inputs.self.sourceInfo.outPath + "/b-low";
|
||||
import ./simple.nix;
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
(
|
||||
cd $flakeDir
|
||||
git add .
|
||||
git commit -m init
|
||||
# nix build
|
||||
)
|
||||
|
||||
clientDir=$TEST_ROOT/client-$RANDOM
|
||||
mkdir -p $clientDir
|
||||
cat > $clientDir/flake.nix <<EOF
|
||||
{
|
||||
inputs.inp = {
|
||||
type = "git";
|
||||
url = "file://$repoDir";
|
||||
dir = "b-low";
|
||||
};
|
||||
|
||||
outputs = inputs: rec {
|
||||
packages = inputs.inp.packages;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
nix build $clientDir --no-link
|
||||
|
||||
}
|
||||
test_git_subdir_self_path
|
|
@ -5,6 +5,7 @@ nix_tests = \
|
|||
flakes/mercurial.sh \
|
||||
flakes/circular.sh \
|
||||
flakes/init.sh \
|
||||
flakes/inputs.sh \
|
||||
flakes/follow-paths.sh \
|
||||
flakes/bundle.sh \
|
||||
flakes/check.sh \
|
||||
|
|
Loading…
Reference in a new issue