Using experimental Nix features in Nixos, and when they will land in stable

I’m a long time but non-expert user of NixOS. I found out today about two experimental Nix features (both seemingly spearheaded by @edolstra): flakes and nix-command. These look amazing.

I have two questions:

  1. What is the best way to use these features in NixOS?
  2. What is the roadmap for integrating either of these into Nix?

Edit: Really what I’m asking in #1 is how I can use the features showcased in the Tweag blog post on NixOS. I am on the unstable channel and I have added nixFlakes to my packages. I do not know where to add the experimental-features line, since ~/.config/nix/nix.conf does not exist and nix.extraOptions doesn’t seem right either. Maybe I am using nix-command since I can now use e.g. nix build, but I do not have e.g. nix dev-shell.

2 Likes

You can actually create ~/.config/nix/nix.conf and it will be respected even on NixOS. It’s just extra options for specific user, by default home directories are not managed by Nix unless you install home-manager.

nix.extraOptions could also work but it would be global.

Thanks @takeda. If I add:

  nix.extraOptions = ''experimental-features = nix-command flakes'';

to my NixOS config, it results in warning: unknown setting 'experimental-features' whenever running Nix.

Similarly running nix --experimental-features nix-command dev-shell results in error: unrecognised flag '--experimental-features'.

Running nix --version gives nix (Nix) 2.3.4. Do I need to do something to manually upgrade it past nixpkgs unstable?

Edit: If I install nixFlakes explicitly with nix-shell, I do get access to dev-shell and flakes (but still not nix shell like the blog post). Still not understanding why installing nixFlakes in my NixOS systemPackages didn’t work, do I need to keep it from being overwritten by the default nix command?

3 Likes

You need to set nix.package in configuration.nix:

nix = {
   package = pkgs.nixFlakes;
   extraOptions = lib.optionalString (config.nix.package == pkgs.nixFlakes)
     "experimental-features = nix-command flakes";
};

The fragment above should be adjusted to check for the nix version instead as of 2022-07.

8 Likes

@peterhoeg

Exactly what I was looking for, thanks!

I would like to use these features for a project that I contribute to, but I don’t want to require users to figure out how to use experimental features - is there a roadmap for when these features will land in stable Nix? Nix 3.0? I don’t know where to look for that information.

I guess the flakes-v2 milestone on the nix project is the place to go:

1 Like

I’m hitting certainly a more basic wall:

I just did curl -L https://nixos.org/nix/install | sh, where would I find (or place) configuration.nix so that I can fully replicate the post blog?

What you are doing is installing nix.

/etc/nixos/configuration.nix is for NixOS.

That particular blog posts gives instructions on how to use nix with flakes support on NixOS.

While you absolutely can use nix on its own, I will suggest installing NixOS in a VM instead in order to get the full experience: Download Nix / NixOS | Nix & NixOS

1 Like

Thank you!

I’m stepping up the learning curve and I’ve noticed that there is a prepackages nix package called something like nixFlakes.

I guess that also effectively brings flakes to my nix executable.

I ultimately put the experimental flag in .config/nix/nix.config and it is taken up, but still I need to check the preview version of nix to recognize it as a valid flag.

Sorry for this basic question, for a beginner, nix is a bit of a jungle without a clear pathway.