When building a recent nixpkgs version kernel with nixos-rebuild, nix build, and probably others, nix wants to recompile the kernel when we are currently in a nix-shell.
This seems to be related to the fact that these two packages get added to the derivation of the kernel:
ncurses-6.1-20181027pkg-config-0.29.2This doesn't happen for older kernel/nixpkgs combinations, specifically linux-4.14.76, nixpkgs rev 81f5c2698a8 (2018 Oct 17).
cc @tilpner, who was also able to reproduce this on irc.
Minimal failing example:
# Doesn't try to build kernel:
nixos-rebuild build
# Tries to rebuild kernel:
nix-shell -p [] --run "nixos-rebuild build"
"x86_64-linux"Linux 4.14.85, NixOS, 19.03pre161818.776f084cf1b (Koi)yesyesnix-env (Nix) 2.1.3"nixos-19.03pre161797.c26dbef830a""nixos-19.03pre158246.6141939d6e0"/nix/var/nix/profiles/per-user/root/channels/nixosIt's probably because of https://github.com/NixOS/nixpkgs/pull/47909 which adds some build inputs when in nix-shell.
Yes! Thank you! Reverting that exact (merge) commit in my local repo gives the expected behaviour:
$ nix-shell -p [] --run "nix build -f nixos system"
trace: Optimising i3-gaps
trace: Optimising ag
trace: Optimising htop
trace: Optimising netcat-gnu
[1/13/23 built, 0.0 MiB DL]
error: interrupted by the user
$ # Building kernel
$ git revert -m 1 c67ccd34c08fdb4e97c647c3fb09c1eb6e5431c6
[detached HEAD 9a59ea57b52] Revert "Merge pull request #47909 from teto/menuconfig"
1 file changed, 2 deletions(-)
$ nix-shell -p [] --run "nix build -f nixos system"
trace: Optimising i3-gaps
trace: Optimising ag
trace: Optimising htop
trace: Optimising netcat-gnu
[18 built, 0.0 MiB DL
$ # Not building kernel!
That still leaves open the question what to do with this problem.
nixos-rebuild could unset IN_NIX_SHELL
I'ts not just nixos-rebuild, it's also nix-build, nix build, nix-instantiate, and probably more
cc @teto @joachifm @yegortimoshenko
nix-shell is for development and debugging of a package, and should therefore resemble the actual build as close as possible. Automatically bringing in additional dependencies when developing is perhaps not such a good idea. Can't simply -p be used to bring in pkgconfig and ncurses?
Short-term answer is probably to revert. That said, it is very neat to have complete development shells like this. Maybe:
{
linuxShellFor = drv: drv.overrideAttrs (super: {
nativeBuildInputs = super.nativeBuildInputs ++ [ ncurses pkgconfig ];
});
}
Other than that, would really like to see shellInputs derivation attribute that is lazily evaluated in build context, and merged into nativeBuildInputs in shell context.
This is a consequence I realized was possible only after submitting my PR and it was merged by then already. As a short term fix, reverting may be the way to go. As someone who works quite often on the kernel source, or on packages, I believe default shellHooks could definitely be improved for a wide range of applications (https://github.com/NixOS/nixpkgs/pull/42864). So if we had a way to modify shellHooks that play nice with the rest of nix, that would be great.