hercules-ci / flake-parts

❄️ Simplify Nix Flakes with the module system
https://flake.parts
MIT License
721 stars 41 forks source link

How to configure multiple overlays to different hosts? #139

Open ghost opened 1 year ago

ghost commented 1 year ago

I have two overlays, two hosts. Host 1 needs to use overlay1 Host 2 needs to use overlay1 overlay2.

{ self, inputs, ... }: {
  flake.overlays.default = import ../pkgs;

  perSystem = { system, ... }: {
    _module.args.pkgs = import self.inputs.nixpkgs {
      inherit system;
      overlays =
        [ self.overlays.default 2.overlays.default ];
      config.allowUnfree = true;
    };
  };
}

IMG_5789

roberth commented 1 year ago

Flake evaluation is designed not to depend on external factors, such as which host is evaluating the flake.

I would recommend something like NixOS or home-manager to configure host environments. These each have their own ways of initializing the pkgs module argument.

Alternatively, if you do not want to manage significant portions of your host environment declaratively, you could declare the relevant packages for each host using distinct package names. Instead of just _module.args.pkgs, you could also add _module.args.pkgs2 or any other name. pkgs is only "special" because it is implicitly expected by some modules. flake-parts itself does not come with such an expectation though.

akirak commented 1 year ago

@nuusers In your case, you won't specify those host-specific overlays under perSystem though? You can specify overlays for a NixOS system as part of the configuration:

nixpkgs.lib.nixosSystem {
  inherit system specialArgs;
  modules = [
   {
      # Specify overlays for the system
      nixpkgs.overlays = overlays;
   }
   ...
  ];
}
kekeqwq commented 1 year ago

@roberth Sorry I lost my account, here is my solution: https://github.com/kekeqwq/flakes/blob/3916883f74fbcd924f5679526a7bcea996c486ea/flake-parts/nixos.nix#LL30C32-L30C32 You can close this issue.