mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
flakes: Ensure that self.outPath == ./.
Users expect `self` to refer to the directory where the `flake.nix` file resides.
This commit is contained in:
parent
532c70f531
commit
904a107d16
3 changed files with 86 additions and 2 deletions
|
@ -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})
|
||||
|
|
79
tests/flakes/inputs.sh
Normal file
79
tests/flakes/inputs.sh
Normal file
|
@ -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 <<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";
|
||||
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
|
|
@ -4,6 +4,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