Flake and hardware-configuration.nix

In an attempt of switching to use flake to manage my NixOS configuration, nixos-rebuild reported this error:

error: cannot look up '<nixpkgs/nixos/modules/installer/scan/not-detected.nix>' in pure evaluation mode (use '--impure' to override) 
                                                                                                                                 
   at /nix/store/k31v0jpfglgwj8qpqmc06d0a0h1zgg0y-source/hardware-configuration.nix:8:7:                                         
                             
        7|   imports =                                        
        8|     [ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>                                                                      
         |       ^         
        9|     ];                                                                                                                
(use '--show-trace' to show detailed location information)

I commented that import out to proceed.

However, hardware-configuration.nix is generated by nixos-generate-config, and its header comment suggests not to edit it, as it may change “in future invocations”. I checked its source, but it pushes the import unconditionally, without the knowledge of flake.

Did you have this issue? How did you solve it?

Thanks in advance.

Change to this:

  imports = [
    (modulesPath + "/installer/scan/not-detected.nix")
  ];
3 Likes