From dc1b42ae395e5d3a6cb9f69848488f6c992e62a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20He=C3=9F?= Date: Sun, 25 Sep 2022 15:05:39 +0200 Subject: [PATCH] m1n1: Support custom logo --- nix/m1-support/boot-m1n1/default.nix | 27 +++++++++++++++++++-------- nix/m1-support/m1n1/default.nix | 19 ++++++++++++++++++- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/nix/m1-support/boot-m1n1/default.nix b/nix/m1-support/boot-m1n1/default.nix index be985391..2e574994 100644 --- a/nix/m1-support/boot-m1n1/default.nix +++ b/nix/m1-support/boot-m1n1/default.nix @@ -10,6 +10,7 @@ let bootM1n1 = buildPkgs.callPackage ../m1n1 { isRelease = true; withTools = false; + customLogo = config.boot.m1n1CustomLogo; }; bootUBoot = buildPkgs.callPackage ../u-boot { @@ -41,13 +42,23 @@ in { ]; }; - options.boot.m1n1ExtraOptions = lib.mkOption { - type = lib.types.str; - default = ""; - description = '' - Append extra options to the m1n1 boot binary. Might be useful for fixing - display problems on Mac minis. - https://github.com/AsahiLinux/m1n1/issues/159 - ''; + options.boot = { + m1n1ExtraOptions = lib.mkOption { + type = lib.types.str; + default = ""; + description = '' + Append extra options to the m1n1 boot binary. Might be useful for fixing + display problems on Mac minis. + https://github.com/AsahiLinux/m1n1/issues/159 + ''; + }; + + m1n1CustomLogo = lib.mkOption { + type = lib.types.nullOr lib.types.path; + default = null; + description = '' + Custom logo to build into m1n1. The path must point to a 256x256 PNG. + ''; + }; }; } diff --git a/nix/m1-support/m1n1/default.nix b/nix/m1-support/m1n1/default.nix index 445d6e53..404e9abc 100644 --- a/nix/m1-support/m1n1/default.nix +++ b/nix/m1-support/m1n1/default.nix @@ -4,10 +4,12 @@ , pkgsCross , python3 , dtc +, imagemagick , isRelease ? false , withTools ? true , withChainloading ? false , rust-bin ? null +, customLogo ? null }: assert withChainloading -> rust-bin != null; @@ -41,7 +43,8 @@ in stdenv.mkDerivation rec { nativeBuildInputs = [ dtc pkgsCross.aarch64-multiplatform.buildPackages.gcc - ] ++ lib.optional withChainloading rustenv; + ] ++ lib.optional withChainloading rustenv + ++ lib.optional (customLogo != null) imagemagick; postPatch = '' substituteInPlace proxyclient/m1n1/asm.py \ @@ -49,6 +52,20 @@ in stdenv.mkDerivation rec { --replace 'TOOLCHAIN = ""' 'TOOLCHAIN = "'$out'/toolchain-bin/"' ''; + preConfigure = lib.optionalString (customLogo != null) '' + pushd data &>/dev/null + ln -fs ${customLogo} bootlogo_256.png + if [[ "$(magick identify bootlogo_256.png)" != 'bootlogo_256.png PNG 256x256'* ]]; then + echo "Custom logo is not a 256x256 PNG" + exit 1 + fi + + rm bootlogo_128.png + convert bootlogo_256.png -resize 128x128 bootlogo_128.png + ./makelogo.sh + popd &>/dev/null + ''; + installPhase = '' runHook preInstall