NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.46k stars 13.66k forks source link

nixos-rebuild should use nix.* options when building nixpkgs #8160

Open acertain opened 9 years ago

acertain commented 9 years ago

Currently, nixos-rebuild puts them into /etc/nix/nix.conf for nix's next invocation. For most of the options, this is fine (if sub-optimal), but for the chroot options (buildUseChroot and chrootDirs) these options make another build of nixpkgs necessary (using --option for nixos-rebuild should work, but it didn't). This recently bit me in #2387.

wmertens commented 9 years ago

Yes I agree. Basically nixos-rebuild should first only update nix.conf (easiest is to overwrite the file during the run) and test that nix still works with that config before running the system build. Then it can revert the file before updating the system.

Even better of course would be providing the new config via an environment variable but I don't think that works via nix-daemon.

On Thu, Jun 4, 2015, 12:16 AM Carter Charbonneau notifications@github.com wrote:

Currently, nixos-rebuild puts them into /etc/nix/nix.conf for nix's next invocation. For most of the options, this is fine (if sub-optimal), but for the chroot options (buildUseChroot and chrootDirs) these options make another build of nixpkgs necessary (using --option for nixos-rebuild should work, but they didn't). This recently bit me in #2387 https://github.com/NixOS/nixpkgs/issues/2387.

— Reply to this email directly or view it on GitHub https://github.com/NixOS/nixpkgs/issues/8160.

vcunat commented 9 years ago

Nixos-rebuild certainly first builds new nix and then uses the result to evaluate the system (by default). That's fine. However, consider that nixos-rebuild build might be building system meant for a different machine, so many of nix.conf options might be plainly wrong. (It's not a typical case, I admit, perhaps except for nixops users.)

For nixos-rebuildswitch it would be safe, I think (and test/boot, too). We might add an option to force it with nixos-rebuild build as well, just as we have --no-build-nix.

wmertens commented 9 years ago

Thinking about it, it would probably be best to create a temporary profile with only the new nix config which gets removed after build. Then nix-daemon is configured correctly and it's easy to make the step optional for @vcunat's use case.

On Fri, Jun 5, 2015, 1:09 PM Vladimír Čunát notifications@github.com wrote:

Nixos-rebuild certainly first builds new nix and then uses the result to evaluate the system (by default). That's fine. However, consider that nixos-rebuild build might be building system meant for a different machine, so many of nix.conf options might be plainly wrong. (It's not a typical case, I admit, perhaps except for nixops users.)

For nixos-rebuildswitch it would be safe, I think (and test/boot, too). We might add an option to force it with nixos-rebuild build as well, just as we have --no-build-nix.

— Reply to this email directly or view it on GitHub https://github.com/NixOS/nixpkgs/issues/8160#issuecomment-109259522.

vcunat commented 9 years ago

The nix config gets generated as a part of the nixos build, so it needs to get into store anyway in the end.

dezgeg commented 9 years ago

A related thing that I got burned by today; specifically entering invalid stuff into nix.extraOptions:

Aug 17 22:31:09 kbuilder systemd[1]: Started Nix Daemon.
Aug 17 22:31:09 kbuilder nix-daemon[12307]: error: configuration option ‘build-cache-failure’ should be either ‘true’ or ‘false’, not ‘1’
Aug 17 22:31:09 kbuilder systemd[1]: nix-daemon.service: main process exited, code=exited, status=1/FAILURE
Aug 17 22:31:09 kbuilder systemd[1]: Unit nix-daemon.service entered failed state.
Aug 17 22:31:09 kbuilder systemd[1]: nix-daemon.service failed.

After this all/most nix commands stopped working, including nixos-rebuild. Though it's still not too hard to recover from this (the GRUB menu / running switch-to-configuration of old profile manually), it'd be nice to avoid that.

wmertens commented 8 years ago

This is still a problem. It's a minor problem but still annoying. In fact, it is two problems:

  1. You can make an invalid Nix config and it won't be detected. Major usability problem.
  2. Your nix store settings are ignored for your build. Sort of minor.

For 1, there needs to be a lint mode on nix. @edolstra would that be hard?

For 2, the workaround is to first build and use the nix config. Maybe nixos-rebuild could have a --nix-only switch? @vcunat would that be hard do you think?

vcunat commented 8 years ago

For 1, the config should be set by nix.* options in nixos config, which IMHO significantly lowers the possibility of making a mistake. Some real checking would be better, of course.

That work-around would have to be more complicated. IIRC our nix (daemon) reads config from /etc/nix/ directly, and you clearly don't want nixos-rebuild change that at that point.

davidak commented 7 years ago

I have the problem (2) right now: nixos-rebuild want's to rebuilt the kernel and i set nix.buildCores = 12; to speed that up. The nix-daemon option should get applied before other tasks.

cleverca22 commented 7 years ago

you can also nixos-rebuild --option build-cores 12 to temporarily override any option at runtime

wmertens commented 7 years ago

Actually, would it be possible to map the nix.* options to equivalent build cli options, and have a --no-map-nix-options flag for when that is not desired?

On Wed, Jun 14, 2017 at 6:22 PM Michael Bishop notifications@github.com wrote:

you can also nixos-rebuild --option build-cores 12 to temporarily override any option at runtime

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/NixOS/nixpkgs/issues/8160#issuecomment-308483791, or mute the thread https://github.com/notifications/unsubscribe-auth/AADWlhY3jojaWrt-Q0iaCscT4qW8ihEjks5sEAipgaJpZM4E3MWz .

stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
Artturin commented 2 years ago

This is still a problem. It's a minor problem but still annoying. In fact, it is two problems:

1. You can make an invalid Nix config and it won't be detected. Major usability problem.

the config is now validated

https://github.com/NixOS/nixpkgs/blob/bfb6f709c032169ea6fa20e2c4c8741a06d5e018/nixos/modules/services/misc/nix-daemon.nix#L67-L77

wmertens commented 2 years ago

Great!

Not sure what to do about problem 2) though. Maybe define a nix wrapper script that converts all configuration options that make sense into command line options, and then nixos-rebuild first builds that wrapper and uses it to build the system, just like it first builds Nix?

Artturin commented 2 years ago

in a flake only the config can be built like this nix build '.#nixosConfigurations.vm.config.environment.etc."nix/nix.conf".source' --print-out-paths --no-link

so we can use that in addition to https://nixos.org/manual/nix/stable/command-ref/env-common.html?highlight=NIX_CONFIG#common-environment-variables

to do

NIX_CONFIG=$(cat $(nix build '.#nixosConfigurations.vm.config.environment.etc."nix/nix.conf".source' --print-out-paths --no-link)) nix show-config
physics-enthusiast commented 6 months ago

Still relevant. Also affects "cross"-compilation via binfmt emulation (due to this line) in situations where boot.binfmt.emulatedSystems is set at the same time as the packages to be built are first introduced without having to do an intermediate rebuild (e.g. for declarative cross-arch VMs).