Follow a directory from a input in flakes

Essentially, I want to be able to do this:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs?dir=lib";
  };
}

The above input fails with: error: invalid flake input path element 'nixpkgs?dir=lib'

Is this possible with a different syntax or is it not possible at all?

No this (i. e. https://github.com/nix-community/neovim-nightly-overlay/blob/1294c96baead66a8e3b051172f113069c8c19d1a/flake.nix#L9 the referred dir has a flake.nix file) is not possible, you might combine GitHub - nix-community/nixpkgs.lib: nixpkgs lib for cheap instantiation [maintainer=@github-action] (with initial help from @blaggacao) as an input with your general approach.

1 Like

Thanks! While the usage of follows for flake-parts in neovim-nightly does work, but doesn’t it seem misleading to follow the flake in the root project dir instead of sub-flake in the lib directory?

I could use nixpkgs.lib as a flake input and try to follow, but doesn’t it look more like a workaround?

What I would like to know is, if its worth for nix to support following a sub-dir flake, maybe with a syntax that looks like: ...follows = "nixpkgs?dir=lib";

It’s a slight inconvenience due to duplication, but this seems like a simple solution:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nixpkgs-lib.url = "github:NixOS/nixpkgs/nixpkgs-unstable?dir=lib";
    flake-parts.url = "github:hercules-ci/flake-parts";
    flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs-lib";
  };
}

I don’t know for sure if a feature like you’re proposing would be difficult to implement, but I believe the number of cases where you’d consider doing this is so rare that this precise nixpkgs situation is actually the only case where it could be useful.

2 Likes

Fair enough! Thank you