mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-30 17:43:42 +00:00
6e192c4489
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.
45 lines
948 B
Nix
45 lines
948 B
Nix
{ 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);
|
|
};
|
|
};
|
|
}
|