How should I setup nested Flake 'follows' to use top-level nixpkgs?

I’m looking for advice on:

  1. Is trying to use the same nixpkgs version for nested Flakes silly?
  2. How best to allow nested Flakes to all follow my version of nixpkgs. I have a solution I stumbled into at the end.

I have managed to migrate my dotfiles setup to home-manager on PopOS/Mac. After I had things working well I changed my setup to use Flakes and setup home-manager to follow my version of nixpkgs. The inputs looked like the following:

{
  inputs = {
    home-manager = {
      inputs.nixpkgs.follows = "nixpkgs";
      url = "github:nix-community/home-manager";
    };
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
  };
}

Then I wanted to integrate a few rust utilities to have Flake support and ended up with the following:

# top-level flake
{
  inputs = {
    git-remote-open.url = "github:CoffeeAndCode/git-remote-open";
    home-manager = {
      inputs.nixpkgs.follows = "nixpkgs";
      url = "github:nix-community/home-manager";
    };
    mdquote.url = "github:CoffeeAndCode/mdquote";
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
  };
}

# example rust project flake
{
  inputs = {
    naersk.url = "github:nmattia/naersk";
    utils.url = "github:numtide/flake-utils";
  };
}

which creates something like the following inputs tree:

Inputs:
├───git-remote-open: github:CoffeeAndCode/git-remote-open/142ab1c4a0b34f23a232308d50359e79530b698f
│   ├───naersk: github:nmattia/naersk/32e3ba39d9d83098b13720a4384bdda191dd0445
│   │   └───nixpkgs: github:NixOS/nixpkgs/c3870f2bb5d1f631d7f6b31d744f25272c9a4dd7
│   ├───nixpkgs: github:NixOS/nixpkgs/c3870f2bb5d1f631d7f6b31d744f25272c9a4dd7
│   └───utils: github:numtide/flake-utils/eed214942bcfb3a8cc09eb3b28ca7d7221e44a94
├───home-manager: github:nix-community/home-manager/db00b39a9abec04245486a01b236b8d9734c9ad0
│   └───nixpkgs follows input 'nixpkgs'
├───mdquote: github:CoffeeAndCode/mdquote/9c93dfe71dfd3f5efc85f87d50fb1c65b8aaa14d
│   ├───naersk: github:nmattia/naersk/32e3ba39d9d83098b13720a4384bdda191dd0445
│   │   └───nixpkgs: github:NixOS/nixpkgs/c3870f2bb5d1f631d7f6b31d744f25272c9a4dd7
│   ├───nixpkgs: github:NixOS/nixpkgs/c3870f2bb5d1f631d7f6b31d744f25272c9a4dd7
│   └───utils: github:numtide/flake-utils/eed214942bcfb3a8cc09eb3b28ca7d7221e44a94
└───nixpkgs: github:nixos/nixpkgs/cd0ffd3f5fad719586a9b2d06b1faa603da6ba8d

I took a pass at trying to ‘follow’ in my Rust utility flake, but I don’t think it did much:

{
  inputs = {
    naersk = {
      url = "github:nmattia/naersk";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    utils.url = "github:numtide/flake-utils";
  };
}

I was able to get all nixpkgs to follow my top-level with the following, but I’m unsure if there’s a better way to handle it (or if it’s silly to even pursue).

{
  inputs = {
    git-remote-open = {
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.naersk.follows = "naersk";
      url = "github:CoffeeAndCode/git-remote-open";
    };
    home-manager = {
      inputs.nixpkgs.follows = "nixpkgs";
      url = "github:nix-community/home-manager";
    };
    mdquote = {
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.naersk.follows = "naersk";
      url = "github:CoffeeAndCode/mdquote";
    };
    naersk = {
      inputs.nixpkgs.follow = "nixpkgs";
      url = "github:nmattie/naersk";
    };
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
  };
}

Thanks for any advice.

4 Likes

Hello @jonknapp, I have a similar situation here:

The flake has this inputs tree:

Inputs:
├───flake-utils: github:numtide/flake-utils/7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19
├───neovim: github:nix-community/neovim-nightly-overlay/09064a12c364bc9dc912d06a00508f0e237a99b9
│   ├───flake-compat: github:edolstra/flake-compat/12c64ca55c1014cdc1b16ed5a804aa8576601ff2
│   ├───neovim-flake: github:neovim/neovim/3f097321955e32b0724e0f0d059ecef3d764aac8?dir=contrib
│   │   ├───flake-utils: github:numtide/flake-utils/997f7efcb746a9c140ce1f13c72263189225f482
│   │   └───nixpkgs: github:nixos/nixpkgs/ac169ec6371f0d835542db654a65e0f2feb07838
│   └───nixpkgs: github:nixos/nixpkgs/5e2018f7b383aeca6824a30c0cd1978c9532a46a
└───nixpkgs: github:nixos/nixpkgs/70088dc29994c32f8520150e34c6e57e8453f895

Adding neovim.inputs.nixpkgs.follows = "nixpkgs"; to my inputs works well but adding neovim.inputs.neovim-flake.inputs.nixpkgs.follows = "nixpkgs"; results in the following error:

error: cannot find flake 'flake:neovim-flake' in the flake registries

Have you since found a better solution than copying all those transitive dependencies to your inputs just to have their inputs follows something?

Nothing new from my end, just a lot of copy/paste.

I found an upstream bug report for this:

https://github.com/NixOS/nix/issues/5790