Knowing in advance what nixos-rebuild will do

The nixos-rebuild command gives no visibility into what it’s going to do, namely:

  • what packages will be downloaded, and how large they are
  • what packages will be built
  • why those packages couldn’t be downloaded from a cache

Of these 3, the first 2 seem related, and possibly easier to solve. Are we in a situation where most of the functionality to get those 2 is already in place, and we just need someone to wire things up?

Or is it a larger task that would require lots of effort?

As to the 3rd, I can imagine it’s quite hard, since I imagine that the nix tool has no way of knowing which piece of code has caused a cache miss. Or am I wrong?

This is covered by nixos-rebuild dry-build.

Obviously because the derivation hash changed compared to what is cached.


Thanks, that’s handy! I think it would be nice if the tool would show that list by default, maybe summarized somehow, while also displaying the indivudual and total size of the download.

Yes, that’s the obvious part. What I was asking is more “can we deduce which specific piece of config caused the hash to change”. Often I find myself looking for the culprit across flake.nix, HM config, overlays…

No, unfortunately we cannot. When Nix runs it executes all the expressions to instantiate derivations, whose hash is then used to query the binary cache. At the point where the derivation is instantiated all of the context where it came from is lost. You can check this for yourself by having a look at the JSON serialization of the derivation contents, e.g.

$ nix show-derivation "$(nix-instantiate '<nixpkgs>' -A hello)"
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
  "/nix/store/90jjw94xiyg5drj70whm9yll6xjj0ca9-hello-2.10.drv": {
    "outputs": {
      "out": {
        "path": "/nix/store/fjc71ycmr5fnfxyfgwi2dwh323z12gvq-hello-2.10"
    "inputSrcs": [
    "inputDrvs": {
      "/nix/store/cy27ypqr3ipxsvjl1mni2xcyf62rgvwj-stdenv-linux.drv": [
      "/nix/store/q4dcb46srn8ykn02wjqp1gdxvwcfaw2i-hello-2.10.tar.gz.drv": [
      "/nix/store/xa4b7dfdsnig7n6glm696wmqad0zvybj-bash-4.4-p23.drv": [
    "system": "x86_64-linux",
    "builder": "/nix/store/xvvgw9sb8wk6d2c0j3ybn7sll67s3s4z-bash-4.4-p23/bin/bash",
    "args": [
    "env": {
      "buildInputs": "",
      "builder": "/nix/store/xvvgw9sb8wk6d2c0j3ybn7sll67s3s4z-bash-4.4-p23/bin/bash",
      "configureFlags": "",
      "depsBuildBuild": "",
      "depsBuildBuildPropagated": "",
      "depsBuildTarget": "",
      "depsBuildTargetPropagated": "",
      "depsHostHost": "",
      "depsHostHostPropagated": "",
      "depsTargetTarget": "",
      "depsTargetTargetPropagated": "",
      "doCheck": "1",
      "doInstallCheck": "",
      "name": "hello-2.10",
      "nativeBuildInputs": "",
      "out": "/nix/store/fjc71ycmr5fnfxyfgwi2dwh323z12gvq-hello-2.10",
      "outputs": "out",
      "patches": "",
      "pname": "hello",
      "propagatedBuildInputs": "",
      "propagatedNativeBuildInputs": "",
      "src": "/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz",
      "stdenv": "/nix/store/7gdji02y6rbnzv5mcxcf3mwksk785y8j-stdenv-linux",
      "strictDeps": "",
      "system": "x86_64-linux",
      "version": "2.10"

As you can see there is absolutely no reference to pkgs/applications/misc/hello/default.nix or anything similar left.

The hash of the outPath is used to query the binary cache:

$ curl
StorePath: /nix/store/fjc71ycmr5fnfxyfgwi2dwh323z12gvq-hello-2.10
URL: nar/0nb8qh3ihhls6jh2kgdl1jlkrzrf0w1advrr31s5dfy8pmmkirr4.nar.xz
Compression: xz
FileHash: sha256:0nb8qh3ihhls6jh2kgdl1jlkrzrf0w1advrr31s5dfy8pmmkirr4
FileSize: 41096
NarHash: sha256:17fcqinwrvgb2ybws0rlxg73zc4i61ps7pd5bs9p6wv2rn9nvd67
NarSize: 206000
References: fjc71ycmr5fnfxyfgwi2dwh323z12gvq-hello-2.10 gk42f59363p82rg2wv2mfy71jn5w4q4c-glibc-2.32-48
Deriver: 90jjw94xiyg5drj70whm9yll6xjj0ca9-hello-2.10.drv