Which nixpkgs stable tag for nixos and darwin together?

I am trying to set-up a flake for both nixos and darwin systems, with home manager.

At the moment I am using unstable, which seems to work for both nixos and darwin. Home manager is set to 23.05.

Relevant config:

    pkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
    pkgs-stable.url = "github:nixos/nixpkgs/nixos-23.05";
    pkgs-stable-darwin.url = "github:NixOS/nixpkgs/nixpkgs-23.05-darwin";
    nixpkgs.follows = "pkgs-unstable";

I would like to switch to stable 23.05 everywhere. I am confused about which tag I should use for the nixpkgs input in that case. It is clear for nixos (pkgs-stable.url), it is (less) clear for darwin (pkgs-stable-darwin.url).

How is the nixpkgs-23.05-darwin tag different from the nixos-23.05 tag?

What should one use when configuring both nixos and darwin?

My full config is posted here.

Thoughts welcome!

(you probably want to use advice bellow)

For NixOS use nixos-* branches, for Mac use nixpkgs-*-darwin or nixpkgs-unstable. Yes annyoing, but this is the safest way to use it.

Using nixos-* on mac might cause some source builds, while using nixpkgs-*-darwin on NixOS might not only cause source builds, but severe failures, as important things like the kernel and bootloader are not checked.

Thanks @NobbZ , but how can I make this work in a flake that covers both architectures? I donā€™t understand how the nixpkgs is passed on to the respective machines. I made an attempt to override in the flake linked above but could not get it to work.

1 Like

Use the nixos-* inputs to call nixosSystem from, pass the -darwin related to whatever nix-darwin uses.

This is what I am trying to do indeed. But I do not see how, because I do not see how I am passing packages to darwin machinesā€¦ pardon my ignorance, I am new to this.

For nixos, it appears to be via the call to

nixos-host = inputs.pkgs-stable-nixos.lib.nixosSystem 

However, for darwin there is no

  mac-hostname = inputs.pkgs-stable-darwin.lib.nixosSystem 

but instead

mac-hostname = inputs.nix-darwin.lib.darwinSystem

nix-darwin is a different input from pkgs-stable-darwin.

So I am not sure how to pass github:NixOS/nixpkgs/nixpkgs-23.05-darwin without setting the nixpkgs variable to it for all hosts.

inputs...
pkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
pkgs-stable-nixos.url = "github:nixos/nixpkgs/nixos-23.05";
pkgs-stable-darwin.url = "github:NixOS/nixpkgs/nixpkgs-23.05-darwin";
nixpkgs.follows = "pkgs-stable-nixos";

outputs...
let
  mkModules = host: (import ./modules/hosts/${host} {inherit inputs;});
  in {
    nixosConfigurations = {
      nixos-hostname = inputs.pkgs-stable-nixos.lib.nixosSystem rec {
        system = "x86_64-linux";
        specialArgs = {
          inherit inputs system stateVersion;
        };
        modules = mkModules "nixos-hostname";
      };
    };

    darwinConfigurations = {
      mac-hostname = inputs.nix-darwin.lib.darwinSystem rec {
        system = "aarch64-darwin";
        # inputs = nixpkgs.lib.overrideExisting inputs {nixpkgs = nixpkgs-darwin;};
        specialArgs = {
          inherit inputs system stateVersion;
        };
        modules = mkModules "mac-hostname";
      };
    };
  };

EDIT: oh wait, it is maybe done with the follows attribute?

nix-darwin = {
  url = "github:lnl7/nix-darwin";
  inputs.nixpkgs.follows = "pkgs-stable-darwin";
};

Having the same nixpkgs sources for Nixos and macOS cannot be guaranteed, because the the branches are independent from one another and thereā€™s no target in hydra that performs both the NixOS tests and darwin tests, from what I understand, but I may be wrong.

Iā€™ve asked this here but it went unanswered.

In the end, I use two sub-flakes, one for darwin and the other for Linux that reference the main repo where most of the outputs are defined. In this way I can ā€œoverrideā€ some of the main flake outputs just for one of the OSes, while keeping most of the stuff declared in a common ā€œbaseā€ flake.

As far as I know (Iā€™m not a Darwin user) the darwinSystem takes a pkgs attribute

That is correct, and the pkgs attribute is passed on automatically by the modules system. I think because pkgs is part of _module.args by default?
I not sure how to override itā€¦
I have tried this (see commented out line), but this causes an error about the ā€˜libā€™ attribute missingā€¦

    darwinConfigurations = {
      mac-hostname = inputs.nix-darwin.lib.darwinSystem rec {
        system = "aarch64-darwin";
        # pkgs = inputs.stable-darwin.legacyPackages.aarch64-darwin.pkg;
        specialArgs = {
          inherit inputs system stateVersion;
          overlays = import ./overlays;
        };
        modules = mkModules "mac-hostname";
      };
    };

If darwinSystem works like HM in this regard (I donā€™t use darwin), then it would be pkgs = inputs.stable-darwin.legacyPackages.aarch64-darwin.