From a2f33a4b895e00d9fd9d0b2b035f1d1103f606f3 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Mon, 30 Sep 2024 12:19:54 -0300 Subject: [PATCH 1/5] seabios: nixfmt-rfc-style --- pkgs/by-name/se/seabios/package.nix | 56 +++++++++++++++++------------ 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/pkgs/by-name/se/seabios/package.nix b/pkgs/by-name/se/seabios/package.nix index 713f58702113..9c06b7cf753e 100644 --- a/pkgs/by-name/se/seabios/package.nix +++ b/pkgs/by-name/se/seabios/package.nix @@ -1,9 +1,10 @@ -{ lib -, stdenv -, fetchgit -, acpica-tools -, python3 -, writeText +{ + lib, + acpica-tools, + fetchgit, + python3, + stdenv, + writeText, }: stdenv.mkDerivation (finalAttrs: { @@ -16,7 +17,10 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-hWemj83cxdY8p+Jhkh5GcPvI0Sy5aKYZJCsKDjHTUUk="; }; - outputs = [ "out" "doc" ]; + outputs = [ + "out" + "doc" + ]; nativeBuildInputs = [ python3 ]; @@ -29,20 +33,28 @@ stdenv.mkDerivation (finalAttrs: { "EXTRAVERSION=\"-nixpkgs\"" ]; - hardeningDisable = [ "pic" "stackprotector" "fortify" ]; + hardeningDisable = [ + "fortify" + "pic" + "stackprotector" + ]; - postConfigure = let - config = writeText "config.txt" (lib.generators.toKeyValue { } { - # SeaBIOS with CSM (Compatible Support Module) support; learn more at - # https://www.electronicshub.org/what-is-csm-bios/ - "CONFIG_CSM" = "y"; - "CONFIG_PERMIT_UNALIGNED_PCIROM" = "y"; - "CONFIG_QEMU_HARDWARE" = "y"; - }); - in '' - cp ${config} .config - make olddefconfig - ''; + postConfigure = + let + config = writeText "config.txt" ( + lib.generators.toKeyValue { } { + # SeaBIOS with CSM (Compatible Support Module) support; learn more at + # https://www.electronicshub.org/what-is-csm-bios/ + "CONFIG_CSM" = "y"; + "CONFIG_PERMIT_UNALIGNED_PCIROM" = "y"; + "CONFIG_QEMU_HARDWARE" = "y"; + } + ); + in + '' + cp ${config} .config + make olddefconfig + ''; installPhase = '' runHook preInstall @@ -64,9 +76,7 @@ stdenv.mkDerivation (finalAttrs: { ''; license = with lib.licenses; [ lgpl3Plus ]; maintainers = with lib.maintainers; [ AndersonTorres ]; - platforms = lib.systems.inspect.patternLogicalAnd - lib.systems.inspect.patterns.isUnix - lib.systems.inspect.patterns.isx86; + platforms = lib.systems.inspect.patternLogicalAnd lib.systems.inspect.patterns.isUnix lib.systems.inspect.patterns.isx86; badPlatforms = [ lib.systems.inspect.patterns.isDarwin ]; }; }) From b4e763282a3fd994f20ff515616b1df8c0ef7468 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Mon, 30 Sep 2024 12:24:35 -0300 Subject: [PATCH 2/5] seabios: use outputDoc --- pkgs/by-name/se/seabios/package.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/se/seabios/package.nix b/pkgs/by-name/se/seabios/package.nix index 9c06b7cf753e..992082babeab 100644 --- a/pkgs/by-name/se/seabios/package.nix +++ b/pkgs/by-name/se/seabios/package.nix @@ -59,8 +59,8 @@ stdenv.mkDerivation (finalAttrs: { installPhase = '' runHook preInstall - mkdir -pv $doc/share/doc/seabios-${finalAttrs.version}/ - cp -v docs/* $doc/share/doc/seabios-${finalAttrs.version}/ + mkdir -pv ''${!outputDoc}/share/doc/seabios-${finalAttrs.version}/ + cp -v docs/* ''${!outputDoc}/share/doc/seabios-${finalAttrs.version}/ install -Dm644 out/Csm16.bin -t $out/share/seabios/ runHook postInstall From 525eebaa3d30267cc52e5f8b731a9d5aa32d9c64 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Mon, 30 Sep 2024 12:35:00 -0300 Subject: [PATCH 3/5] seabios: new parameter ___build-type It can assume the values "coreboot", "csm" and "qemu". The triple-underscored kebab-cased format is a poor man's mitigation for the problem of unexpected shadowing. --- pkgs/by-name/se/seabios/package.nix | 31 +++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/pkgs/by-name/se/seabios/package.nix b/pkgs/by-name/se/seabios/package.nix index 992082babeab..0e0fc06aeb16 100644 --- a/pkgs/by-name/se/seabios/package.nix +++ b/pkgs/by-name/se/seabios/package.nix @@ -5,8 +5,33 @@ python3, stdenv, writeText, + # Configurable options + ___build-type ? "csm", }: +assert lib.elem (___build-type) [ + "coreboot" + # SeaBIOS with CSM (Compatible Support Module) support; learn more at + # https://www.electronicshub.org/what-is-csm-bios/ + "csm" + "qemu" +]; +let + biosfile = + { + "coreboot" = "bios.bin.elf"; + "csm" = "Csm16.bin"; + "qemu" = "bios.bin"; + } + .${___build-type}; + configuration-string = + { + "coreboot" = "CONFIG_COREBOOT"; + "csm" = "CONFIG_CSM"; + "qemu" = "CONFIG_QEMU"; + } + .${___build-type}; +in stdenv.mkDerivation (finalAttrs: { pname = "seabios"; version = "1.16.3"; @@ -43,9 +68,7 @@ stdenv.mkDerivation (finalAttrs: { let config = writeText "config.txt" ( lib.generators.toKeyValue { } { - # SeaBIOS with CSM (Compatible Support Module) support; learn more at - # https://www.electronicshub.org/what-is-csm-bios/ - "CONFIG_CSM" = "y"; + "${configuration-string}" = "y"; "CONFIG_PERMIT_UNALIGNED_PCIROM" = "y"; "CONFIG_QEMU_HARDWARE" = "y"; } @@ -61,7 +84,7 @@ stdenv.mkDerivation (finalAttrs: { mkdir -pv ''${!outputDoc}/share/doc/seabios-${finalAttrs.version}/ cp -v docs/* ''${!outputDoc}/share/doc/seabios-${finalAttrs.version}/ - install -Dm644 out/Csm16.bin -t $out/share/seabios/ + install -Dm644 out/${biosfile} -t $out/share/seabios/ runHook postInstall ''; From dd122c58b1e40900ee8bf87fcc2d290e930f8a39 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Mon, 30 Sep 2024 13:01:02 -0300 Subject: [PATCH 4/5] seabios: passthru attribute `firmware` So that the caller can pick the exact location of the resulting BIOS. --- pkgs/by-name/se/seabios/package.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/by-name/se/seabios/package.nix b/pkgs/by-name/se/seabios/package.nix index 0e0fc06aeb16..ac647e93b195 100644 --- a/pkgs/by-name/se/seabios/package.nix +++ b/pkgs/by-name/se/seabios/package.nix @@ -89,6 +89,11 @@ stdenv.mkDerivation (finalAttrs: { runHook postInstall ''; + passthru = { + build-type = ___build-type; + firmware = "${finalAttrs.finalPackage}/share/seabios/${biosfile}"; + }; + meta = { homepage = "https://www.seabios.org"; description = "Open source implementation of a 16bit x86 BIOS"; From e032a06dc9cb5fd4cfa32e626adf13efee9a8d04 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Mon, 30 Sep 2024 13:01:21 -0300 Subject: [PATCH 5/5] {seabios-coreboot, seabios-csm, seabios-qemu}: "init" --- pkgs/top-level/all-packages.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 12aace53e661..87902dcf3b18 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -5643,6 +5643,10 @@ with pkgs; nltk-data = callPackage ../tools/text/nltk-data { }; + seabios-coreboot = seabios.override { ___build-type = "coreboot"; }; + seabios-csm = seabios.override { ___build-type = "csm"; }; + seabios-qemu = seabios.override { ___build-type = "qemu"; }; + seaborn-data = callPackage ../tools/misc/seaborn-data { }; nodepy-runtime = with python3.pkgs; toPythonApplication nodepy-runtime;