System config flake with darwin and linux system definitions

I’m trying to consolidate the system config + HM flakes for my linux machines and a aarch64-darwin.

I thought I’d just mix them up to have:

  outputs = inputs @ { self, nixpkgs, nurpkgs, nixpkgsUnstable, musnix, home-manager }:
    {
      homeConfigurations = (
        import ./outputs/home-conf.nix {
          inherit (inputs) nixpkgs nurpkgs nixpkgsUnstable home-manager;
          nixosConfigs = inputs.self.nixosConfigurations;
        }
      );

      nixosConfigurations = (
        import ./outputs/nixos-conf.nix {
          inherit (nixpkgs) lib;
          inherit inputs;
        }
      );

      darwinConfigurations."jm1b" = darwin.lib.darwinSystem {
        # nixpkgs.overlays = overlays;
        specialArgs = { inherit darwin overlays; };
        system = "aarch64-darwin";
        modules = [ ../system/machine/jm1b/darwin-configuration.nix ];
      };
    };

because they’re lazily evaluated anyway, and then call the same flake with nixos-rebuild on linux and darwin-rebuild in mac.

But when I add darwin to the inputs, and run for a linux system, I get the following error:

error: 'outputs' at /nix/.../flake.nix:27:13 called with unexpected argument 'darwin'

So I’m still stuck with a different flake for darwin; for synergy I’m just importing the user specific HM config part via outputs/home-conf.nix which then calls all the user’s packages/services/programs via imports, to get the “same” settings for my user across systems. (System-specifics are selected with conditional imports).

Is anyone running multi-platform configs from one flake; how to achieve that?

The objective is to have one flake and all systems/users imported from nix expressions in respective subdirs, to leverage sharing of common settings without duplication.

There is no darwin input here, what is your full config? What exactly do you change when you say

Is all you need to do adding a ... to that arg list?

1 Like

Ah yes, of course (it had probably gotten too late :man_facepalming: )…
Indeed it was a simple matter of missing darwin in the arguments.

So finally I came up with this (I’ll refactor a bit more I guess to use the nixos-conf wrapper to get it more parametrised):

{
  description = "Home Manager (dotfiles) and NixOS configurations";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
    nixpkgsUnstable.url = "github:NixOS/nixpkgs/nixos-unstable";

    darwin.url = "github:lnl7/nix-darwin/master";
    darwin.inputs.nixpkgs.follows = "nixpkgs";

    home-manager = {
      url = github:nix-community/home-manager/release-22.05;
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nurpkgs = {
      url = github:nix-community/NUR;
      # inputs.nixpkgs.follows = "nixpkgs";
    };

    musnix = { url = "github:musnix/musnix"; };

    # tex2nix = {
    #   url = github:Mic92/tex2nix/4b17bc0;
    #   inputs.utils.follows = "nixpkgs";
    # };
  };

  outputs = inputs @ { self, nixpkgs, nurpkgs, nixpkgsUnstable, musnix, home-manager, darwin }:
    {
      homeConfigurations = (
        import ./outputs/home-conf.nix {
          inherit (inputs) nixpkgs nurpkgs nixpkgsUnstable home-manager;
          nixosConfigs = inputs.self.nixosConfigurations;
        }
      );

      nixosConfigurations = (
        import ./outputs/nixos-conf.nix {
          inherit (nixpkgs) lib;
          inherit inputs;
        }
      );

      darwinConfigurations."jm1b" = let
          system = "aarch64-darwin";
          overlays = [
            (final: prev: {
              unstable = inputs.nixpkgsUnstable.legacyPackages.aarch64-darwin;
            })
          ];
        in darwin.lib.darwinSystem {
          inherit inputs system;
          specialArgs = { inherit darwin system overlays; };
          modules = [ ./system/machine/jm1b/darwin-configuration.nix ];
        };
    };
}
1 Like