nix-files/pkgs/additional/linux-postmarketos-exynos5/default.nix

101 lines
3.2 KiB
Nix
Raw Normal View History

{ lib
, linux ? linux_6_1, linux_6_1
, linuxManualConfig
, optimizeForSize ? false
, writeTextFile
#v nixpkgs calls `.override` on the kernel to configure additional things
, features ? []
, randstructSeed ? ""
, ...
}@args:
let
# TODO: lift to shared module
parseKconfigLine = line: let
pieces = lib.splitString "=" line;
in
if lib.hasPrefix "#" (lib.head pieces) then [
# this line is a comment.
# N.B.: this could be like `# CONFIG_FOO is not set`, which i might want to report as `n`
] else if lib.length pieces == 1 then [
# no equals sign: this is probably a blank line
] else [{
name = lib.head pieces;
# value = parseKconfigValue (lib.concatStringsSep "=" (lib.tail pieces));
# nixpkgs kernel config is some real fucking bullshit: it wants a plain string here instead of the structured config it demands eeeeeeverywhere else.
value = lib.concatStringsSep "=" (lib.tail pieces);
}]
;
parseKconfig = wholeStr: let
lines = lib.splitString "\n" wholeStr;
parsedItems = lib.concatMap parseKconfigLine lines;
in
lib.listToAttrs parsedItems;
KconfigPmos = builtins.readFile ./config-postmarketos-exynos5.arm7;
# remove CONFIG_LOCALVERSION else nixpkgs complains about mismatched modDirVersion
withoutOsFlavor = Kconfig: lib.replaceStrings
[ ''CONFIG_LOCALVERSION="-postmarketos-exynos5"'' ]
[ ''CONFIG_LOCALVERSION='' ]
Kconfig
;
# 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>
withModuleFixes = Kconfig: lib.replaceStrings
[ ''CONFIG_BATTERY_SBS=y'' ]
[ ''CONFIG_BATTERY_SBS=m'' ]
Kconfig
;
withOptimizations = Kconfig: if optimizeForSize then
lib.replaceStrings
[ ''CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y'' ]
# 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.
# 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
[ ''CONFIG_CC_OPTIMIZE_FOR_SIZE=y'' ]
Kconfig
else
Kconfig
;
withNixosRequirements = Kconfig: Kconfig + ''
#
# 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";
'';
KconfigStr = withNixosRequirements (
withOptimizations (
withModuleFixes (
withoutOsFlavor (
KconfigPmos
)
)
)
);
in linuxManualConfig {
inherit (linux) extraMakeFlags modDirVersion src version;
inherit features randstructSeed;
kernelPatches = args.kernelPatches or [];
configfile = writeTextFile {
name = "config-postmarketos-exynos5.arm7";
text = KconfigStr;
};
# nixpkgs requires to know the config as an attrset, to do various eval-time assertions.
# this forces me to include the Kconfig inline, instead of fetching it the way i do all the other pmOS kernel stuff.
config = parseKconfig KconfigStr;
}