From 162fbe31ffe4c2b2d7648e5df2d5a0c9b4a44996 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 11 Feb 2022 18:11:08 +0100 Subject: [PATCH] Replace defaultBla.$system with bla.$system.default This also simplifies some InstallableFlake logic and fixes 'nix bundle' parsing its installable twice. Fixes #5532. --- src/libcmd/installables.cc | 5 ++++- src/nix/bundle.cc | 11 ++++++----- src/nix/develop.cc | 9 ++++++++- src/nix/flake.cc | 2 +- src/nix/run.cc | 5 ++++- tests/flake-bundler.sh | 26 +++++++++++++------------ tests/flake-local-settings.sh | 2 +- tests/flake-searching.sh | 6 ++++-- tests/flakes.sh | 36 ++++++++++++++++++----------------- 9 files changed, 61 insertions(+), 41 deletions(-) diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 644954977..c07e39628 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -158,7 +158,10 @@ SourceExprCommand::SourceExprCommand() Strings SourceExprCommand::getDefaultFlakeAttrPaths() { - return {"defaultPackage." + settings.thisSystem.get()}; + return { + "packages." + settings.thisSystem.get() + ".default", + "defaultPackage." + settings.thisSystem.get() + }; } Strings SourceExprCommand::getDefaultFlakeAttrPathPrefixes() diff --git a/src/nix/bundle.cc b/src/nix/bundle.cc index c13018328..6b891a6ee 100644 --- a/src/nix/bundle.cc +++ b/src/nix/bundle.cc @@ -49,9 +49,11 @@ struct CmdBundle : InstallableCommand Category category() override { return catSecondary; } + // FIXME: cut&paste from CmdRun. Strings getDefaultFlakeAttrPaths() override { Strings res{ + "apps." + settings.thisSystem.get() + ".default", "defaultApp." + settings.thisSystem.get() }; for (auto & s : SourceExprCommand::getDefaultFlakeAttrPaths()) @@ -61,10 +63,7 @@ struct CmdBundle : InstallableCommand Strings getDefaultFlakeAttrPathPrefixes() override { - Strings res{ - "apps." + settings.thisSystem.get() + "." - - }; + Strings res{"apps." + settings.thisSystem.get() + "."}; for (auto & s : SourceExprCommand::getDefaultFlakeAttrPathPrefixes()) res.push_back(s); return res; @@ -80,7 +79,9 @@ struct CmdBundle : InstallableCommand const flake::LockFlags lockFlags{ .writeLockFile = false }; InstallableFlake bundler{this, evalState, std::move(bundlerFlakeRef), bundlerName, - {"defaultBundler." + settings.thisSystem.get()}, + {"bundlers." + settings.thisSystem.get() + ".default", + "defaultBundler." + settings.thisSystem.get() + }, {"bundlers." + settings.thisSystem.get() + "."}, lockFlags }; diff --git a/src/nix/develop.cc b/src/nix/develop.cc index f88f5909c..92e31599a 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -325,8 +325,15 @@ struct Common : InstallableCommand, MixProfile 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 { auto res = SourceExprCommand::getDefaultFlakeAttrPathPrefixes(); diff --git a/src/nix/flake.cc b/src/nix/flake.cc index cd85bcea6..303edb9fe 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -651,7 +651,7 @@ struct CmdFlakeCheck : FlakeCommand }; static Strings defaultTemplateAttrPathsPrefixes{"templates."}; -static Strings defaultTemplateAttrPaths = {"defaultTemplate"}; +static Strings defaultTemplateAttrPaths = {"templates.default", "defaultTemplate"}; struct CmdFlakeInitCommon : virtual Args, EvalCommand { diff --git a/src/nix/run.cc b/src/nix/run.cc index bae64ed39..a67c23bcb 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -158,7 +158,10 @@ struct CmdRun : InstallableCommand 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()) res.push_back(s); return res; diff --git a/tests/flake-bundler.sh b/tests/flake-bundler.sh index 699920f60..9496b8f92 100644 --- a/tests/flake-bundler.sh +++ b/tests/flake-bundler.sh @@ -10,26 +10,28 @@ cd $TEST_HOME cat < flake.nix { outputs = {self}: { - bundlers.$system.simple = drv: + bundlers.$system = rec { + simple = drv: if drv?type && drv.type == "derivation" then drv - else self.defaultPackage.$system; - defaultBundler.$system = self.bundlers.$system.simple; - defaultPackage.$system = import ./simple.nix; - defaultApp.$system = { - type = "app"; - program = "\${import ./simple.nix}/hello"; - }; + else self.packages.$system.default; + default = simple; + }; + packages.$system.default = import ./simple.nix; + apps.$system.default = { + type = "app"; + program = "\${import ./simple.nix}/hello"; + }; }; } EOF nix build .# nix bundle --bundler .# .# -nix bundle --bundler .#defaultBundler.$system .#defaultPackage.$system -nix bundle --bundler .#bundlers.$system.simple .#defaultPackage.$system +nix bundle --bundler .#bundlers.$system.default .#packages.$system.default +nix bundle --bundler .#bundlers.$system.simple .#packages.$system.default -nix bundle --bundler .#defaultBundler.$system .#defaultApp.$system -nix bundle --bundler .#bundlers.$system.simple .#defaultApp.$system +nix bundle --bundler .#bundlers.$system.default .#apps.$system.default +nix bundle --bundler .#bundlers.$system.simple .#apps.$system.default clearStore diff --git a/tests/flake-local-settings.sh b/tests/flake-local-settings.sh index 7765fe379..e92c16f87 100644 --- a/tests/flake-local-settings.sh +++ b/tests/flake-local-settings.sh @@ -21,7 +21,7 @@ cat < flake.nix nixConfig.allow-dirty = false; # See #5621 outputs = a: { - defaultPackage.$system = import ./simple.nix; + packages.$system.default = import ./simple.nix; }; } EOF diff --git a/tests/flake-searching.sh b/tests/flake-searching.sh index bc55f2bdc..db241f6d2 100644 --- a/tests/flake-searching.sh +++ b/tests/flake-searching.sh @@ -15,8 +15,10 @@ cat < flake.nix { inputs.foo.url = "$PWD/foo"; outputs = a: { - defaultPackage.$system = import ./simple.nix; - packages.$system.test = import ./simple.nix; + packages.$system = rec { + test = import ./simple.nix; + default = test; + }; }; } EOF diff --git a/tests/flakes.sh b/tests/flakes.sh index db178967f..ea629ae70 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -41,8 +41,10 @@ cat > $flake1Dir/flake.nix < $templatesDir/flake.nix < $templatesDir/trivial/flake.nix < $flake3Dir/flake.nix <&1 && fail "nix flake check should have failed" || true) -echo "$checkRes" | grep -q "defaultPackage.system-1" -echo "$checkRes" | grep -q "defaultPackage.system-2" +echo "$checkRes" | grep -q "packages.system-1.default" +echo "$checkRes" | grep -q "packages.system-2.default" # Test 'follows' inputs. cat > $flake3Dir/flake.nix < $flake5Dir/flake.nix <