-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nixos/activation: Add pre-switch checks
Add an option for shell script fragments that are ran before switching to a new NixOS system configuration (pre installation of bootloader or system activation). Also add a new subcommand for switch-to-configuration called "check" that will cause the program to always exit after checks are ran.
- Loading branch information
Showing
7 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ lib, pkgs, ... }: | ||
let | ||
preSwitchCheckScript = | ||
set: | ||
lib.concatLines ( | ||
lib.mapAttrsToList (name: text: '' | ||
# pre-switch check ${name} | ||
( | ||
${text} | ||
) | ||
if [[ $? != 0 ]]; then | ||
echo "Pre-switch check '${name}' failed" | ||
exit 1 | ||
fi | ||
'') set | ||
); | ||
in | ||
{ | ||
options.system.preSwitchChecks = lib.mkOption { | ||
default = { }; | ||
example = lib.literalExpression '' | ||
{ failsEveryTime = | ||
''' | ||
false | ||
'''; | ||
} | ||
''; | ||
|
||
description = '' | ||
A set of shell script fragments that are executed before the switch to a | ||
new NixOS system configuration. A failure in any of these fragments will | ||
cause the switch to fail and exit early. | ||
''; | ||
|
||
type = lib.types.attrsOf lib.types.str; | ||
|
||
apply = | ||
set: | ||
set | ||
// { | ||
script = pkgs.writeShellScript "pre-switch-checks" (preSwitchCheckScript set); | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters