linux-postmarketos-*: factor out a sane-kernel-tools
helper set
This commit is contained in:
parent
8f6b4cc551
commit
95685fe91f
|
@ -2,6 +2,7 @@
|
|||
, fetchurl
|
||||
, linux-megous
|
||||
, linuxManualConfig
|
||||
, sane-kernel-tools
|
||||
, writeTextFile
|
||||
#v nixpkgs calls `.override` on the kernel to configure additional things, but we don't care about those things
|
||||
, features ? null
|
||||
|
@ -22,39 +23,7 @@ let
|
|||
};
|
||||
};
|
||||
|
||||
# parseKconfigValue = str: let
|
||||
# inherit (lib) kernel;
|
||||
# in
|
||||
# if str == "y" then
|
||||
# kernel.yes
|
||||
# else if str == "m" then
|
||||
# kernel.module
|
||||
# else
|
||||
# # kernel.freeform (lib.removePrefix ''"'' (lib.removeSuffix ''"'' str))
|
||||
# kernel.freeform str
|
||||
# ;
|
||||
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;
|
||||
|
||||
KconfigStr = (builtins.readFile ./config-postmarketos-allwinner.aarch64) + ''
|
||||
defconfigStr = (builtins.readFile ./config-postmarketos-allwinner.aarch64) + ''
|
||||
#
|
||||
# Extra nixpkgs-specific options
|
||||
# nixos/modules/system/boot/systemd.nix wants CONFIG_DMIID
|
||||
|
@ -79,11 +48,11 @@ in linuxManualConfig {
|
|||
|
||||
configfile = writeTextFile {
|
||||
name = "config-postmarketos-allwinner.aarch64";
|
||||
text = KconfigStr;
|
||||
text = defconfigStr;
|
||||
};
|
||||
# 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;
|
||||
# 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;
|
||||
|
||||
# these likely aren't *all* required for pinephone: pmOS kernel is shared by many devices
|
||||
kernelPatches = [
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
, linux ? linux_6_1, linux_6_1
|
||||
, linuxManualConfig
|
||||
, optimizeForSize ? false
|
||||
, sane-kernel-tools
|
||||
, writeTextFile
|
||||
#v nixpkgs calls `.override` on the kernel to configure additional things
|
||||
, features ? []
|
||||
|
@ -10,46 +11,24 @@
|
|||
}@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;
|
||||
defconfigPmos = builtins.readFile ./config-postmarketos-exynos5.arm7;
|
||||
|
||||
# remove CONFIG_LOCALVERSION else nixpkgs complains about mismatched modDirVersion
|
||||
withoutOsFlavor = Kconfig: lib.replaceStrings
|
||||
withoutOsFlavor = defconfig: lib.replaceStrings
|
||||
[ ''CONFIG_LOCALVERSION="-postmarketos-exynos5"'' ]
|
||||
[ ''CONFIG_LOCALVERSION='' ]
|
||||
Kconfig
|
||||
defconfig
|
||||
;
|
||||
|
||||
# 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
|
||||
withModuleFixes = defconfig: lib.replaceStrings
|
||||
[ ''CONFIG_BATTERY_SBS=y'' ]
|
||||
[ ''CONFIG_BATTERY_SBS=m'' ]
|
||||
Kconfig
|
||||
defconfig
|
||||
;
|
||||
|
||||
withOptimizations = Kconfig: if optimizeForSize then
|
||||
withOptimizations = defconfig: 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.
|
||||
|
@ -57,12 +36,12 @@ let
|
|||
# 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
|
||||
defconfig
|
||||
else
|
||||
Kconfig
|
||||
defconfig
|
||||
;
|
||||
|
||||
withNixosRequirements = Kconfig: Kconfig + ''
|
||||
withNixosRequirements = defconfig: defconfig + ''
|
||||
#
|
||||
# Extra nixpkgs-specific options
|
||||
# nixos/modules/system/boot/systemd.nix wants CONFIG_DMIID
|
||||
|
@ -76,11 +55,11 @@ let
|
|||
CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,selinux,smack,tomoyo,apparmor,bpf";
|
||||
'';
|
||||
|
||||
KconfigStr = withNixosRequirements (
|
||||
defconfigStr = withNixosRequirements (
|
||||
withOptimizations (
|
||||
withModuleFixes (
|
||||
withoutOsFlavor (
|
||||
KconfigPmos
|
||||
defconfigPmos
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -92,9 +71,9 @@ in linuxManualConfig {
|
|||
|
||||
configfile = writeTextFile {
|
||||
name = "config-postmarketos-exynos5.arm7";
|
||||
text = KconfigStr;
|
||||
text = defconfigStr;
|
||||
};
|
||||
# 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;
|
||||
# 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;
|
||||
}
|
||||
|
|
26
pkgs/additional/sane-kernel-tools/default.nix
Normal file
26
pkgs/additional/sane-kernel-tools/default.nix
Normal file
|
@ -0,0 +1,26 @@
|
|||
{ lib
|
||||
, newScope
|
||||
}:
|
||||
lib.makeScope newScope (self: with self; {
|
||||
parseDefconfigLine = 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;
|
||||
# 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);
|
||||
}]
|
||||
;
|
||||
# parseDefconfig: given the entire text of a defconfig file
|
||||
# parse it into an attrset usable by the nixpkgs kernel config tools.
|
||||
parseDefconfig = wholeStr: let
|
||||
lines = lib.splitString "\n" wholeStr;
|
||||
parsedItems = lib.concatMap parseDefconfigLine lines;
|
||||
in
|
||||
lib.listToAttrs parsedItems;
|
||||
})
|
|
@ -78,6 +78,7 @@ let
|
|||
sane-backgrounds = callPackage ./additional/sane-backgrounds { };
|
||||
sane-cast = callPackage ./additional/sane-cast { };
|
||||
sane-die-with-parent = callPackage ./additional/sane-die-with-parent { };
|
||||
sane-kernel-tools = lib.recurseIntoAttrs (callPackage ./additional/sane-kernel-tools { });
|
||||
sane-open = callPackage ./additional/sane-open { };
|
||||
sane-screenshot = callPackage ./additional/sane-screenshot { };
|
||||
sane-scripts = lib.recurseIntoAttrs (callPackage ./additional/sane-scripts { });
|
||||
|
|
Loading…
Reference in New Issue
Block a user