# Nix-pkgset: Cross-compilation aware (flake) package sets

**URL:** https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911
**Category:** Announcements
**Created:** [February 17, 2024, 2:30pm UTC](https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911 "2024-02-17T14:30:48Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![szlend](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@szlend](https://discourse.nixos.org/u/szlend)
#### Post date: [February 17, 2024, 2:30pm UTC](https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911/1 "2024-02-17T14:30:48Z")

</div>

Inspired by @jade’s [Flakes aren’t real](https://jade.fyi/blog/flakes-arent-real/), @zimbatm’s [1000 instances of nixpkgs](https://zimbatm.com/notes/1000-instances-of-nixpkgs) and my own struggles working with cross-compilation across flake input boundaries over the past year, I’ve prototyped a library called [nix-pkgset](https://github.com/szlend/nix-pkgset).

[Nix-pkgset](https://github.com/szlend/nix-pkgset) is a lightweight library that helps package nix derivations into cross-compilation aware package sets by [splicing](https://nixos.org/manual/nixpkgs/stable/#ssec-cross-dependency-implementation) packages in the same fashion as [nixpkgs](https://github.com/NixOS/nixpkgs).

**Design goals:**

- Adopt the packaging conventions of `nixpkgs` as much as possible (scopes, splicing, `pkgs<build><host>`, `pkgsCross`, etc.)
- Avoid re-instantiating nixpkgs (use `lib.makeScope` instead of overlays)

**WARNING:** The library is still in proof of concept stage and the API is subject to change.

My understanding of nixpkgs scopes and splicing is still pretty limited so it’s possible that some of what I’m doing is insane. I would love to get some feedback on this, especially from `nixpkgs` maintainers responsible for scopes and splicing. My hope is to eventually have something similar upstreamed to `nixpkgs`.

Nix-pkgset: [GitHub - szlend/nix-pkgset: Nix package set library](https://github.com/szlend/nix-pkgset)

---

<div class="post-metadata">

### Author: ![tomberek](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tomberek/32/283_2.png) [@tomberek](https://discourse.nixos.org/u/tomberek)
#### Post date: [February 17, 2024, 3:48pm UTC](https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911/2 "2024-02-17T15:48:17Z")

</div>

I love this direction. It presents a simpler interface to people and a potential to standardize how nixpkgs itself does this.

I’ve been playing and implementing a very similar set of ideas of leveraging makeScope, package sets, and reducing the cognitive load compared to overlays. I’d love to discuss if you have a chance.

Spoke about a similar idea to “lib.makePackageSet” at the end of this talk: [FOSDEM 2024 - Units of composition: recipes, overlays, and packages](https://fosdem.org/2024/schedule/event/fosdem-2024-3107-units-of-composition-recipes-overlays-and-packages/) I would encourage exposing the recipes prior to callPackage’ing them.

---

<div class="post-metadata">

### Author: ![szlend](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@szlend](https://discourse.nixos.org/u/szlend)
#### Post date: [February 17, 2024, 4:36pm UTC](https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911/3 "2024-02-17T16:36:51Z")

</div>

@tomberek Excellent talk! I wish I saw it earlier cause I really like the idea of composing recipes over packages. I also share your pain of naming some of these concepts.

> I’ve been playing and implementing a very similar set of ideas of leveraging makeScope, package sets, and reducing the cognitive load compared to overlays. I’d love to discuss if you have a chance.

Would love to see what you’ve been up to and possibly join efforts. If you’d like to reach me, you can find my email in the nixpkgs maintainers list and I can also share other contact methods there. For any comments on `nix-pkgset` feel free to open issues on Github as well.

---

<div class="post-metadata">

### Author: ![Lun](https://discourse.nixos.org/user_avatar/discourse.nixos.org/lun/32/5552_2.png) [@Lun](https://discourse.nixos.org/u/Lun)
#### Post date: [March 15, 2025, 6:48pm UTC](https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911/4 "2025-03-15T18:48:23Z")

</div>

Has there been any progress in this area recently, in nix-pkgset or other people’s attempts in the same area?  
I like the approach here, the proof of concept status makes it a bit unappetizing to use.

---

<div class="post-metadata">

### Author: ![szlend](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@szlend](https://discourse.nixos.org/u/szlend)
#### Post date: [March 16, 2025, 3:14pm UTC](https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911/5 "2025-03-16T15:14:53Z")

</div>

There’s a bunch of experiments in the library. I think the only thing I would really keep is the simplified API for creating spliced package sets.

Something along the lines of:

```auto
pkgset = makePackageSet "foo" pkgs.newScope (self: {
  ...
})

```

This would make a new package set based on the scope of `pkgs`. And also include:

- `pkgset.foo` (a pre-spliced packageset if you wanna avoid `callPackage` when doing cross-compilation. Equivalent to `pkgs.__splicedPackages`)
- `pkgset.fooBuildBuild`, `pkgset.fooBuildHost`, `pkgset.fooHostHost`, `pkgset.fooHostTarget`, `pkgset.fooTargetTarget` for when you want to access unspliced package variants.

Other features like mimicking `pkgsCross` and merging package sets I would probably throw away for simplicity’s sake.

This is what I’ve been using for a while now, but I haven’t updated the library yet. I can do this soon.

---

<div class="post-metadata">

### Author: ![szlend](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@szlend](https://discourse.nixos.org/u/szlend)
#### Post date: [March 19, 2025, 7:06am UTC](https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911/6 "2025-03-19T07:06:22Z")

</div>

I’ve updated the library to the first release candidate for a stable release. The API for `makePackageSet` has changed and there’s no more merging of package sets. Instead each package set is named so they’re still accessible if you layer them one on top of the other.

I’ve been using a similar setup for a few months now so I’m pretty happy with the API.

I’d be happy to hear some feedback and then stabilize this.

---

<div class="post-metadata">

### Author: ![Lun](https://discourse.nixos.org/user_avatar/discourse.nixos.org/lun/32/5552_2.png) [@Lun](https://discourse.nixos.org/u/Lun)
#### Post date: [March 26, 2025, 8:28pm UTC](https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911/7 "2025-03-26T20:28:54Z")

</div>

Giving it a shot, is there an intended way to expose the scope in a way that it can be instantiated on top of an arbitrary nixpkgs instance eg for cross usage?

Some options, exposing a flake `attr mkPkgset = pkgs: nix-pkgset.lib....`, or having the flake’s legacyPackages output have .override available so you can do `.override { pkgs = myPkgsCross; }`. Although I guess that’s slower since the original nixpkgs had to be instantiated first?

Maybe you already intended a particular way and I skipped over it.

---

<div class="post-metadata">

### Author: ![szlend](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@szlend](https://discourse.nixos.org/u/szlend)
#### Post date: [March 26, 2025, 11:59pm UTC](https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911/8 "2025-03-26T23:59:01Z")

</div>

The intended way is to just:

```auto
makeMyPkgset = pkgs: nix-pkgset.lib.makePackageSet "myPkgset" pkgs.newScope f;

```

Then you can initialize it however you want:

```auto
pkgset = makeMyPkgset pkgs;
pkgsetCross = makeMyPkgset pkgsCross;

```

I should probably document this better. But I’m not yet convinced adding a shortcut to override the base `newScope` is really necessary.

---

<div class="post-metadata">

### Author: ![Lun](https://discourse.nixos.org/user_avatar/discourse.nixos.org/lun/32/5552_2.png) [@Lun](https://discourse.nixos.org/u/Lun)
#### Post date: [March 27, 2025, 12:29am UTC](https://discourse.nixos.org/t/nix-pkgset-cross-compilation-aware-flake-package-sets/39911/9 "2025-03-27T00:29:42Z")

</div>

From the “1000 instances of nixpkgs” perspective having a standard/recommended way in the README to instantiate someone else’s flake that uses this lib’s pkgset on top of an arbitrary existing pkgs instance seems like a good idea.
