Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename defaultX flake outputs to X.default #5532

Closed
edolstra opened this issue Nov 10, 2021 · 11 comments · Fixed by #6089
Closed

Rename defaultX flake outputs to X.default #5532

edolstra opened this issue Nov 10, 2021 · 11 comments · Fixed by #6089
Assignees
Labels
flakes good first issue Quick win for first-time contributors UX The way in which users interact with Nix. Higher level than UI.
Milestone

Comments

@edolstra
Copy link
Member

We have a couple of flake outputs that have a corresponding "default" flake output, e.g.

  • packages and defaultPackage
  • devShells and devShell
  • apps and defaultApp
  • overlays and overlay
  • nixosModules and nixosModule
  • templates and defaultTemplate
  • bundlers and defaultBundler

There are also some flake outputs that lack a default, but could probably use one, like nixosConfigurations.

As can be seen above, the naming is inconsistent. It also requires a lot of special handling in commands like nix flake show and nix flake check. So I propose getting rid of all the singular flake outputs and using an attribute named default as the default. E.g.

  • defaultPackage.<system> => packages.<system>.default
  • devShell.<system> => devShells.<system>.default
  • overlay => overlays.default

Migration: we can deprecate the old singular flake outputs in 2.5 and remove support for them some time later.

@edolstra edolstra added improvement UX The way in which users interact with Nix. Higher level than UI. labels Nov 10, 2021
@edolstra edolstra self-assigned this Nov 10, 2021
@edolstra edolstra added this to the nix-2.5 milestone Nov 10, 2021
@thufschmitt
Copy link
Member

One issue with this is that we’ll then have a default in the same namespace as the rest, which isn’t very clean.
Like if I want something that iterates over all the packages exported by a flake (or my flake has hydraJobs = self.packages), then there will be a default package that’s probably just a duplicate of another one and doesn’t really make sense.

Also, if I want to reuse the outputs of flake as an overlay (do something like import nixpkgs { overlays = [ (_: prev: nix.packages.${prev.system}) ]; }, then I’ll also add a default package.

(not that these are really blockers of course, but it’s mildly annoying)

@michaelpj
Copy link

Having suffered through lots of annoyance due to working with some nix code that mixes derivations with different meanings together: please keep collections homogeneous! Put the special attributes somewhere else.

@hazelweakly
Copy link

This brings up a slightly unrelated point of annoyance for me. There's a solid amount of flake attributes that are system namespaced as well as ones that are not system namespaced. The separation prevents things like cleanly writing a forAllSystems {} flake generator (you end up with forAllSystems {} // { the rest of the flake} or, worse, forAllSystems {} // ( if arm mac then {}) // (if x86_64 linux then {}) // ...

To reiterate on @michaelpj's point, one of the big appeals behind flakes (for me) was that:

  • purity meant you could actually cache stuff
  • defined outputs and structure meant that you didn't need to stick magic inside attributes that needed to be evaluated. The last bit makes things really slow occasionally, and is errorprone as anyone who has ever touched nixpkgs's python stuff can attest to.

If attributes are going to be modified for consistency, I think a standardized naming scheme and attribute shape makes more sense; but I think we should strongly avoid any situation in which <thing>.default can be ambiguous.

@thufschmitt
Copy link
Member

Random suggestion: What about giving each flake a canonical name (with a name field for example), and using this name as the default attr name?
For example nix build would first try packages.${builtins.currenSystem}.${name}.

That way there’s no need for a distinguished defaultXXX field, and we also don’t have the duplicate default field since it will generally make sense to have the default package named like the flake

@edolstra edolstra modified the milestones: nix-2.5, nix-2.6 Dec 10, 2021
@tomberek
Copy link
Contributor

Beginning to implement: tomberek@28c2db5

Random notes
Notes about using "name":

nixosConfigurations vs nixosConfigurations.HOSTNAME - special, need "hostname"

  • needs more thought.... HOSTNAME -> name -> "default" -> error

what if "name" is not defined? use "default" with warning to please add a name

mismatch between flakeref's name and flake name attribute:
nix flake show
github:org/some-name and { name = "something";}
path - doesn't have a name
. - doesn't have a name

todo: add to nix flake show

  • add to self.name and to lockfile
  • add to self.description and to lockfile

Adding name will cause eval breakages.

  • add the capability, don't use it for now... slowly adopt as people go to 2.5/6/7/8.
  • hard error in 2.4

@garbas garbas moved this to In Progress in Nix UX Dec 16, 2021
@garbas garbas added this to Nix UX Dec 16, 2021
@felix-andreas
Copy link
Member

Another suggestion: Introduce a default attribute which contains the different default outputs:

default.package.<system>
default.devShell.<system>
default.app.<system>
...
# or
default.<system>.package
default.<system>.devShell
default.<system>.app
...

This would lead to some consistency for default outputs and wouldn't "pollute" the namespace of the outputs.

@tomberek
Copy link
Contributor

tomberek commented Jan 6, 2022

Another thought: if you only have a single item in the plural form (eg: packages) then it automatically becomes the default.

@garbas garbas moved this from In Progress to Todo in Nix UX Jan 6, 2022
@edolstra edolstra modified the milestones: nix-2.6, nix-2.7 Jan 21, 2022
@blaggacao
Copy link
Contributor

blaggacao commented Jan 31, 2022

@andreasfelix for the reasons contained in divnix/std#5 (comment) I think that's not a good idea (hence 👎 ). If not for that I would have liked your suggestion.

TLDR; the special casing when consumed by downstream users "pollutes" downstream a bit through structurally different fully qualified identifiers, just looks weird.

I'd favor a more "hidden"-feeling ._default (or even .__default) over just plain .default.

But I also like @tomberek last suggestion as a fall-back.

@tomberek
Copy link
Contributor

tomberek commented Feb 3, 2022

Plan:

  • error when nix build has no default option when no explicit attribute is used on CLI, which a note specifying that the attribute name "default" is used.
  • Place deprecation warnings into all singulars.
devShells.<system> = rec {  
  default = thing;
  thing = mkShell { name = "asdfa"; paths = [ asdf asdf asdf];};
  another = mkShell { name = "asdfa"; paths = [ asdf asdf asdf];};
  stuff = mkShell { name = "asdfa"; paths = [ asdf asdf asdf];};
}
nixosConfigurations = {
  default = self.nixosConfigurations.amachine;
  amachine = { ...} : {};
};

Solves the singular/plural issue.

@tomberek tomberek moved this from Todo to Friday Hacking Extravaganza in Nix UX Feb 3, 2022
bandithedoge pushed a commit to nvim-neorg/nixpkgs-neorg-overlay that referenced this issue Nov 20, 2022
ivanbrennan added a commit to ivanbrennan/hello-flake that referenced this issue Jan 1, 2023
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/why-is-there-a-default-overlay-in-flakes/24422/1

@MForster MForster mentioned this issue Jan 11, 2023
3 tasks
pasqui23 pushed a commit to pasqui23/nixops that referenced this issue Jan 31, 2023
Newer versions of Nix do not work with the old `flake.nix`
because of the change described in:

NixOS/nix#5532

This change fixes that while still preserving compatibility with
older versions of Nix.
pasqui23 pushed a commit to pasqui23/nixops that referenced this issue Jan 31, 2023
Newer versions of Nix do not work with the old `flake.nix`
because of the change described in:

NixOS/nix#5532

This change fixes that while still preserving compatibility with
older versions of Nix.
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/modify-flake-now-that-defaultpackage-is-deprecated/25571/1

WilliamHsieh added a commit to WilliamHsieh/dotfiles that referenced this issue Mar 11, 2023
seb314 added a commit to seb314/gpt-cli that referenced this issue Mar 19, 2023
It seems somewhat unclear what the correct schema is for nix &
nix-direnv, and id appears to differ between versions (?).
The current version is based more or less on
nix flake new -t github:nix-community/nix-direnv <desired output path> # from https://github.com/nix-community/nix-direnv
https://serokell.io/blog/practical-nix-flakes
NixOS/nix#5532
and
https://nixos.wiki/wiki/Flakes

With an extra output path alias added because my local nix-direnv
complains otherwise.
WilliamHsieh added a commit to WilliamHsieh/dotfiles that referenced this issue Apr 16, 2023
peterldowns added a commit to peterldowns/nix-search-cli that referenced this issue Sep 12, 2023
As reported in #10
the cargo-culted warning about flake compatibility is showing up for
users who are not on pre-2.7 nix. Additionally, running `nix flake
check` shows warnings about the existence of the `defaultApp`,
`defaultPackage`, and `devShell` keys that are only defined for
compatibility purposes.

At this point, feels safe enough to remove the warning. If someone
complains because they are on a very old version of flakes I can easily
revisit this decision.

For background information on the flake schema change as of 2.7, see:

- https://nixos.org/manual/nix/stable/release-notes/rl-2.7.html#release-27-2022-03-07
- NixOS/nix#5532 (comment)
andreasabel pushed a commit to agda/agda that referenced this issue Jan 2, 2024
This PR makes the following changes:

* Add a `.envrc` file to auto-load the `flake.nix` when I enter the repository
  * This helps with e.g. Haskell VSCode integration
  * Only affects users of `direnv`
  * An alternative would be to add `.envrc` to the `.gitignore`, and let each developer write their own `.envrc`

* Refactor the `flake.nix` file
  * Replace the [deprecated attributes](NixOS/nix#5532) `defaultPackage` and `devShell`
  * Explicitly track the `nixpkgs` dependency
    * This seems to be the convention for most flakes I have viewed
  * Add comments
  * Stop using a nixpkg overlay
    * Overlays are verbose & not newbie-friendly
    * [Overlays are overkill here, and do not scale well](https://zimbatm.com/notes/1000-instances-of-nixpkgs)
  * Misc. refactoring to reduce length

I have tested the following features of `flake.nix`:

* `nix develop` starts a sub-shell with `cabal`,etc. where I can build agda
* `nix build` produces binaries in `result/bin/`

Commits:

* Add .envrc

* flake.nix: replace deprecated `.devShell` etc.

* flake.nix: track nixpkgs explicitly

As opposed to implicitly via the flake registry:
https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake#types

* flake.nix: de-overlay & add comments

* .gitignore nix build outputs

* flake.nix: bump nixpkgs pin

* flake.nix: add back overlay

Using flake-parts to keep the overlay non-obtrusive

* flake.nix: mark overlay as experimental
thkoch2001 added a commit to thkoch2001/microvm.nix that referenced this issue Jan 25, 2024
The switch from defaultPackage to packages.${system}.default happened in NixOS/nix#5532.

Additionally I removed one layer:
self.nixosConfigurations.my-microvm.config.microvm.declaredRunner;
self.nixosConfiguration.config.microvm.declaredRunner;

The latter should be easier to understand for new users.
VitalyAnkh pushed a commit to VitalyAnkh/agda that referenced this issue Mar 5, 2024
This PR makes the following changes:

* Add a `.envrc` file to auto-load the `flake.nix` when I enter the repository
  * This helps with e.g. Haskell VSCode integration
  * Only affects users of `direnv`
  * An alternative would be to add `.envrc` to the `.gitignore`, and let each developer write their own `.envrc`

* Refactor the `flake.nix` file
  * Replace the [deprecated attributes](NixOS/nix#5532) `defaultPackage` and `devShell`
  * Explicitly track the `nixpkgs` dependency
    * This seems to be the convention for most flakes I have viewed
  * Add comments
  * Stop using a nixpkg overlay
    * Overlays are verbose & not newbie-friendly
    * [Overlays are overkill here, and do not scale well](https://zimbatm.com/notes/1000-instances-of-nixpkgs)
  * Misc. refactoring to reduce length

I have tested the following features of `flake.nix`:

* `nix develop` starts a sub-shell with `cabal`,etc. where I can build agda
* `nix build` produces binaries in `result/bin/`

Commits:

* Add .envrc

* flake.nix: replace deprecated `.devShell` etc.

* flake.nix: track nixpkgs explicitly

As opposed to implicitly via the flake registry:
https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake#types

* flake.nix: de-overlay & add comments

* .gitignore nix build outputs

* flake.nix: bump nixpkgs pin

* flake.nix: add back overlay

Using flake-parts to keep the overlay non-obtrusive

* flake.nix: mark overlay as experimental
brndnmtthws added a commit to brndnmtthws/conky that referenced this issue Mar 8, 2024
`nix flake check` no longer returns warnings.
brndnmtthws added a commit to brndnmtthws/conky that referenced this issue Mar 8, 2024
`nix flake check` no longer returns warnings.
thkoch2001 added a commit to thkoch2001/microvm.nix that referenced this issue Mar 18, 2024
The switch from defaultPackage to packages.${system}.default happened in NixOS/nix#5532.
thkoch2001 added a commit to thkoch2001/microvm.nix that referenced this issue Mar 18, 2024
The switch from defaultPackage to packages.${system}.default happened in NixOS/nix#5532.
astro pushed a commit to astro/microvm.nix that referenced this issue Mar 18, 2024
The switch from defaultPackage to packages.${system}.default happened in NixOS/nix#5532.
freebsd-git pushed a commit to freebsd/freebsd-ports that referenced this issue Apr 19, 2024
Bugfix over the short-lived 1.20.0

ChangeLog: https://github.com/brndnmtthws/conky/releases/tag/v1.20.0

Features

 * Build AppImage separately per OS
 * Rotate appimage signing key
 * Add/use clang 15 on ubuntu builds
 * Define text_object.data.l as "long long"
 * Bump web deps, fix lint
 * Updated flake per NixOS/nix#5532
 * Fix bad imlib2 typedefs for imlib<1.10
 * Use --force with brew install, block upgrades
 * Tidy up docs
 * Update README.md
 * Update README.md
 * Handle external PropertyNotify events
 * Label dependency changes
 * Tweak XSendEvent arguments
 * Add modified date to web docs
 * Improve documentation for window types and hints
 * Refactor x11 event handling
 * Issue template: Link docs to obtain stack traces
 * Exclusive XInput event handling

Bug fixes

 * Enable wayland in appimage build
 * Fix regression in lua_load path handling
 * Lua imlib2 fixes
 * Increase max length of ACPI temp (fixes #977)
 * Skip propagation of non-input events
 * Fix render order in draw_stuff
 * Fix event propagation on Openbox
 * Fix missing y_abs argument copy
clrpackages pushed a commit to clearlinux-pkgs/conky that referenced this issue Apr 19, 2024
…20.0

Brenden Matthews (40):
      Bump version
      Enable wayland in appimage build
      Add missing deps
      Build appimage on PRs
      Only sign appimage if the signing key is available
      Typo
      Fix clang versions
      Include arch in appimage name
      Check librsvg version before enabling
      Make sure correct libc++ is installed
      Refactor this
      Underp this derp
      Rotate appimage signing key
      Add/use clang 15 on ubuntu builds
      This too
      Reorder these
      Bump version
      Bump web deps, fix lint
      Updated flake per NixOS/nix#5532
      Update install instructions, fix Lua link
      Fix bad imlib2 typedefs for imlib<1.10
      This is duplicated
      Actually that won't work
      Update README.md
      Use --force with brew install, block upgrades
      This too
      Just ignore homebrew return code
      Fix regression in lua_load path handling
      Fix naming conflict for Imlib2.h
      Tidy up docs
      Add note about nixpkgs package to README
      Increase max length of ACPI temp (fixes #977)
      Update README.md
      Update README.md
      Label dependency changes
      Bump web deps
      Add modified date to web docs
      Bump follow-redirects (and other things)
      Sort
      Issue template: Link docs to obtain stack traces

Livanh (2):
      Define text_object.data.l as "long long"
      Re-define text_object.data.l as "int64_t"

Simon Lees (12):
      lua-imlib2: Improve Error handling
      lua-imlib2: Implement Stride in a standard way
      lua-imlib2: Fix alpha mask so that its scaled
      lua-imlib2: Add cairo_imlib2_helper to docs.
      lua-imlib2: move to conky style logging
      lua-imlib2: Fix typo in the docs.
      lua-imlib2: Add missing logging.h file
      Split cairo_draw_image into two functions
      Swap to internal C++ logging.h
      Fix Memory Leak
      cmake: use full path rather then relative.
      Document cairo_place_image

Stavros Ntentos (10):
      Build AppImage separately per OS
      `jobs.<job_id>.strategy.fail-fast = false`
      Missed `.sha256` extension
      Ubuntu 20.04 clang+library-versions typo
      D'oh! We need tags to `git describe`
      Try harder to ignore duplicate `conky.1.gz`s
      Allow visibility in `>> $GITHUB_ENV`s
      Download in `pwd`, not in `artifacts/`
      `git describe --tags --always --debug`??
      `actions/checkout@v4`: with: `fetch-depth: 0`

Tin Švagelj (9):
      Handle external PropertyNotify events
      Skip propagation of non-input events
      Fix render order in draw_stuff (#1801)
      Fix event propagation on Openbox
      Set propagate to True, to not propagate by default (#1809)
      Fix missing y_abs argument copy (#1813)
      Improve documentation for window types and hints (#1818)
      Refactor x11 event handling (#1819)
      Exclusive XInput event handling (#1821)

dependabot[bot] (8):
      build(deps): bump softprops/action-gh-release from 1 to 2
      build(deps): bump the web-deps group in /web with 6 updates
      build(deps): bump DeterminateSystems/magic-nix-cache-action from 3 to 4
      build(deps): bump DeterminateSystems/nix-installer-action from 9 to 10
      build(deps-dev): bump the web-deps group in /web with 7 updates
      build(deps): bump the web-deps group in /web with 11 updates
      build(deps): bump the web-deps group in /web with 8 updates
      build(deps-dev): bump express from 4.18.2 to 4.19.2 in /web
tcberner pushed a commit to freebsd/freebsd-ports-kde that referenced this issue Apr 24, 2024
Bugfix over the short-lived 1.20.0

ChangeLog: https://github.com/brndnmtthws/conky/releases/tag/v1.20.0

Features

 * Build AppImage separately per OS
 * Rotate appimage signing key
 * Add/use clang 15 on ubuntu builds
 * Define text_object.data.l as "long long"
 * Bump web deps, fix lint
 * Updated flake per NixOS/nix#5532
 * Fix bad imlib2 typedefs for imlib<1.10
 * Use --force with brew install, block upgrades
 * Tidy up docs
 * Update README.md
 * Update README.md
 * Handle external PropertyNotify events
 * Label dependency changes
 * Tweak XSendEvent arguments
 * Add modified date to web docs
 * Improve documentation for window types and hints
 * Refactor x11 event handling
 * Issue template: Link docs to obtain stack traces
 * Exclusive XInput event handling

Bug fixes

 * Enable wayland in appimage build
 * Fix regression in lua_load path handling
 * Lua imlib2 fixes
 * Increase max length of ACPI temp (fixes #977)
 * Skip propagation of non-input events
 * Fix render order in draw_stuff
 * Fix event propagation on Openbox
 * Fix missing y_abs argument copy
picnoir added a commit to numtide/nix-gl-host that referenced this issue Aug 10, 2024
Yeah, it's deprecated NixOS/nix#5532. But
that's the API we were fulfilling, let's be stable.

Fixes #22
TyberiusPrime added a commit to TyberiusPrime/anysnake2 that referenced this issue Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flakes good first issue Quick win for first-time contributors UX The way in which users interact with Nix. Higher level than UI.
Projects
Status: Done
8 participants