2018-06-19 05:11:40 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2020-01-25 00:01:46 +03:00
|
|
|
inherit (lib) mkMerge mkIf mkOption types;
|
2018-06-19 05:11:40 +03:00
|
|
|
cfg = config.mobile.boot.stage-1.shell;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.mobile.boot.stage-1.shell = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enables a shell before switching root.
|
|
|
|
|
|
|
|
This shell (as currently configured) will not allow switching root.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
console = mkOption {
|
2019-09-13 05:23:13 +03:00
|
|
|
type = types.str;
|
2018-06-19 05:11:40 +03:00
|
|
|
default = "console";
|
|
|
|
description = ''
|
|
|
|
Selects the /dev/___ device to use.
|
|
|
|
|
|
|
|
Use `ttyS0` for serial, `tty1` for first VT or keep the default to `console`
|
|
|
|
for the last defined `console=` kernel parameter.
|
|
|
|
'';
|
|
|
|
};
|
2020-01-25 00:01:46 +03:00
|
|
|
|
|
|
|
shellOnFail = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enables a shell on failures.
|
|
|
|
'';
|
|
|
|
};
|
2018-06-19 05:11:40 +03:00
|
|
|
};
|
|
|
|
|
2020-01-25 00:01:46 +03:00
|
|
|
config.mobile.boot.stage-1 = mkMerge [
|
|
|
|
(mkIf (cfg.enable || cfg.shellOnFail) {
|
|
|
|
tasks = [
|
|
|
|
(pkgs.writeText "system-shell.rb" ''
|
|
|
|
module System
|
|
|
|
def self.shell()
|
2021-01-19 06:36:13 +03:00
|
|
|
# `cttyhack` ensures we get job control (^C, ^Z) going.
|
|
|
|
cmd = %q{setsid /bin/sh -c 'setsid cttyhack sh; exec ash -mi' < /dev/${cfg.console} >/dev/${cfg.console} 2>/dev/${cfg.console}}
|
2020-01-25 00:01:46 +03:00
|
|
|
$logger.debug(" $ #{cmd}")
|
|
|
|
puts("\nExit this shell (CTRL+D) to resume booting.\n")
|
|
|
|
system(cmd)
|
|
|
|
end
|
2019-12-25 08:37:55 +03:00
|
|
|
end
|
2020-01-25 00:01:46 +03:00
|
|
|
'')
|
|
|
|
];
|
|
|
|
})
|
|
|
|
(mkIf cfg.enable {
|
|
|
|
tasks = [
|
|
|
|
(pkgs.writeText "run-shell-task.rb" ''
|
|
|
|
class Tasks::RunShell < SingletonTask
|
|
|
|
def initialize()
|
|
|
|
# Wedge the task between the target "root", and the
|
|
|
|
# actual task we want to prevent running.
|
|
|
|
add_dependency(:Target, :SwitchRoot)
|
|
|
|
Tasks::SwitchRoot.instance.add_dependency(:Task, self)
|
|
|
|
end
|
2019-12-25 08:37:55 +03:00
|
|
|
|
2020-01-25 00:01:46 +03:00
|
|
|
def run()
|
|
|
|
System.shell()
|
|
|
|
end
|
2019-12-25 08:37:55 +03:00
|
|
|
end
|
2020-01-25 00:01:46 +03:00
|
|
|
'')
|
|
|
|
];
|
|
|
|
})
|
|
|
|
];
|
2018-06-19 05:11:40 +03:00
|
|
|
}
|