Is there a way to override a flake input and record which version was used?

I’d like to compile a staging-next version of nixpkgs and record the commit ID it actually used. Regular

nix build ~/.config/home-manager --override-input nixpkgs github:NixOS/nixpkgs/staging-next

does print out the commit it used to the terminal, but this stopped working great for me after I started using GitHub - maralorn/nix-output-monitor: Pipe your nix-build output through the nix-output-monitor a.k.a nom to get additional information while building. (which prints a ton of text to the terminal, so the commit id usually leaves the terminal history). It doesn’t record the lock file (as expected).

I tried something like:

nix build ~/.config/home-manager --override-input nixpkgs github:NixOS/nixpkgs/staging-next --output-lock-file ~/.config/home-manager/flake-temp.lock 

but that doesn’t write any lock file, it seems that the implicit --no-write-lockfile overrides --output-lock-file. is this a bug/missing feature?

Is there a good alternative to record the commit id being used or to find it out in retrospect?

`--override-input` does not affect `flake.lock` in `self.outPath` · Issue #6894 · NixOS/nix · GitHub seems related, but it suggests “no” as the answer.

I currently use the following to record my inputs:

I’ve since added builtins.unsafeDiscardStringContext in front of input.outPath to not force nix to download unused flake inputs.

nix flake lock --override-input nixpkgs github:NixOS/nixpkgs/staging-next --output-lock-file ~/.config/home-manager/flake-temp.lock does seem to work.

2 Likes

Indeed! This suggests even stronger that it not working for build (or nh home switch with nh 4 beta in my case) is a bug.