Nix registry pin nixpkgs with overlay

Hello, I’ve been playing with flakes lately. I’ve found nix.registry.nixpkgs.flake = inputs.nixpkgs to be useful for matching the package version to one already existing when doing stuff like nix shell.

In the system configuration there’s overlays provided to, for example, add a package. I’d like this package to also be available in the pinned nixpkgs, but I haven’t found a way to do it.

Can anyone point to an example of how to pin nixpkgs to one with overridden and added packages?

I’d love for there to be a way to do that too, but it’s probably impossible because a flake must be source code that can be read and evaluated (from the store or from a url).

what you can do is pin your system config flake itself (self) in the registry and have the overlay that you want to reuse downstream be one of its outputs (overlays.default is a good choice)

an alternative is to have the added packages themselves be system flake outputs, so you can just use them without any overlays

Create a pinned entry for the “overlay” and use its packages directly.

If they don’t provide a package set in the outputs, ask for it! package should be the default, not an overlay!

Can you show me an example of what you mean by that? I’ve tried a bunch of different things without any luck on simplifying how to use overlay packages on different hosts.

The packages are my own. I did add a self entry to the registry, but that has the issue that there’s only one for multiple hosts that might have different overlays, and that I still have to know what flake I’m looking for a package in when I want to do a quick nix shell (well, normally nix-shell -p, but I haven’t figured out that migration yet.

I did pin the self to the registry, but the issue with that is I have to know what flake a package is in, and I don’t know how to make a different one per host.

I was hopeful I’d have something easy such that I could modify packages on a host basis, while being able to use something like nix-shell. I’m already having to type extra with adding nixpkgs# to the start.

I don’t understand what you mean by different overlays.

Just use self#package on the CLI.

If my flake.nix has an output of packages, then that will be the same set of packages for each host, won’t it? Or maybe there’s some way to tie together the nixosConfigurations and the output.packages?

Or perhaps I’m not making any sense at all. The idea of what I was thinking was that I’d be able to use one command (like nix shell self#something) and it would use local package configuration for that host. That local config might be some subset of new packages and overlays to existing packages, but I wouldn’t have to worry about knowing what that config was when I just ran a shell.

If it helps, my github config is here.

Lately, I’ve been (ab?)using impure expressions like (builtins.getFlake "/etc/nixos").outputs.nixosConfigurations.cs-338._module.args.pkgs. It’s somewhat dirty, but I rely on this hack to re-use the prebuilt pytorch/tensorflow in some development environments until I have a better solution

1 Like