Error: experimental Nix feature 'nix-command' is disabled

Dear all,
I am somewhat stuck using ‘nix build’ to build a cloned git-repository. Maybe (even most likely) it’s something dumb, but I really don’t know what the CLI tries to tell me :confused: .
First some context:
I would like to use a nix flake to build a project written in C++ on Ubuntu 20.04 with KDE (looks like Kubuntu, but KDE was installed after I figured that Gnome is to slow). I used this tutorial here:

Tested the hello-world package, everything works fine - so off to building the cloned repo.

Running the command ‘nix --extra-experimental-features nix-build [repo folder]’, I get
'warning: unknown experimental feature ‘nix-build’

If I now run the command ‘nix build’ (which is listed if I run “nix --help” under the headline ‘Main commands’) I get the error message:
‘error: experimental Nix feature ‘nix-command’ is disabled; use ‘–extra-experimental-features nix-command’ to override’

I would suspect, that I have not activated the experimental features yet, but I could not find a solution online either. Could you please point me the right direction on what to put into the command line? I really appreciate your help :).

Kind regards,

Sebastian

2 Likes

Have you tried using the suggested option instead of inventing your own?

Nix is telling you the answer, as @NobbZ says :slight_smile:

You can also make that permanent using nix.extraOptions or by writing the same into ~/.config/nix/nix.conf .

2 Likes

Yeah, it’s a bit confusing, but you are meant to append literally --extra-experimental-features nix-command and not --extra-experimental-features nix-command, where command=build.
The reason for this “weirdness” is that the official command is still nix-build, which will be replaced in the future by nix build, but this command is not considered stable yet. By adding all that it should make people aware that they shall not yet assume this is how the CLI will look in the end.

7 Likes

Hej,
thanks a lot for the fast answer and explaining the rationale behind it :slight_smile: . Final command resulted to
nix --extra-experimental-features nix-command build [folder]
Then I got the error. ‘error: experimental Nix feature ‘flakes’ is disabled; use ‘–extra-experimental-features flakes’ to override’.
So the command:
nix --extra-experimental-features nix-command --extra-experimental-features flakes build [folder]
finally did the job!

1 Like

Alternatively this would work as well:

$ nix --extra-experimental-features "nix-command flakes" build [folder]
5 Likes

I’m encountering this for direnv for some reason. I fixed it by adding this to my configuration.nix:

    nix.extraOptions = ''
    experimental-features = nix-command
    '';
1 Like

Given a recent enough nixpkgs (since 22.05) nix.settings.experimental-features = "nix-command flakes" would be the way.

3 Likes

Thanks! It took me quite a while to find this knowledge. Is this documented anywhere?

1 Like

What exactly do you mean?

The experimental-features config option is mentioned in the nix manual about the nix.conf:

https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-experimental-features

The nixos option in the option search:

https://search.nixos.org/options?channel=22.11&show=nix.settings&from=0&size=50&sort=relevance&type=packages&query=nix.settings

Which exact values to add or which experimental features are available is not documented in either.

You need to discover them, and their interdependencies on your own, as you try to do things…

The most common to be used today are nix-command and flakes, though there are also ca-derivations (content addressed derivations), impure-derivations and recursive-nix (allows nix being used in a derivation). Perhaps there are even more, but those are the ones I have seen being discussed or used in the wild.

2 Likes

Worth noting that these days nix will loudly complain to you if the settings are missing, and explain exactly what to put in your nix.conf to enable the experimental features you were trying to use in the error message.

3 Likes

I think he means it’s especially difficult to figure out what the correct command is, made difficult by the confusing error messages. To illustrate the practically user-hostile flow, a command mentioned simply as “nix search” in the automatically generated default config for every first NixOS build is apparently supposed to be nix --extra-experimental-features nix-command search if one happens to understand that first error correctly. And, after running this with the confidence of cathartic clarity, it errors again. My mistake, the correct form of “nix search” is nix --extra-experimental-features nix-command --extra-experimental-features flakes search. Wait, that doesn’t work.

3 Likes

So weiiiiiiiiiiirrdd, ahhhhhhhhhhhhhhhhhhhh

But it works…

error: cannot find flake ‘flake:’ in the flake registries