Commit Graph

425 Commits

Author SHA1 Message Date
Doron Behar
bade7e638e nixos/top-level: drop legacy systemBuilderArgs.perl
This makes it possible to build a system without Perl at all.

The actual original consumer of this perl environment was
`nixos/modules/system/activation/switch-to-configuration.pl`, which was
deleted in c59d4343f9, (replaced by Rust
switch-to-configuration-ng). That commit did not touch `top-level.nix`
or `activatable-system.nix`, so this Perl environment was left behind
even though its original (and, as far as I could trace, only) in-tree
consumer was gone.

Any out-of-tree/third-party activation script that happens to read this
`perl` variable will break but can be easily fixed by simply
reintroducing the deleted assignment. Nixpkgs doesn't have any such
consumers so it seems.
2026-08-15 23:56:03 +03:00
K900
1fdf8fd586 bootspec: honor boot.kernel.enable
WSL and other container-brained-but-not-really systems may not want a kernel,
and now that bootspec is no longer optional, this pulls one in anyway.
2026-06-11 15:38:11 +03:00
Arian van Putten
f9335936bc nixos/bootspec: remove enable option (#530066) 2026-06-10 19:34:34 +00:00
Emily
31d1d80b3f lib/systems: move kernel configuration out of the platform structure
Currently, you need to override `stdenv.hostPlatform` to request a
compressed kernel on AArch64, and the kernel configuration is split
between the central structured configuration and string snippets in
platform definitions. This has consequently made the latter bitrot
terribly. Since the platform‐specific logic is now very limited after
cleaning up the detritus, we can move it into the kernel derivation
and expose the relevant configuration there for anyone who wants to
customize it further or needs to read it out.

Co-authored-by: zowoq <59103226+zowoq@users.noreply.github.com>
2026-06-10 11:17:38 +10:00
r-vdp
c44bf2a69d nixos/bootspec: remove enable option
Bootspec has been enabled by default and marked internal for a long
time.

Dropping this option avoids us needing fallbacks in bootloader scripts.
2026-06-09 21:45:54 +03:00
r-vdp
69dc41f083 nixos/preSwitchChecks: actually set errexit inside check bodies
The previous `if ! ( ... )` wrapper put the check body in a context
where bash ignores `set -e`, so a failing command in the middle of a
check would not abort it and the switch would proceed. Run the
subshell outside any conditional and capture $? explicitly instead.
2026-06-04 02:18:34 +03:00
r-vdp
663a59e0b6 nixos/activation: run user nixos-activation.service exactly once per switch
stc-ng starts every active target (including default.target) and then
explicitly restarts nixos-activation.service. As a Type=oneshot without
RemainAfterExit the unit is inactive after login, so the default.target
start job re-runs it via Wants=, and the explicit restart runs it again
(or, depending on ordering, SIGTERMs the currently running script and re-runs it).

Set RemainAfterExit=yes so target starts are a no-op for an already-run
activation, and restartIfChanged=false so the unit-diff pass leaves it
alone when the script changes. The explicit restart in stc-ng remains
the single trigger per switch. Print that restart so it is visible in
the switch output, and drop it from the "NOT restarting" list.

Extend the user-activation-scripts test to assert the activation is
only run once, and never killed.
2026-05-23 12:50:40 +02:00
André Lima
a8ec955f87 nixos/system/activation: write all extra dependencies with structuredAttrs
Assisted-by: Codex GPT 5.4 <noreply@openai.com>
2026-05-19 01:51:45 +01:00
K900
877385b045 Merge remote-tracking branch 'origin/master' into staging-next 2026-05-18 16:19:13 +03:00
Alyssa Ross
9488f36f15 nixos/i18n: fix eval for non-glibc systems (e.g. musl) (#514825) 2026-05-18 09:42:55 +00:00
Colin
cce4239d68 nixos/i18n: fix eval for non-glibc systems (e.g. musl)
`pkgs.glibcLocales` is null for musl systems, so
`options.i18n.glibcLocales` needs to also be nullable.
otherwise, the `.override` and subsequence path interpolations
fail for non-gnu systems.
2026-05-07 17:35:58 +00:00
K900
cd9a5eeafb Merge remote-tracking branch 'origin/staging-next' into staging 2026-05-04 21:37:41 +03:00
Michael Daniels
2e87c2f8f4 nixos/*: remove unused let bindings
Generated using deadnix (with some manual work); split from #514611.
2026-05-01 20:39:14 -04:00
nixpkgs-ci[bot]
dec7ed05b0 Merge staging-next into staging 2026-04-21 12:24:17 +00:00
r-vdp
49c05db108 nixos/switchable-system: improve switch-inhibitor pre-check
The check ran `realpath /run/current-system` under errexit, so a
missing current-system symlink aborted the script.
Drop the realpath calls (the -f test and jq already follow symlinks)
and use a static store path for the empty fallback instead of mktemp/trap.

Also exempt dry-activate, which makes no state changes and was being
blocked from showing its diff, and let jq fail loudly on malformed
inhibitor JSON instead of silently treating it as empty.
2026-04-16 10:50:02 +02:00
Jo
f35405eb12 nixos/system/activation: use structuredAttrs instead of passAsFile (#498925) 2026-04-15 14:35:39 +00:00
Will Fancher
f8ed5f30c0 nixos/filesystems: Remove default = "auto" from fsType
NixOS has traditionally enabled the `ext` family of file systems by
default. Originally, when switching to systemd initrd, we wanted to
transition to making this explicit so that initrds could be made
without `ext`. The problem is that anyone with `fsType = "auto";` for
an `ext` file system in initrd will fail to boot, which is not really
an acceptable regression as we switch to systemd initrd by default.

By removing `default = "auto"` from `fsType`, we rule out the vast
majority of these regressions as eval errors, since most users of
`fsType = "auto"` for ext file systems are using it because of the
default value.

In hindsight, this is probably what #225352 was really about.
2026-04-05 19:06:28 -04:00
Stefan Frijters
d7a461100a nixos/system/activation: use structuredAttrs instead of passAsFile 2026-03-22 12:58:16 +01:00
Vladimír Čunát
d6acf1b543 Revert "nixos/initrd: refactor secrets option into secretPaths and extraSecretsHook" 2026-03-21 15:58:52 +01:00
cyclopentane
72e4df576e nixos/initrd: add secretPaths and extraSecretsHook 2026-02-24 21:38:40 +01:00
r-vdp
34fd3fe6a2 nixos/power-management: run postBootCommands in a systemd service instead of stage2-init.sh
This reduces our initrd script slightly, and we never made any clear
ordering guarantees about when these commands run anyway.
It also removes this as a blocker for nixos-init.
2026-02-08 23:49:17 +02:00
r-vdp
b5bb5d22da nixos-init: read the required paths from a file in the toplevel instead of from the environment
This is a first step towards using nixos-init also during re-activation.
2026-01-26 11:54:07 +01:00
nixpkgs-ci[bot]
d172ccd368 Merge master into staging-nixos 2026-01-20 18:09:17 +00:00
jopejoe1
97f925962d nixosTests.activation-lib: don't use fileset 2026-01-19 12:21:00 +01:00
jopejoe1
ffc9c1bd48 nixosTests.activation.test-forbiddenDependencies-{fail,succeed}: set stateVersion 2026-01-19 12:19:26 +01:00
Ramses
f74cde140d nixos/activation: prefer local builds for activation script (#480993) 2026-01-19 09:18:29 +00:00
Arian van Putten
ef696c6a60 nixos/switchable-system: improve switch inhibitors (#477800) 2026-01-18 20:46:53 +00:00
Norbert Melzer
c68bd3a944 nixos/activation: prefer local build
FIX #479747
2026-01-17 12:20:13 +01:00
r-vdp
3408d1a4a9 nixos/switchable-system: improve switch inhibitors
Improvements:
1. Turn the nix value into an attrset so that every inhibitor has a name
   that we can match between generations
2. Write the attrset to a file as JSON
3. When checking, we load the JSON files from both the current and the
   new generation into a jq pipeline and match up the keys.
   We output a dict with a value for every key that is present in both
   generations with a different value.
4. Build in error handling for different corner cases (missing files,
   non-JSON content)
2026-01-09 11:59:26 +02:00
nikstur
7f49ae6543 nixos/nixos-init: conflict with postBootCommands and powerUpCommands (#474454) 2026-01-08 22:36:36 +00:00
Majiir Paktu
e656d186b2 nixos/nixos-init: conflict with postBootCommands and powerUpCommands 2026-01-06 21:00:36 -05:00
nixpkgs-ci[bot]
a9db0efa12 Merge master into staging-nixos 2026-01-07 00:18:45 +00:00
r-vdp
a998d196ab nixos/switchable-system: only include the switch-inhibitors check when we have inhibitors 2026-01-06 23:50:10 +02:00
r-vdp
2c3ee7a8f3 nixos/switchable-system: improve error message in case switch inhibitors changed 2026-01-05 12:19:07 +02:00
Thiago Kenji Okada
a55bb24b49 nixos-rebuild-ng: pass the NIXOS_NO_CHECK variable through the systemd-run and sudo invocations (#475295) 2026-01-04 12:46:35 +00:00
Colin
eae4139c54 nixos/activation: use the builder's sed
9bfd0d688d changed this line from
`substituteInPlace` to `sed`, but in the case of cross compilation
that would use the host's `sed`, which isn't necessarily executable by
the build machine.
2026-01-02 22:53:30 +00:00
r-vdp
15dc91ff95 nixos-rebuild-ng: pass the NIXOS_NO_CHECK variable through the systemd-run and sudo invocations
This allows to skip nixos pre-switch check when running switch-to-configuration.
2025-12-30 16:40:24 +02:00
Ramses
bbc8ebac5a nixos/activation: avoid build failure with large activation script (#474379) 2025-12-28 23:53:41 +00:00
r-vdp
9bfd0d688d nixos/activation: avoid build failure with large activation script
Two improvements:
* use `writeShellApplication` (which uses `passAsFile` instead of
  passing the activation script as an env var into the derivation.
  We disable shellcheck and the bash options that this builder
  usually adds to avoid issues with out-of-tree activation scripts.
* use `sed` instead of `substituteInPlace`, since the substitute
  functions load the file content into a shell variable

This avoids issues when the activation is too long to fit in a shell variable.
Before this commit, a very large activation script, would cause build
failures because of different limits on the file content size, e.g.
```
➜ nix build -f . nixosTests.restartByActivationScript.nodes.machine.system.build.toplevel -vL
this derivation will be built:
  /nix/store/xw6anpfjyamnycjg58cmj01sz3ididyl-nixos-system-machine-test.drv
building '/nix/store/xw6anpfjyamnycjg58cmj01sz3ididyl-nixos-system-machine-test.drv'...
nixos-system-machine-test> error: executing '/nix/store/rlq03x4cwf8zn73hxaxnx0zn5q9kifls-bash-5.3p3/bin/bash': Argument list too long
error: builder for '/nix/store/xw6anpfjyamnycjg58cmj01sz3ididyl-nixos-system-machine-test.drv' failed with exit code 1;
       last 1 log lines:
       > error: executing '/nix/store/rlq03x4cwf8zn73hxaxnx0zn5q9kifls-bash-5.3p3/bin/bash': Argument list too long
       For full logs, run:
        nix log /nix/store/xw6anpfjyamnycjg58cmj01sz3ididyl-nixos-system-machine-test.drv
```
2025-12-28 01:41:12 +02:00
r-vdp
93cda47a1f nixos/switchable-system: introduce a standard pre-switch check to prevent switching under certain conditions
This commit introduces "switch inhibitors" which are derivations that
prevent a switch of a system to a new configuration if those derivations
don't have the same hash in both configurations.
This means that we can for instance add the systemd and dbus derivations
such that users will be instructed to reboot their system when those
derivations have changed instead of switching.

This feature should be used sparingly, but it can make NixOS more robust
by avoiding users switching to a configuration that can make their
system unstable (like major updates of systemd, or new versions of dbus
since the dbus and dbus-broker daemons cannot be restarted).

The user can still force the switch by setting an env var.
2025-12-25 12:02:34 +02:00
r-vdp
e16bd36ed6 nixos/activation: avoid generating empty activation scripts 2025-11-24 16:08:04 -03:00
Robert Hensing
41b98b4a8a nixos: Shuffle definitions and deprecate system.extraSystemBuilderCmds
Shuffle:
The definitions are now combined into a single option. Since they have
no interdependencies, that's ok, but you may notice this trivial change
by a changed hash, and analyzing with nix-diff.

Deprecation:
Use the option `system.systemBuilderCommands` instead.
2025-11-12 21:00:32 +01:00
Emily
7f9a83be1f nixos/nixos-init: add more strict assertions for required config (#450775) 2025-10-12 15:15:13 +00:00
nikstur
8f5d10fd7e nixos/nixos-init: add more strict assertions for required config 2025-10-12 16:55:23 +02:00
nikstur
26cf6ffe54 nixos/top-level: only include preSwitchChecks when they are set 2025-10-09 23:52:38 +02:00
Wolfgang Walther
91a8fee3aa treewide: remove redundant parentheses
Auto-fixed by nixf-diagnose.
2025-10-05 10:52:03 +02:00
misuzu
e7fa9ff16c nixos-init: init at 0.1.0 (#433154) 2025-09-23 12:48:56 +00:00
nikstur
d0c03e4c5a nixos-init: init at 0.1.0 2025-09-23 00:21:33 +02:00
Val Packett
313fa9dc99 nixos/top-level: fix cutoffPackages without initialRamdisk
In systems without initrd (e.g. containers) that also use system.replaceDependencies, we'd get:

error: attribute 'initialRamdisk' missing
at /nix/store/8vfhnwmmzqqzy97q9c5m4bzyaqqf63zy-source/nixos/modules/system/activation/top-level.nix:286:21:
   285|       cutoffPackages = mkOption {
   286|         default = [ config.system.build.initialRamdisk ];
      |                     ^

Make that initialRamdisk reference conditional on the initrd being enabled.
2025-09-18 18:59:45 -03:00
Will Fancher
6b5020dc9c nixos/top-level: Install 'bootStage2' as 'init' in all non-initrd configs
Eventually we'd like to change our posture on this, and somehow ensure
that 'init' is always our systemd binary, but for now containers
require us to do it this way.
2025-09-10 09:45:48 -04:00