Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
acertain opened this issue Jun 3, 2015 · 15 comments
Open

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

acertain opened this issue Jun 3, 2015 · 15 comments

Comments

@acertain
Copy link
Contributor

acertain commented Jun 3, 2015

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.

@acertain acertain changed the title nixos-rebuild should use nix.* options when building nixpkgs nixos-rebuild should use nix.* options when building nixpkgs Jun 3, 2015
@wmertens
Copy link
Contributor

wmertens commented Jun 5, 2015

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
#2387.


Reply to this email directly or view it on GitHub
#8160.

@vcunat
Copy link
Member

vcunat commented Jun 5, 2015

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
Copy link
Contributor

wmertens commented Jun 5, 2015

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-rebuild_switch_ 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
#8160 (comment).

@vcunat
Copy link
Member

vcunat commented Jun 5, 2015

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

@dezgeg
Copy link
Contributor

dezgeg commented Aug 17, 2015

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
Copy link
Contributor

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
Copy link
Member

vcunat commented Aug 6, 2016

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
Copy link
Member

davidak commented Jun 14, 2017

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
Copy link
Contributor

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

@wmertens
Copy link
Contributor

wmertens commented Jul 26, 2017 via email

@stale
Copy link

stale bot commented Jun 5, 2020

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.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 5, 2020
@Artturin
Copy link
Member

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

echo "Validating generated nix.conf"
ln -s $out ./nix.conf
set -e
set +o pipefail
NIX_CONF_DIR=$PWD \
${cfg.package}/bin/nix show-config ${optionalString (isNixAtLeast "2.3pre") "--no-net"} \
${optionalString (isNixAtLeast "2.4pre") "--option experimental-features nix-command"} \
|& sed -e 's/^warning:/error:/' \
| (! grep '${if cfg.checkConfig then "^error:" else "^error: unknown setting"}')
set -o pipefail
'';

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 21, 2022
@wmertens
Copy link
Contributor

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
Copy link
Member

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

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 13, 2022
@physics-enthusiast
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants