numtide / blueprint

Nix without the glue code
53 stars 6 forks source link

support multiple instances of nixpkgs #22

Open zimbatm opened 4 months ago

zimbatm commented 4 months ago

At the moment, only the "nixpkgs" input is used to:

Some users might want to use different versions of nixpkgs for different machines (eg: stable and unstable)

kriswill commented 3 months ago

or, use multiple nixpkgs? For instance, I like my OS nixpkgs to be pinned to the current nixos-release tag, but use certain applications from the unstable, or even trunk...

zimbatm commented 3 months ago

The current workaround is to create a modules/common/nixpkgs-unstable.nix module.

{ inputs, pkgs, .... }:
{
  _module.args.pkgsUnstable = import inputs.nixpkgs-unstable {
    inherit (pkgs) system;
    config.allowUnfree = true;
  };
}

Then import it in whatever module needs it:

{ flake, pkgsUnstable, ... }:
{
  # Import to add the pkgsUnstable argument
  imports = [ flake.modules.common.nixpkgs-unstable ];
  # Pull the package from pkgsUnstable
  services.myservice.package = pkgsUnstable.myservice;
}
jfly commented 1 month ago

Do you have a plan for the "api" you'd like to expose here, @zimbatm? In other words, how would people specify which instance of nixpkgs to use for each host?

I personally like being able to patch nixpkgs (example here) before using it to define my nixosConfigurations. It would be quite cool if whatever API we design here would allow for something like that.

I'd be interested in trying to implement this if you're open to a PR.

zimbatm commented 1 month ago

Not super precisely.

There is a need for patching/overriding inputs. For this, we could add inputs/<name>/default.nix pattern that can be used to override said inputs. Details tbd.

Then, there is a need to map a nixpkgs input to a host. We have hosts/<hostname>/default.nix where you can do your own calls to nixosSystem, but then it's missing some of the integration / specialArgs that blueprint is providing. Ideally you could just map a specific host to a specific nixpkgs input. Maybe introduce a hosts/inventory.toml or hosts/<hostname>/meta.toml where the mapping could be specified. This would also open the road to adding other meta information like the SSH users for deploy tools.