From f61d7ea0b3556c9abf480a9863bd2f1fc48af843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Tue, 3 Jan 2023 23:12:23 +0100 Subject: [PATCH] nixos: add service to propagate status of activationScripts This change makes `systemctl --failed` indicate the result of the NixOS activation scripts, instead of making their failure only visible if you (1) manually look at system logs or (2) run the activation script manually. I'm re-using the existing /run/nixos directory for the (runtime) state. --- .../system/activation/activation-script.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nixos/modules/system/activation/activation-script.nix b/nixos/modules/system/activation/activation-script.nix index ddb165a76cc8e..9c7188c9d9cbf 100644 --- a/nixos/modules/system/activation/activation-script.nix +++ b/nixos/modules/system/activation/activation-script.nix @@ -59,6 +59,10 @@ let mkdir -p /nix/var/nix/gcroots ln -sfn /run/current-system /nix/var/nix/gcroots/current-system + # Write a state file for nixos-activation-scripts-status.service + mkdir -p /run/nixos/activation-scripts + echo "$_status" >/run/nixos/activation-scripts/exit_status + exit $_status ''; @@ -258,6 +262,17 @@ in source ${config.system.build.earlyMountScript} ''; + # A service that propagates the exit code of the activation scripts so that + # `systemctl --failed` shows if any of them failed. + systemd.services.nixos-activation-scripts-status = { + wantedBy = [ "multi-user.target" ]; + script = '' + exit_status="$(cat /run/nixos/activation-scripts/exit_status)" + echo "NixOS activation scripts finished with exit code $exit_status" + exit "$exit_status" + ''; + }; + systemd.user = { services.nixos-activation = { description = "Run user-specific NixOS activation";