Any way to use custom fetcher for nix flake inputs?

The question
Is there a way to provide a custom fetcher to a nix flake?

The context
I’m building a tool targeted to meta-repo management. I’m trying to combine it with nix develop and nix build to make it comfortable for its specific development and packaging needs. The tool itself includes a lockfile system, but it is different from flake.lock because it serves different purpose and needs. We can think of it more like a replacement for git submodules.

So, given a meta-repo as an input, my derivation would produce a combined code source tree usable to make further derivations out from it. In practical terms, it’s a new fetcher.

Obviously it needs network access, so it’s a fixed-output derivation.

The problem
Since it is a fixed-output derivation, its hash will change eventually.

The easiest way of getting an updated hash would be to be able to use nix flake update, but for that my derivation should be used like a fetcher.

One example
I imagine a nix flake described like this:

inputs.customFetcher.url = "github:example/example-fetcher";
inputs.customFetchedInput = {
  type = inputs.customFetcher;
  url = "example://custom-url/somehow";
output = { self, nixpkgs, customFetchedInput, ... }: {
  defaultPackage.x86_64-linux = nixpkgs.mkDerivation { src = customFetchedInput.src; ... };

I’m not sure if this is possible or not, or if I’m being mistaken at some point.

I’m also worried to see Restrict fixed-output derivations · Issue #2270 · NixOS/nix · GitHub because it would destroy my project completely. :sob: I hope it never happens.

1 Like