2024-06-07 07:24:48 +00:00
|
|
|
{ lib
|
2024-06-09 17:48:46 +00:00
|
|
|
, linux ? linux_6_1, linux_6_1
|
2024-06-07 07:24:48 +00:00
|
|
|
, linuxManualConfig
|
2024-06-09 18:40:38 +00:00
|
|
|
, optimizeForSize ? false
|
2024-06-09 19:34:07 +00:00
|
|
|
, sane-kernel-tools
|
2024-06-07 07:24:48 +00:00
|
|
|
, writeTextFile
|
|
|
|
#v nixpkgs calls `.override` on the kernel to configure additional things
|
|
|
|
, features ? []
|
|
|
|
, randstructSeed ? ""
|
|
|
|
, ...
|
|
|
|
}@args:
|
|
|
|
|
|
|
|
let
|
2024-06-09 19:34:07 +00:00
|
|
|
defconfigPmos = builtins.readFile ./config-postmarketos-exynos5.arm7;
|
2024-06-09 18:40:38 +00:00
|
|
|
|
2024-06-07 07:24:48 +00:00
|
|
|
# remove CONFIG_LOCALVERSION else nixpkgs complains about mismatched modDirVersion
|
2024-06-09 19:34:07 +00:00
|
|
|
withoutOsFlavor = defconfig: lib.replaceStrings
|
2024-06-09 18:40:38 +00:00
|
|
|
[ ''CONFIG_LOCALVERSION="-postmarketos-exynos5"'' ]
|
|
|
|
[ ''CONFIG_LOCALVERSION='' ]
|
2024-06-09 19:34:07 +00:00
|
|
|
defconfig
|
2024-06-09 18:40:38 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
# XXX(2024/06/06): if this module is loaded before udev, then kernel panic.
|
|
|
|
# see: <repo:NixOS/mobile-nixos:devices/families/mainline-chromeos/default.nix>
|
2024-06-09 19:34:07 +00:00
|
|
|
withModuleFixes = defconfig: lib.replaceStrings
|
2024-06-09 18:40:38 +00:00
|
|
|
[ ''CONFIG_BATTERY_SBS=y'' ]
|
|
|
|
[ ''CONFIG_BATTERY_SBS=m'' ]
|
2024-06-09 19:34:07 +00:00
|
|
|
defconfig
|
2024-06-09 18:40:38 +00:00
|
|
|
;
|
|
|
|
|
2024-06-09 19:34:07 +00:00
|
|
|
withOptimizations = defconfig: if optimizeForSize then
|
2024-06-09 18:40:38 +00:00
|
|
|
lib.replaceStrings
|
|
|
|
[ ''CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y'' ]
|
2024-06-07 07:24:48 +00:00
|
|
|
# XXX(2024/06/06): if the bzImage is too large, it fails to boot.
|
|
|
|
# probably an issue with the uboot relocations; not sure exactly what the size limit is.
|
2024-06-09 07:00:26 +00:00
|
|
|
# XXX(2024/06/08): it now boots fine with the stock optimizations, though the difference in size is only 500KiB (about 10%).
|
|
|
|
# perhaps this was mis-diagnosed
|
2024-06-09 18:40:38 +00:00
|
|
|
[ ''CONFIG_CC_OPTIMIZE_FOR_SIZE=y'' ]
|
2024-06-09 19:34:07 +00:00
|
|
|
defconfig
|
2024-06-09 18:40:38 +00:00
|
|
|
else
|
2024-06-09 19:34:07 +00:00
|
|
|
defconfig
|
2024-06-09 18:40:38 +00:00
|
|
|
;
|
|
|
|
|
2024-06-09 19:34:07 +00:00
|
|
|
withNixosRequirements = defconfig: defconfig + ''
|
2024-06-07 07:24:48 +00:00
|
|
|
#
|
|
|
|
# Extra nixpkgs-specific options
|
|
|
|
# nixos/modules/system/boot/systemd.nix wants CONFIG_DMIID
|
|
|
|
#
|
|
|
|
CONFIG_DMIID=y
|
|
|
|
|
|
|
|
#
|
|
|
|
# Extra sane-specific options
|
|
|
|
#
|
|
|
|
CONFIG_SECURITY_LANDLOCK=y
|
|
|
|
CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,selinux,smack,tomoyo,apparmor,bpf";
|
|
|
|
'';
|
2024-06-09 18:40:38 +00:00
|
|
|
|
2024-06-09 19:34:07 +00:00
|
|
|
defconfigStr = withNixosRequirements (
|
2024-06-09 18:40:38 +00:00
|
|
|
withOptimizations (
|
|
|
|
withModuleFixes (
|
|
|
|
withoutOsFlavor (
|
2024-06-09 19:34:07 +00:00
|
|
|
defconfigPmos
|
2024-06-09 18:40:38 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2024-06-07 07:24:48 +00:00
|
|
|
in linuxManualConfig {
|
2024-06-09 17:48:46 +00:00
|
|
|
inherit (linux) extraMakeFlags modDirVersion src version;
|
2024-06-07 07:24:48 +00:00
|
|
|
inherit features randstructSeed;
|
|
|
|
kernelPatches = args.kernelPatches or [];
|
|
|
|
|
|
|
|
configfile = writeTextFile {
|
|
|
|
name = "config-postmarketos-exynos5.arm7";
|
2024-06-09 19:34:07 +00:00
|
|
|
text = defconfigStr;
|
2024-06-07 07:24:48 +00:00
|
|
|
};
|
|
|
|
# nixpkgs requires to know the config as an attrset, to do various eval-time assertions.
|
2024-06-09 19:34:07 +00:00
|
|
|
# this forces me to include the defconfig inline, instead of fetching it the way i do all the other pmOS kernel stuff.
|
|
|
|
config = sane-kernel-tools.parseDefconfig defconfigStr;
|
2024-06-07 07:24:48 +00:00
|
|
|
}
|