How to disable automatic unpacking of nix flake inputs?

Is it possible to disable the automatic unpacking of Nix Flake inputs?

For example, say we have the following flake.nix which depends on a non-flake tarball:

{
  inputs = {
    tarball = {
      url = "https://some.tar.zst";
      flake = false;
    };
  };
  outputs = { self, tarball }: {
    # I would like tarball to remain how it was downloaded, so no unpacking.
  }
}
3 Likes

This sounds like @pwaller’s recent issue: Flake inputs fetched and unpacked despite outputs being a cache hit · Issue #9570 · NixOS/nix · GitHub

3 Likes

Thanks, it’s similar to that issue but what I’m specifically looking for is something like:

{
  inputs = {
    tarball = {
      url = "https://some.tar.zst";
      flake = false;
      unpack = false;       # <--- disables the automatic unpacking of inputs
      name = "some.tar.zst" # <--- uses a proper name instead of /nix/store/...-source
    };
  };
  outputs = { self, tarball }: {
    # tarball now refers to the downloaded tarball in the nix store with the specified name like:
    # /nix/store/...-some.tar.zst
  }
}
1 Like

https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake

  • file: Plain files or directory tarballs, either over http(s) or from the local disk.In URL form, the schema must be file+http://, file+https:// or file+file://. If the extension doesn’t correspond to a known archive format (as defined by the tarball fetcher), then the file+ prefix can be dropped.

So in this case you want to avoid dropping the file+ before https:

inputs.tarball.url = "file+https://some.tar.zst";
2 Likes

Ah yes, I have this exact complaint also; it would be very helpful to see in the output which flake sources are being fetched. I’m half tempted to make the change as a part of Builtin fetching should be representable by derivations · Issue #9077 · NixOS/nix · GitHub

This would name the derivations according to the flake input name in your case it would be (-tarball-source) because your input is .input.tarball.

I think the underlying reason for the existing behaviour is that this fetchTree call isn’t passed a name attribute.

The downside is that a nix upgrade making this change would cause all existing flake builds (relying on a flake input) to become subsitution misses, since it changes the source inputs in the derivation.

1 Like