This a learning process, with many an insight on the way!
So, first of all: not keeping Nix source bundles (such as a specific Nixpkgs revision obtained by fetchTarball
, etc.) is not a bug. Nix source is just not considered a reference for whatever results from evaluating it – otherwise you’d hold on to every channel state on your system.
Secondly, now that we know what the actual problem is (till next bout of enlightenment), the solution is along those lines:
{ nixpkgs ? (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/<revision>.tar.gz";
sha256 = "<whatever that is>";
}),
... }:
let
pkgs = import nixpkgs {};
...
in stdenv.mkDerivation {
NIXPKGS_SRC = "${nixpkgs}";
# rest of the owl
...
}
The idea being: give a name to the fixed-output derivation of the source bundle itself (not just the result of importing it, as is the usual pattern), and store its path in a derivation artifact (like an environment variable, as in this example). This way the bundle is recorded as a reference of the derivation, and will stay alive as long as the derivation itself is.