Re-use system flake lockfile in other flakes

Hello folks. I have a NixOS system set up using a system flake. This means I have an /etc/nixos/flake.lock pointing to fixed versions of various inputs used in building my system configuration.

When starting a new development project, I’d like to be able to reuse the specific versions of these inputs already pinned in /etc/nixos/flake.lock. What is the easiest way to do this?

I’m aware that I could just manually edit the flake.lock of the new project to align it with /etc/nixos/flake.lock, but I was wondering if there’s something in the Nix “porcelain” that already allows me to do this.

Add your pinned repositories to flake registry and then it will automatically use these versions when you will do flakes:foo as a flake source.

Thank you. If I understand your suggestion correctly, it consists of two parts.

Step 1: Add a module like this to my system configuration:

{ config, inputs, <input-name>, ... }:
{
  config = {
    nix.registry.<input-name>.flake = inputs.<input-name>;
  };
}

where inputs are the inputs of my system flake (injected into the module via extraSpecialArgs).

Step 2: Use flakes:<input-name> as the url of the relevant input in the downstream flake.nix, like so:

{
  inputs = {
    <input-name>.url = "flakes:<input-name>";
  ...

This didn’t quite work as-is (I get an error saying “error: input ‘flakes:’ is unsupported”), but dropping the flakes: prefix seems to make it work.

Thanks!

The one minor dissatisfaction I have with this solution is that it involves modifying flake.nix in a non-portable way, as opposed to only modifying flake.lock.

But this is easily worked around: after I’ve generated the initial flake.lock I can just remove the registry indirection from input.<input-name>.url and point it to the original URL.