`nix.settings.experimental-features` not enabling flakes/nix-command system wide

I switched to flakes following the manual page and this guide: Introduction to Flakes | NixOS & Flakes Book

My configuration is being created from flake.nix and I’m building using

nixos-rebuild switch --flake 'path:.#desktop'

My flake.nix contains

{
  description = "Tom's Desktop";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";

    home-manager = {
      url = "github:nix-community/home-manager/release-24.05";
      inputs.nixpkgs.follows = "nixpkgs"; 
    };
   
    impermanence.url ="github:nix-community/impermanence/master";
  };

  outputs = { self, nixpkgs, home-manager, impermanence, nur, ... }@inputs: 
    let 
      globals = import ./globals.nix;
    in {
    users.mutableUsers = false;

    nix.settings.experimental-features = [ "nix-command" "flakes" ];

    nixosConfigurations.desktop = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./hardware
        ./system
        home-manager.nixosModules.home-manager
        impermanence.nixosModules.impermanence
        ./users/root
        ./users/${globals.user}
        {
          _module.args = { inherit inputs globals; };
        }
      ];
    };
  };
}

But when I run nix flake init I get

error: experimental Nix feature 'nix-command' is disabled; use '--extra-experimental-features nix-command' to override

I can run it with --extra-experimental-features nix-command as suggested and it works but the manual suggests that the nix.settings.experimental-features is permanent and the argument shouldn’t be required.

The problem is, that other tools which rely on the setting e.g.

 nixos-container create foo --config '
  services.httpd.enable = true;
'

breaks with the same error about flakes not being enabled yet doesn’t support the --extra-experimental-features argument directly.

It looks like nix.settings.experimental-features enables the feature for nixos-rebuild but not system wide

That’s the

unofficial user’s wiki

That has been hogging the domain and not allowing management by the foundation. Definitely not a manual. The official wiki is this one: NixOS Wiki - NixOS Wiki

The actual manual with the flake format description is here: nix flake - Nix Reference Manual


If you read that, you’ll note that neither nix nor users are valid flake outputs. You need to add those settings to your configuration, not just put them in random places. For simplicity, adding them here will work:

But you should probably put them in system/default.nix or such.

ah thanks for the clarification. Given that nixos validates the configuration I’m surprised it let me put it there without erroring on the build

There’s no error, just unused values. Nix will warn you about unrecognized flake outputs, though.

Only when you run nix flake check, though. External tools like home-manager often look for their own non-standard outputs so warnings during regular use would be annoying. There is a proposal to make flake outputs extensible in a more formalized manner using schemas.

1 Like