<nixos-config> error while combining configuration.nix and flakes

Hello NixOS friends,

Being new to both home-manager and flakes, I was surprised that this basic flake.nix could not be run with nixos-rebuild without the --impure option. I haven’t seen the error mentioned anywhere online, so I thought I’d ask here. Any ideas why that might be occuring?

The flake.nix is similar to a lot of basic examples floating around. Only modifications are to the URL and the home-manager username. It is based on this blog post from return12. The nix system it is being run on is not much more than the base install, which I’ve created for the purposes of testing NixOS configuration via flake.


[ejr@nixos-test:~/dotfiles]$ sudo nixos-rebuild switch --upgrade --flake '.#nixos-test'
warning: Git tree '/home/ejr/dotfiles' is dirty
building the system configuration...
warning: Git tree '/home/ejr/dotfiles' is dirty
error: cannot look up '<nixos-config>' in pure evaluation mode (use '--impure' to override)

       at /nix/store/hd3pdbffficwkxw8lx8rfvcbmxp3g3q8-source/nixos/modules/system/activation/top-level.nix:299:68:

          298|         config.system.copySystemConfiguration
          299|         ''ln -s '${import ../../../lib/from-env.nix "NIXOS_CONFIG" <nixos-config>}' \
             |                                                                    ^
          300|             "$out/configuration.nix"
(use '--show-trace' to show detailed location information)


# ~/dotfiles/flake.nix

  description = "NixOS configuration and home-manager configurations";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
  outputs = { home-manager, nixpkgs, ...}:
    nixosConfigurations.nixos-test = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        home-manager.nixosModules.home-manager {
          home-manager.useUserPackages = true;
          home-manager.users.ejr = {
            imports = [

So I found the source of the problem.

Inside configuration.nix I had this:

  # Copy the NixOS configuration file and link it from the resulting system
  # (/run/current-system/configuration.nix). This is useful in case you
  # accidentally delete configuration.nix.
  system.copySystemConfiguration = true;

I set it to false, and now nixos-rebuild without the --impure option works perfectly. :slight_smile:

1 Like