nixos-rebuild-ng: validate NixOS configuration path#418243
nixos-rebuild-ng: validate NixOS configuration path#418243thiagokokada merged 5 commits intoNixOS:masterfrom
Conversation
|
@tejing1 I changed my opinion about validating the NixOS path. It is probably the only idea that will cover all cases (in #417191, you could still corrupt your system if you passed I will only validate the 2 destructive cases though to not complicate too much the code, that is either the |
|
Well, you already know I agree about going with validation. :-) Implementation looks fine, though I didn't go over it in great detail. Hopefully the escape hatch is unnecessary, but better to have it and not need it than to need it and not have it... |
When `path://` or `git+file://` protocol is used in Flake mode (that is the most common case since we normalize the paths, see PR NixOS#375493) and the current working directory in a symlink pointing base store path to the Nix store (e.g., /run/opengl-driver/lib), there is a nasty bug where Nix resolves the path as the Nix store path of the current derivation instead of the target derivation. Since we blindly activate this path, this can corrupt the installation and break some other activation scripts, like `systemd-boot-builder.py`. While it is possible to recover this situation using `nix-env -p /nix/var/nix/profiles/system --delete-generations old`, this is far from ideal. This commit solves it by validating that the resolved NixOS configuration path includes at least `$out/nixos-version`. I am not sure if this is going to break some cases so there is a escape hatch in the form of the environment variable `NIXOS_REBUILD_I_UNDERSTAND_THE_CONSEQUENCES_PLEASE_BREAK_MY_SYSTEM`, but in general it looks safe.
fdd55df to
e364976
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
@ofborg build nixos-rebuild-ng nixos-rebuild-ng.passthru.tests |
In NixOS#418243 we started to validate NixOS config path to avoid a nasty bug in Nix, but this doesn't work in the `--build-host` and `--target-host` case because the configuration will not be available in the local host to check if it contains a `nixos-version`. This moves the check to `--target-host` instead, that is probably the correct choice anyway. Fix NixOS#418868.
|
Successfully created backport PR for |
In #418243 we started to validate NixOS config path to avoid a nasty bug in Nix, but this doesn't work in the `--build-host` and `--target-host` case because the configuration will not be available in the local host to check if it contains a `nixos-version`. This moves the check to `--target-host` instead, that is probably the correct choice anyway. Fix #418868. (cherry picked from commit 0f6624e)
When
path://orgit+file://protocol is used in Flake mode (that is the most common case since we normalize the paths, see PR #375493) and the current working directory in a symlink pointing base store path to the Nix store (e.g., /run/opengl-driver/lib), there is a nasty bug where Nix resolves the path as the Nix store path of the current derivation instead of the target derivation.Since we blindly activate this path, this can corrupt the installation and break some other activation scripts, like
systemd-boot-builder.py. While it is possible to recover this situation usingnix-env -p /nix/var/nix/profiles/system --delete-generations old, this is far from ideal.This commit solves it by validating that the resolved NixOS configuration path includes at least
$out/nixos-version. I am not sure if this is going to break some cases so there is a escape hatch in the form of the environment variableNIXOS_REBUILD_I_UNDERSTAND_THE_CONSEQUENCES_PLEASE_BREAK_MY_SYSTEM, but in general it looks safe.Fix: #144811.
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.