mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-13 01:36:15 +02:00
Replace defaultBla.$system with bla.$system.default
This also simplifies some InstallableFlake logic and fixes 'nix bundle' parsing its installable twice. Fixes #5532.
This commit is contained in:
parent
caf5172945
commit
162fbe31ff
9 changed files with 61 additions and 41 deletions
|
@ -158,7 +158,10 @@ SourceExprCommand::SourceExprCommand()
|
||||||
|
|
||||||
Strings SourceExprCommand::getDefaultFlakeAttrPaths()
|
Strings SourceExprCommand::getDefaultFlakeAttrPaths()
|
||||||
{
|
{
|
||||||
return {"defaultPackage." + settings.thisSystem.get()};
|
return {
|
||||||
|
"packages." + settings.thisSystem.get() + ".default",
|
||||||
|
"defaultPackage." + settings.thisSystem.get()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Strings SourceExprCommand::getDefaultFlakeAttrPathPrefixes()
|
Strings SourceExprCommand::getDefaultFlakeAttrPathPrefixes()
|
||||||
|
|
|
@ -49,9 +49,11 @@ struct CmdBundle : InstallableCommand
|
||||||
|
|
||||||
Category category() override { return catSecondary; }
|
Category category() override { return catSecondary; }
|
||||||
|
|
||||||
|
// FIXME: cut&paste from CmdRun.
|
||||||
Strings getDefaultFlakeAttrPaths() override
|
Strings getDefaultFlakeAttrPaths() override
|
||||||
{
|
{
|
||||||
Strings res{
|
Strings res{
|
||||||
|
"apps." + settings.thisSystem.get() + ".default",
|
||||||
"defaultApp." + settings.thisSystem.get()
|
"defaultApp." + settings.thisSystem.get()
|
||||||
};
|
};
|
||||||
for (auto & s : SourceExprCommand::getDefaultFlakeAttrPaths())
|
for (auto & s : SourceExprCommand::getDefaultFlakeAttrPaths())
|
||||||
|
@ -61,10 +63,7 @@ struct CmdBundle : InstallableCommand
|
||||||
|
|
||||||
Strings getDefaultFlakeAttrPathPrefixes() override
|
Strings getDefaultFlakeAttrPathPrefixes() override
|
||||||
{
|
{
|
||||||
Strings res{
|
Strings res{"apps." + settings.thisSystem.get() + "."};
|
||||||
"apps." + settings.thisSystem.get() + "."
|
|
||||||
|
|
||||||
};
|
|
||||||
for (auto & s : SourceExprCommand::getDefaultFlakeAttrPathPrefixes())
|
for (auto & s : SourceExprCommand::getDefaultFlakeAttrPathPrefixes())
|
||||||
res.push_back(s);
|
res.push_back(s);
|
||||||
return res;
|
return res;
|
||||||
|
@ -80,7 +79,9 @@ struct CmdBundle : InstallableCommand
|
||||||
const flake::LockFlags lockFlags{ .writeLockFile = false };
|
const flake::LockFlags lockFlags{ .writeLockFile = false };
|
||||||
InstallableFlake bundler{this,
|
InstallableFlake bundler{this,
|
||||||
evalState, std::move(bundlerFlakeRef), bundlerName,
|
evalState, std::move(bundlerFlakeRef), bundlerName,
|
||||||
{"defaultBundler." + settings.thisSystem.get()},
|
{"bundlers." + settings.thisSystem.get() + ".default",
|
||||||
|
"defaultBundler." + settings.thisSystem.get()
|
||||||
|
},
|
||||||
{"bundlers." + settings.thisSystem.get() + "."},
|
{"bundlers." + settings.thisSystem.get() + "."},
|
||||||
lockFlags
|
lockFlags
|
||||||
};
|
};
|
||||||
|
|
|
@ -325,8 +325,15 @@ struct Common : InstallableCommand, MixProfile
|
||||||
|
|
||||||
Strings getDefaultFlakeAttrPaths() override
|
Strings getDefaultFlakeAttrPaths() override
|
||||||
{
|
{
|
||||||
return {"devShell." + settings.thisSystem.get(), "defaultPackage." + settings.thisSystem.get()};
|
Strings paths{
|
||||||
|
"devShells." + settings.thisSystem.get() + ".default",
|
||||||
|
"devShell." + settings.thisSystem.get(),
|
||||||
|
};
|
||||||
|
for (auto & p : SourceExprCommand::getDefaultFlakeAttrPaths())
|
||||||
|
paths.push_back(p);
|
||||||
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
Strings getDefaultFlakeAttrPathPrefixes() override
|
Strings getDefaultFlakeAttrPathPrefixes() override
|
||||||
{
|
{
|
||||||
auto res = SourceExprCommand::getDefaultFlakeAttrPathPrefixes();
|
auto res = SourceExprCommand::getDefaultFlakeAttrPathPrefixes();
|
||||||
|
|
|
@ -651,7 +651,7 @@ struct CmdFlakeCheck : FlakeCommand
|
||||||
};
|
};
|
||||||
|
|
||||||
static Strings defaultTemplateAttrPathsPrefixes{"templates."};
|
static Strings defaultTemplateAttrPathsPrefixes{"templates."};
|
||||||
static Strings defaultTemplateAttrPaths = {"defaultTemplate"};
|
static Strings defaultTemplateAttrPaths = {"templates.default", "defaultTemplate"};
|
||||||
|
|
||||||
struct CmdFlakeInitCommon : virtual Args, EvalCommand
|
struct CmdFlakeInitCommon : virtual Args, EvalCommand
|
||||||
{
|
{
|
||||||
|
|
|
@ -158,7 +158,10 @@ struct CmdRun : InstallableCommand
|
||||||
|
|
||||||
Strings getDefaultFlakeAttrPaths() override
|
Strings getDefaultFlakeAttrPaths() override
|
||||||
{
|
{
|
||||||
Strings res{"defaultApp." + settings.thisSystem.get()};
|
Strings res{
|
||||||
|
"apps." + settings.thisSystem.get() + ".default",
|
||||||
|
"defaultApp." + settings.thisSystem.get(),
|
||||||
|
};
|
||||||
for (auto & s : SourceExprCommand::getDefaultFlakeAttrPaths())
|
for (auto & s : SourceExprCommand::getDefaultFlakeAttrPaths())
|
||||||
res.push_back(s);
|
res.push_back(s);
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -10,26 +10,28 @@ cd $TEST_HOME
|
||||||
cat <<EOF > flake.nix
|
cat <<EOF > flake.nix
|
||||||
{
|
{
|
||||||
outputs = {self}: {
|
outputs = {self}: {
|
||||||
bundlers.$system.simple = drv:
|
bundlers.$system = rec {
|
||||||
|
simple = drv:
|
||||||
if drv?type && drv.type == "derivation"
|
if drv?type && drv.type == "derivation"
|
||||||
then drv
|
then drv
|
||||||
else self.defaultPackage.$system;
|
else self.packages.$system.default;
|
||||||
defaultBundler.$system = self.bundlers.$system.simple;
|
default = simple;
|
||||||
defaultPackage.$system = import ./simple.nix;
|
};
|
||||||
defaultApp.$system = {
|
packages.$system.default = import ./simple.nix;
|
||||||
type = "app";
|
apps.$system.default = {
|
||||||
program = "\${import ./simple.nix}/hello";
|
type = "app";
|
||||||
};
|
program = "\${import ./simple.nix}/hello";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
nix build .#
|
nix build .#
|
||||||
nix bundle --bundler .# .#
|
nix bundle --bundler .# .#
|
||||||
nix bundle --bundler .#defaultBundler.$system .#defaultPackage.$system
|
nix bundle --bundler .#bundlers.$system.default .#packages.$system.default
|
||||||
nix bundle --bundler .#bundlers.$system.simple .#defaultPackage.$system
|
nix bundle --bundler .#bundlers.$system.simple .#packages.$system.default
|
||||||
|
|
||||||
nix bundle --bundler .#defaultBundler.$system .#defaultApp.$system
|
nix bundle --bundler .#bundlers.$system.default .#apps.$system.default
|
||||||
nix bundle --bundler .#bundlers.$system.simple .#defaultApp.$system
|
nix bundle --bundler .#bundlers.$system.simple .#apps.$system.default
|
||||||
|
|
||||||
clearStore
|
clearStore
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ cat <<EOF > flake.nix
|
||||||
nixConfig.allow-dirty = false; # See #5621
|
nixConfig.allow-dirty = false; # See #5621
|
||||||
|
|
||||||
outputs = a: {
|
outputs = a: {
|
||||||
defaultPackage.$system = import ./simple.nix;
|
packages.$system.default = import ./simple.nix;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
|
@ -15,8 +15,10 @@ cat <<EOF > flake.nix
|
||||||
{
|
{
|
||||||
inputs.foo.url = "$PWD/foo";
|
inputs.foo.url = "$PWD/foo";
|
||||||
outputs = a: {
|
outputs = a: {
|
||||||
defaultPackage.$system = import ./simple.nix;
|
packages.$system = rec {
|
||||||
packages.$system.test = import ./simple.nix;
|
test = import ./simple.nix;
|
||||||
|
default = test;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
|
@ -41,8 +41,10 @@ cat > $flake1Dir/flake.nix <<EOF
|
||||||
description = "Bla bla";
|
description = "Bla bla";
|
||||||
|
|
||||||
outputs = inputs: rec {
|
outputs = inputs: rec {
|
||||||
packages.$system.foo = import ./simple.nix;
|
packages.$system = rec {
|
||||||
defaultPackage.$system = packages.$system.foo;
|
foo = import ./simple.nix;
|
||||||
|
default = foo;
|
||||||
|
};
|
||||||
|
|
||||||
# To test "nix flake init".
|
# To test "nix flake init".
|
||||||
legacyPackages.x86_64-linux.hello = import ./simple.nix;
|
legacyPackages.x86_64-linux.hello = import ./simple.nix;
|
||||||
|
@ -128,7 +130,7 @@ hash2=$(nix flake metadata flake1 --json --refresh | jq -r .revision)
|
||||||
nix build -o $TEST_ROOT/result flake1#foo
|
nix build -o $TEST_ROOT/result flake1#foo
|
||||||
[[ -e $TEST_ROOT/result/hello ]]
|
[[ -e $TEST_ROOT/result/hello ]]
|
||||||
|
|
||||||
# Test defaultPackage.
|
# Test packages.default.
|
||||||
nix build -o $TEST_ROOT/result flake1
|
nix build -o $TEST_ROOT/result flake1
|
||||||
[[ -e $TEST_ROOT/result/hello ]]
|
[[ -e $TEST_ROOT/result/hello ]]
|
||||||
|
|
||||||
|
@ -140,11 +142,11 @@ nix build -o $flake1Dir/result git+file://$flake1Dir
|
||||||
nix path-info $flake1Dir/result
|
nix path-info $flake1Dir/result
|
||||||
|
|
||||||
# 'getFlake' on a mutable flakeref should fail in pure mode, but succeed in impure mode.
|
# 'getFlake' on a mutable flakeref should fail in pure mode, but succeed in impure mode.
|
||||||
(! nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").defaultPackage.$system")
|
(! nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").packages.$system.default")
|
||||||
nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").defaultPackage.$system" --impure
|
nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").packages.$system.default" --impure
|
||||||
|
|
||||||
# 'getFlake' on an immutable flakeref should succeed even in pure mode.
|
# 'getFlake' on an immutable flakeref should succeed even in pure mode.
|
||||||
nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"git+file://$flake1Dir?rev=$hash2\").defaultPackage.$system"
|
nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"git+file://$flake1Dir?rev=$hash2\").packages.$system.default"
|
||||||
|
|
||||||
# Building a flake with an unlocked dependency should fail in pure mode.
|
# Building a flake with an unlocked dependency should fail in pure mode.
|
||||||
(! nix build -o $TEST_ROOT/result flake2#bar --no-registries)
|
(! nix build -o $TEST_ROOT/result flake2#bar --no-registries)
|
||||||
|
@ -370,13 +372,13 @@ cat > $templatesDir/flake.nix <<EOF
|
||||||
description = "Some templates";
|
description = "Some templates";
|
||||||
|
|
||||||
outputs = { self }: {
|
outputs = { self }: {
|
||||||
templates = {
|
templates = rec {
|
||||||
trivial = {
|
trivial = {
|
||||||
path = ./trivial;
|
path = ./trivial;
|
||||||
description = "A trivial flake";
|
description = "A trivial flake";
|
||||||
};
|
};
|
||||||
|
default = trivial;
|
||||||
};
|
};
|
||||||
defaultTemplate = self.templates.trivial;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
@ -388,8 +390,10 @@ cat > $templatesDir/trivial/flake.nix <<EOF
|
||||||
description = "A flake for building Hello World";
|
description = "A flake for building Hello World";
|
||||||
|
|
||||||
outputs = { self, nixpkgs }: {
|
outputs = { self, nixpkgs }: {
|
||||||
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
|
packages.x86_64-linux = rec {
|
||||||
defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello;
|
hello = nixpkgs.legacyPackages.x86_64-linux.hello;
|
||||||
|
default = hello;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
@ -496,17 +500,15 @@ EOF
|
||||||
cat > $flake3Dir/flake.nix <<EOF
|
cat > $flake3Dir/flake.nix <<EOF
|
||||||
{
|
{
|
||||||
outputs = { flake1, self }: {
|
outputs = { flake1, self }: {
|
||||||
defaultPackage = {
|
packages.system-1.default = "foo";
|
||||||
system-1 = "foo";
|
packages.system-2.default = "bar";
|
||||||
system-2 = "bar";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
checkRes=$(nix flake check --keep-going $flake3Dir 2>&1 && fail "nix flake check should have failed" || true)
|
checkRes=$(nix flake check --keep-going $flake3Dir 2>&1 && fail "nix flake check should have failed" || true)
|
||||||
echo "$checkRes" | grep -q "defaultPackage.system-1"
|
echo "$checkRes" | grep -q "packages.system-1.default"
|
||||||
echo "$checkRes" | grep -q "defaultPackage.system-2"
|
echo "$checkRes" | grep -q "packages.system-2.default"
|
||||||
|
|
||||||
# Test 'follows' inputs.
|
# Test 'follows' inputs.
|
||||||
cat > $flake3Dir/flake.nix <<EOF
|
cat > $flake3Dir/flake.nix <<EOF
|
||||||
|
@ -591,7 +593,7 @@ mkdir $flake5Dir
|
||||||
cat > $flake5Dir/flake.nix <<EOF
|
cat > $flake5Dir/flake.nix <<EOF
|
||||||
{
|
{
|
||||||
outputs = { self, flake1 }: {
|
outputs = { self, flake1 }: {
|
||||||
defaultPackage.$system = flake1.defaultPackage.$system;
|
packages.$system.default = flake1.packages.$system.default;
|
||||||
expr = assert builtins.pathExists ./flake.lock; 123;
|
expr = assert builtins.pathExists ./flake.lock; 123;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue