Flake + Home Manager on NixOS error [ flake-utils used]

I use flake + home manager for both macOS and NixOS (in win WSL).
In the 1st version, system architectures ("x86_64-linux/x86_64-darwin) are given statically in the file, I can use flake to run home manager successfully on both MacOS and NixOS.

In the new version, I added flake-utils.lib.eachDefaultSystem to support multiple system architectures automatically.

In this new version, I can successfully run the following command to execute the Home Manager in macOS:
nix run nix-darwin -- switch --flake ~/dotfiles-nix/#x86_64-darwin.Xis-MacBook-Pro

However, I can’t figure out the correct command for NixOS. I have tried the following:

sudo nixos-rebuild switch --flake ~/dotfiles-nix#nixos
sudo nixos-rebuild switch --flake ~/dotfiles-nix#nixosConfigurations.nixos
sudo nixos-rebuild switch --flake ~/dotfiles-nix#x86_64-linux.nixos

All with error:

error: flake 'git+file:///home/nixos/dotfiles-nix' does not provide attribute 'packages.x86_64-linux.nixosConfigurations."x86_64-darwin.nix-os".config.system.build.nixos-rebuild', 'legacyPackages.x86_64-linux.nixosConfigurations."x86_64-darwin.nix-os".config.system.build.nixos-rebuild' or 'nixosConfigurations."x86_64-darwin.nix-os".config.system.build.nixos-rebuild'

Nix flake show:

Can anyone help me with the correct command for NixOS, and probably also explain how the “#” section in the command matches the flake.nix structure whenflake-utils is used? Thanks!

Be aware that you expose the nixosSystem as “nixos”, so it should be

sudo nixos-rebuild switch --flake ~/dotfiles-nix#nixos

(Not tested)

I am not sure why you sneaked in a - on your try.

1 Like

I corrected the type from “nix-os” to “nixos”

But they are with the same error including your suggested: sudo nixos-rebuild switch --flake ~/dotfiles-nix#nixos

Your flake wrongs appends a system under nixosConfiguration which is not correct

nix-repl> :lf github:xixiaofinland/dotfiles-nix/cf4497678215f73219591f5a8788f9aba84a8726  Added 13 variables.

nix-repl> nixosConfigurations
nix-repl> nixosConfigurations.
nixosConfigurations.aarch64-darwin  nixosConfigurations.x86_64-linux

What do you try to archive with the global for each system? A nixosConfiguration is for a specific host that has a system and can not have multiple system AFAIK.

You likely just want to use that for devShells or packages.

Edit: about the #, that defines the attribute to load from the flake and nixos-rebuild will try packages (from other flakes), legacy packages (from nixpkgs) and nixosConfigurations (as you see in the error message what it tried to load).

Edit2: possibly a worth read it Why you don't need flake-utils · ayats.org
, which is exactly stating your issue.

1 Like

Thanks for your help! What do you mean by “the global for each system”?

I’m learning Nix lang and see many templates on the internet use flake-utils to wrap functionalities to support all 4 system architects elegently. I thought this was a best practice.

My old version worked for my x86_64-darwin (macOS) and x86_64-linux (NixOS), but I have them specifically hard-coded (nixos-sys = "x86_64-linux" and mac-sys = "x86_64-darwin"), so once it worked I gave flake-util a try to make the code more elegant and support more systems (I don’t really have this need, meant to practice and write idiomatic Nix).

In my new flake.nix, the MacOS/darwin home manager part works (I think it now supports both x86_64-darwin and aarch-darwin, right?), so I thought it was the same for the nixOS part. Thus you can see both nixosConfigurations and darwinConfigurations are put inside eachDefaultSystem.

I think I miss the skill/command (like nix-repl :lf etc.) to look into the nix structure, thus couldn’t figure out what really is the flake output structure v.s. what structure is needed by nixosConfigurations. Thanks for showing the reply commands!

how do you know if a system is needed or not? In case it’s not , then flake-util indeed shouldn’t wrap nixosConfiguration in. I will read your article through.

The valid flake schema is quite good described at


I am talking about the eachDefauktSystem at level of the outputs attr.
That will cause that a system will be put after nixosConfigurations, which is not valid (see the blog post I linked)

Do you actually “support” those architectures? I mean do you use them and can fix issues with that.
On my opinion flake-utils users tend to declare “supported” system architectures that have never been tested by them, which means they are not supported. You possibly then just make a false claim.
A better approach on my option then is to use the systems flake input and let users override it, in case they want to try your stuff on unsupported/untested architectures, but they will know that they are left alone if it’s not working.

Not really sure if a nixosConfigurations is really meant to be portable to roam around multiple architectures by design, if so it would have a systems in the attr path like the packages do.

Thank you sincerely, I think I have a better understanding now. Also nix-repl> :lf to check the output parameters is also handy.

The “when things go wrong” section in the article Why you don’t need flake-utils also explicitly said the problem I introduced.

I removed flake-util and used forAllSystems for devShells. It supports only systems that I personally use, i.e. x86_64-linux and x86_64-darwin.

the updated version is here.