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:
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'
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!
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).
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.
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.