From 162fbe31ffe4c2b2d7648e5df2d5a0c9b4a44996 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 11 Feb 2022 18:11:08 +0100 Subject: [PATCH 1/4] 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 < Date: Tue, 22 Feb 2022 14:19:39 +0100 Subject: [PATCH 2/4] nix flake check: Warn about deprecated flake outputs --- src/nix/flake.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 303edb9fe..14a235501 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -501,6 +501,17 @@ struct CmdFlakeCheck : FlakeCommand state->forceValue(vOutput, pos); + std::string_view replacement = + name == "defaultPackage" ? "packages..default" : + name == "defaultApps" ? "apps..default" : + name == "defaultTemplate" ? "templates.default" : + name == "defaultBundler" ? "bundlers..default" : + name == "overlay" ? "overlays.default" : + name == "devShell" ? "devShells..default" : + ""; + if (replacement != "") + warn("flake output attribute '%s' is deprecated; use '%s' instead", name, replacement); + if (name == "checks") { state->forceAttrs(vOutput, pos); for (auto & attr : *vOutput.attrs) { From 38eea2c503a70e32dd6110937d49705976d5fc7a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 22 Feb 2022 14:23:39 +0100 Subject: [PATCH 3/4] Update release notes --- doc/manual/src/release-notes/rl-next.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/manual/src/release-notes/rl-next.md b/doc/manual/src/release-notes/rl-next.md index 80eed9397..7dd8387d8 100644 --- a/doc/manual/src/release-notes/rl-next.md +++ b/doc/manual/src/release-notes/rl-next.md @@ -1,5 +1,18 @@ # Release X.Y (202?-??-??) +* A number of "default" flake output attributes have been + renamed. These are: + + * `defaultPackage.` → `packages..default` + * `defaultApps.` → `apps..default` + * `defaultTemplate` → `templates.default` + * `defaultBundler.` → `bundlers..default` + * `overlay` → `overlays.default` + * `devShell.` → `devShells..default` + + The old flake output attributes still work, but `nix flake check` + will warn about them. + * `nix bundle` breaking API change now supports bundlers of the form `bundler..= derivation: another-derivation;`. This supports additional functionality to inspect evaluation information during bundling. A From 1a6548ca757f81594f5b54d8dada4c5ba65821de Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 22 Feb 2022 14:32:56 +0100 Subject: [PATCH 4/4] Update docs --- src/nix/bundle.md | 14 ++++++++------ src/nix/develop.md | 4 ++-- src/nix/flake-init.md | 8 ++++---- src/nix/flake-show.md | 11 +++++++---- src/nix/flake.md | 2 +- src/nix/nix.md | 6 ++---- src/nix/profile-list.md | 2 +- src/nix/profile.md | 2 +- src/nix/run.md | 6 +++--- 9 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/nix/bundle.md b/src/nix/bundle.md index a5186a996..2bb70711f 100644 --- a/src/nix/bundle.md +++ b/src/nix/bundle.md @@ -42,24 +42,26 @@ homepage](https://github.com/NixOS/bundlers) for more details. If no flake output attribute is given, `nix bundle` tries the following flake output attributes: -* `defaultBundler.` +* `bundlers..default` If an attribute *name* is given, `nix run` tries the following flake output attributes: -* `bundler..` +* `bundlers..` # Bundlers A bundler is specified by a flake output attribute named -`bundlers..` or `defaultBundler.`. It looks like this: +`bundlers..`. It looks like this: ```nix -bundlers.x86_64-linux.identity = drv: drv; +bundlers.x86_64-linux = rec { + identity = drv: drv; -bundlers.x86_64-linux.blender_2_79 = drv: self.packages.x86_64-linux.blender_2_79; + blender_2_79 = drv: self.packages.x86_64-linux.blender_2_79; -defaultBundler.x86_64-linux = drv: drv; + default = identity; +}; ``` A bundler must be a function that accepts an arbitrary value (typically a diff --git a/src/nix/develop.md b/src/nix/develop.md index 3e7e339d5..8bcff66c9 100644 --- a/src/nix/develop.md +++ b/src/nix/develop.md @@ -88,9 +88,9 @@ the flake's `nixConfig` attribute. If no flake output attribute is given, `nix develop` tries the following flake output attributes: -* `devShell.` +* `devShells..default` -* `defaultPackage.` +* `packages..default` If a flake output *name* is given, `nix develop` tries the following flake output attributes: diff --git a/src/nix/flake-init.md b/src/nix/flake-init.md index c13b22248..fc1f4f805 100644 --- a/src/nix/flake-init.md +++ b/src/nix/flake-init.md @@ -24,13 +24,13 @@ R""( This command creates a flake in the current directory by copying the files of a template. It will not overwrite existing files. The default -template is `templates#defaultTemplate`, but this can be overridden +template is `templates#templates.default`, but this can be overridden using `-t`. # Template definitions -A flake can declare templates through its `templates` and -`defaultTemplate` output attributes. A template has two attributes: +A flake can declare templates through its `templates` output +attribute. A template has two attributes: * `description`: A one-line description of the template, in CommonMark syntax. @@ -61,7 +61,7 @@ outputs = { self }: { ''; }; - templates.defaultTemplate = self.templates.rust; + templates.default = self.templates.rust; } ``` diff --git a/src/nix/flake-show.md b/src/nix/flake-show.md index e484cf47e..f3b74285d 100644 --- a/src/nix/flake-show.md +++ b/src/nix/flake-show.md @@ -13,10 +13,13 @@ R""( │ │ └───build: derivation 'patchelf-0.12.20201207.f34751b' │ └───x86_64-linux │ └───build: derivation 'patchelf-0.12.20201207.f34751b' - ├───defaultPackage - │ ├───aarch64-linux: package 'patchelf-0.12.20201207.f34751b' - │ ├───i686-linux: package 'patchelf-0.12.20201207.f34751b' - │ └───x86_64-linux: package 'patchelf-0.12.20201207.f34751b' + ├───packages + │ ├───aarch64-linux + │ │ └───default: package 'patchelf-0.12.20201207.f34751b' + │ ├───i686-linux + │ │ └───default: package 'patchelf-0.12.20201207.f34751b' + │ └───x86_64-linux + │ └───default: package 'patchelf-0.12.20201207.f34751b' ├───hydraJobs │ ├───build │ │ ├───aarch64-linux: derivation 'patchelf-0.12.20201207.f34751b' diff --git a/src/nix/flake.md b/src/nix/flake.md index accddd436..48c12d30f 100644 --- a/src/nix/flake.md +++ b/src/nix/flake.md @@ -236,7 +236,7 @@ derivation): outputs = { self, nixpkgs }: { - defaultPackage.x86_64-linux = + packages.x86_64-linux.default = # Notice the reference to nixpkgs here. with import nixpkgs { system = "x86_64-linux"; }; stdenv.mkDerivation { diff --git a/src/nix/nix.md b/src/nix/nix.md index 1dc59362d..0dacadee6 100644 --- a/src/nix/nix.md +++ b/src/nix/nix.md @@ -97,11 +97,9 @@ the Nix store. Here are the recognised types of installables: For example, if `/foo/bar/flake.nix` exists, then `/foo/bar/baz/` will resolve to `path:/foo/bar` - - If *attrpath* is omitted, Nix tries some default values; for most - subcommands, the default is `defaultPackage.`*system* - (e.g. `defaultPackage.x86_64-linux`), but some subcommands have + subcommands, the default is `packages.`*system*`.default` + (e.g. `packages.x86_64-linux.default`), but some subcommands have other defaults. If *attrpath* *is* specified, *attrpath* is interpreted as relative to one or more prefixes; for most subcommands, these are `packages.`*system*, diff --git a/src/nix/profile-list.md b/src/nix/profile-list.md index 5c29c0b02..bdab9a208 100644 --- a/src/nix/profile-list.md +++ b/src/nix/profile-list.md @@ -8,7 +8,7 @@ R""( # nix profile list 0 flake:nixpkgs#legacyPackages.x86_64-linux.spotify github:NixOS/nixpkgs/c23db78bbd474c4d0c5c3c551877523b4a50db06#legacyPackages.x86_64-linux.spotify /nix/store/akpdsid105phbbvknjsdh7hl4v3fhjkr-spotify-1.1.46.916.g416cacf1 1 flake:nixpkgs#legacyPackages.x86_64-linux.zoom-us github:NixOS/nixpkgs/c23db78bbd474c4d0c5c3c551877523b4a50db06#legacyPackages.x86_64-linux.zoom-us /nix/store/89pmjmbih5qpi7accgacd17ybpgp4xfm-zoom-us-5.4.53350.1027 - 2 flake:blender-bin#defaultPackage.x86_64-linux github:edolstra/nix-warez/d09d7eea893dcb162e89bc67f6dc1ced14abfc27?dir=blender#defaultPackage.x86_64-linux /nix/store/zfgralhqjnam662kqsgq6isjw8lhrflz-blender-bin-2.91.0 + 2 flake:blender-bin#packages.x86_64-linux.default github:edolstra/nix-warez/d09d7eea893dcb162e89bc67f6dc1ced14abfc27?dir=blender#packages.x86_64-linux.default /nix/store/zfgralhqjnam662kqsgq6isjw8lhrflz-blender-bin-2.91.0 ``` # Description diff --git a/src/nix/profile.md b/src/nix/profile.md index d3ddcd3d1..0a4ff2fa9 100644 --- a/src/nix/profile.md +++ b/src/nix/profile.md @@ -96,7 +96,7 @@ has the following fields: user specified, but the one resulting from applying the default attribute paths and prefixes; for instance, `hello` might resolve to `packages.x86_64-linux.hello` and the empty string to - `defaultPackage.x86_64-linux`. + `packages.x86_64-linux.default`. * `storePath`: The paths in the Nix store containing the package. diff --git a/src/nix/run.md b/src/nix/run.md index cd3b978c0..a0f362076 100644 --- a/src/nix/run.md +++ b/src/nix/run.md @@ -58,9 +58,9 @@ For instance, if `name` is set to `hello-1.10`, `nix run` will run If no flake output attribute is given, `nix run` tries the following flake output attributes: -* `defaultApp.` +* `apps..default` -* `defaultPackage.` +* `packages..default` If an attribute *name* is given, `nix run` tries the following flake output attributes: @@ -74,7 +74,7 @@ output attributes: # Apps An app is specified by a flake output attribute named -`apps..` or `defaultApp.`. It looks like this: +`apps..`. It looks like this: ```nix apps.x86_64-linux.blender_2_79 = {