NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.86k stars 1.52k forks source link

`--extra-experimental-features` must come before other arguments as of Nix 2.19 #11891

Closed Enzime closed 1 day ago

Enzime commented 5 days ago

As of https://github.com/NixOS/nix/commit/89b39520630726b7c48e8cbc065643134352e43d, --extra-experimental-features "nix-command flakes" must come before --override-input:

$ nix run github:NixOS/nix/89b39520630726b7c48e8cbc065643134352e43d \
  --extra-experimental-features "nix-command flakes" \
  -- flake metadata github:edolstra/flake-compat \
  --override-input nixpkgs nixpkgs/nixpkgs-unstable \
  --extra-experimental-features "nix-command flakes"
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
$ nix run github:NixOS/nix/89b39520630726b7c48e8cbc065643134352e43d \
  --extra-experimental-features "nix-command flakes" \
  -- flake metadata github:edolstra/flake-compat \
  --extra-experimental-features "nix-command flakes" \
  --override-input nixpkgs nixpkgs/nixpkgs-unstable
warning: input '' has an override for a non-existent input 'nixpkgs'
warning: the flag '--override-input nixpkgs flake:nixpkgs/nixpkgs-unstable' does not match any input
Resolved URL:  github:edolstra/flake-compat
Locked URL:    github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33
Description:   Allow flakes to be used with Nix < 2.4
Path:          /nix/store/8kpx53qi52yhjai1vdw8zpa95iqa61bv-source
Revision:      0f9255e01c2351cc7d116c072cb317785dd33b33
Last modified: 2023-10-05 00:37:54

This is a regression as in the previous commit https://github.com/NixOS/nix/commit/bfe1308d3ff7f3dfd4facf4318adcb459e57ece9 this works fine:

$ nix run github:NixOS/nix/bfe1308d3ff7f3dfd4facf4318adcb459e57ece9 \
  --extra-experimental-features "nix-command flakes" \
  -- flake metadata github:edolstra/flake-compat \
  --override-input nixpkgs nixpkgs/nixpkgs-unstable \
  --extra-experimental-features "nix-command flakes"
warning: input '' has an override for a non-existent input 'nixpkgs'
warning: the flag '--override-input nixpkgs flake:nixpkgs/nixpkgs-unstable' does not match any input
Resolved URL:  github:edolstra/flake-compat
Locked URL:    github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33
Description:   Allow flakes to be used with Nix < 2.4
Path:          /nix/store/8kpx53qi52yhjai1vdw8zpa95iqa61bv-source
Revision:      0f9255e01c2351cc7d116c072cb317785dd33b33
Last modified: 2023-10-05 00:37:54

Steps to reproduce

  1. Ensure that experimental-features = nix-command flakes is not set in /etc/nix/nix.conf and ~/.config/nix/nix.conf
  2. Run the commands above

Priorities

Add :+1: to issues you find important.

cc @Ericson2314

edolstra commented 4 days ago

IMHO the new behaviour is better: you should enable an experimental feature before you can use a CLI option that depends on it.

Since this regression is in an experimental feature, I'm inclined to not fix it unless it affects a lot of people.

Ericson2314 commented 1 day ago

Yes this happened because the --override-input ... is processed immediately. Now that the indirect fetcher (the one that uses the registry) is marked as depending on the flakes experimental feature, we need flakes enabled before we can override the input with nixpkgs/*

--override-input is a flake feature, so it seems reasonable to me that we would require the flakes experimental feature.

The only proper way to still allow the arguments to come out of order would be, instead of immediately processing --override-input, building up a list of deferred actions and then processing --extra-experimental-features because anything else in that list. But this is a much larger project and not one the current CLI infrastructure is well set-up to support.

Closing as an acceptable behavior change --- this stuff is experimental, after all. Feel free to reopen if this causes more issues than anticipated.