initrd-shell: Allows using a shell on failure...
This needs to be plugged into the init via duck-typing.
{ config, lib, pkgs, ... }:
let
- inherit (lib) mkOption types;
+ inherit (lib) mkMerge mkIf mkOption types;
cfg = config.mobile.boot.stage-1.shell;
in
{
@@ -25,9 +25,32 @@ in
for the last defined `console=` kernel parameter.
'';
};
+
+ shellOnFail = mkOption {
+ type = types.bool;
+ default = false;
+ description = ''
+ Enables a shell on failures.
+ '';
+ };
};
- config.mobile.boot.stage-1 = lib.mkIf cfg.enable {
+ config.mobile.boot.stage-1 = mkMerge [
+ (mkIf (cfg.enable || cfg.shellOnFail) {
+ tasks = [
+ (pkgs.writeText "system-shell.rb" ''
+ module System
+ def self.shell()
+ cmd = %q{setsid /bin/sh -c /bin/sh < /dev/${cfg.console} >/dev/${cfg.console} 2>/dev/${cfg.console}}
+ $logger.debug(" $ #{cmd}")
+ puts("\nExit this shell (CTRL+D) to resume booting.\n")
+ system(cmd)
+ end
+ end
+ '')
+ ];
+ })
+ (mkIf cfg.enable {
tasks = [
(pkgs.writeText "run-shell-task.rb" ''
class Tasks::RunShell < SingletonTask
@@ -39,13 +62,11 @@ in
end
def run()
- cmd = %q{setsid /bin/sh -c /bin/sh < /dev/${cfg.console} >/dev/${cfg.console} 2>/dev/${cfg.console}}
- $logger.debug(" $ #{cmd}")
- puts("\nExit this shell (CTRL+D) to resume booting.\n")
- system(cmd)
+ System.shell()
end
end
'')
];
- };
+ })
+ ];
}
