2020-05-24 23:15:47 +03:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2018-06-24 00:45:51 +03:00
|
|
|
|
|
|
|
let
|
2020-05-24 23:15:47 +03:00
|
|
|
|
|
|
|
inherit (lib)
|
|
|
|
mergeEqualOption
|
2020-12-15 07:58:45 +03:00
|
|
|
mkDefault
|
2020-05-24 23:15:47 +03:00
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
types
|
|
|
|
;
|
2018-06-24 00:45:51 +03:00
|
|
|
cfg = config.mobile.boot.stage-1.kernel;
|
|
|
|
device_config = config.mobile.device;
|
|
|
|
|
|
|
|
modulesClosure = pkgs.makeModulesClosure {
|
2020-05-24 23:15:47 +03:00
|
|
|
kernel = cfg.package;
|
2018-06-24 00:45:51 +03:00
|
|
|
allowMissing = true;
|
2020-05-24 22:41:27 +03:00
|
|
|
rootModules = cfg.modules ++ cfg.additionalModules;
|
2018-06-24 00:45:51 +03:00
|
|
|
firmware = cfg.firmwares;
|
|
|
|
};
|
2020-12-19 05:42:30 +03:00
|
|
|
|
|
|
|
inherit (config.mobile.quirks) supportsStage-0;
|
2018-06-24 00:45:51 +03:00
|
|
|
in
|
|
|
|
{
|
2020-05-24 22:41:27 +03:00
|
|
|
# Note: These options are provided *instead* of `boot.initrd.*`, as we are
|
|
|
|
# not re-using the `initrd` options.
|
2018-06-24 00:45:51 +03:00
|
|
|
options.mobile.boot.stage-1.kernel = {
|
|
|
|
modular = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether the kernel is built with modules or not.
|
|
|
|
This will enable modules closure generation and listing modules
|
|
|
|
to bundle and load.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
modules = mkOption {
|
2019-09-13 05:23:13 +03:00
|
|
|
type = types.listOf types.str;
|
2018-06-24 00:45:51 +03:00
|
|
|
default = [
|
|
|
|
];
|
|
|
|
description = ''
|
|
|
|
Module names to add to the closure.
|
|
|
|
They will be modprobed.
|
|
|
|
'';
|
|
|
|
};
|
2020-05-24 22:41:27 +03:00
|
|
|
additionalModules = mkOption {
|
2019-09-13 05:23:13 +03:00
|
|
|
type = types.listOf types.str;
|
2018-06-24 00:45:51 +03:00
|
|
|
default = [
|
|
|
|
];
|
|
|
|
description = ''
|
|
|
|
Module names to add to the closure.
|
|
|
|
They will not be modprobed.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
firmwares = mkOption {
|
2019-09-13 05:23:13 +03:00
|
|
|
type = types.listOf types.str;
|
2018-06-24 00:45:51 +03:00
|
|
|
default = [];
|
|
|
|
description = ''
|
2020-10-14 00:23:24 +03:00
|
|
|
Firmwares to add to the closure.
|
2018-06-24 00:45:51 +03:00
|
|
|
'';
|
|
|
|
};
|
2020-05-24 23:15:47 +03:00
|
|
|
# We cannot use `linuxPackagesFor` as older kernels cause eval-time assertions...
|
|
|
|
# This is bad form, but is already in nixpkgs :(.
|
|
|
|
package = mkOption {
|
2020-12-18 02:35:19 +03:00
|
|
|
type = types.nullOr types.package;
|
|
|
|
default = null;
|
2020-05-24 23:15:47 +03:00
|
|
|
description = ''
|
|
|
|
Kernel to be used by the system-type to boot into the Mobile NixOS
|
|
|
|
stage-1.
|
|
|
|
|
|
|
|
This is not using a kernelPackages attrset, but a kernel derivation directly.
|
|
|
|
'';
|
|
|
|
};
|
2018-06-24 00:45:51 +03:00
|
|
|
};
|
|
|
|
|
2020-05-24 23:15:47 +03:00
|
|
|
config.mobile.boot.stage-1 = (mkIf cfg.modular {
|
2020-07-06 07:18:47 +03:00
|
|
|
firmware = [ modulesClosure ];
|
2019-12-23 22:05:17 +03:00
|
|
|
contents = [
|
|
|
|
{ object = "${modulesClosure}/lib/modules"; symlink = "/lib/modules"; }
|
|
|
|
];
|
2018-06-24 00:45:51 +03:00
|
|
|
kernel.modules = [
|
|
|
|
# Basic always-needed kernel modules.
|
|
|
|
"loop"
|
|
|
|
|
|
|
|
# Filesystems
|
|
|
|
"nls_cp437"
|
|
|
|
"nls_iso8859-1"
|
|
|
|
"fat"
|
|
|
|
"vfat"
|
|
|
|
|
|
|
|
"ext4"
|
|
|
|
"crc32c"
|
|
|
|
];
|
2020-05-24 23:15:47 +03:00
|
|
|
});
|
2020-12-15 07:58:45 +03:00
|
|
|
|
|
|
|
config.boot.kernelPackages = mkDefault (
|
2020-12-19 05:42:30 +03:00
|
|
|
if (supportsStage-0 && config.mobile.rootfs.shared.enabled) || cfg.package == null
|
2020-12-15 07:58:45 +03:00
|
|
|
then {
|
|
|
|
# This must look legit enough so that NixOS thinks it's a kernel attrset.
|
|
|
|
stdenv = pkgs.stdenv;
|
|
|
|
kernel = pkgs.runCommandNoCC "dummy" { version = "99"; } "mkdir $out; touch $out/dummy";
|
|
|
|
}
|
2020-12-19 05:42:30 +03:00
|
|
|
else (pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor cfg.package))
|
2020-12-15 07:58:45 +03:00
|
|
|
);
|
2020-12-15 08:02:44 +03:00
|
|
|
|
|
|
|
# Disable kernel config checks as it's EXTREMELY nixpkgs-kernel centric.
|
|
|
|
# We're duplicating that good work for the time being.
|
|
|
|
config.system.requiredKernelConfig = lib.mkForce [];
|
2018-06-24 00:45:51 +03:00
|
|
|
}
|
|
|
|
|