diff options
author | sefidel <contact@sefidel.net> | 2023-02-14 23:36:38 +0900 |
---|---|---|
committer | sefidel <contact@sefidel.net> | 2023-02-14 23:38:29 +0900 |
commit | 748adbac7ca3452d0a1250c37ff4168d6ccf5ae0 (patch) | |
tree | 7be36fd9da46399b3a98bc1b3e9309bd3ce64fb3 /nixos/modules/apple-silicon-support/packages/m1n1 | |
parent | adf6baa00e038e49cf477160eeddc886efced2b4 (diff) | |
download | nixrc-748adbac7ca3452d0a1250c37ff4168d6ccf5ae0.tar.gz nixrc-748adbac7ca3452d0a1250c37ff4168d6ccf5ae0.zip |
feat(nixos): init kompakt
Diffstat (limited to 'nixos/modules/apple-silicon-support/packages/m1n1')
-rw-r--r-- | nixos/modules/apple-silicon-support/packages/m1n1/default.nix | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/nixos/modules/apple-silicon-support/packages/m1n1/default.nix b/nixos/modules/apple-silicon-support/packages/m1n1/default.nix new file mode 100644 index 0000000..ee5450f --- /dev/null +++ b/nixos/modules/apple-silicon-support/packages/m1n1/default.nix @@ -0,0 +1,100 @@ +{ stdenv +, buildPackages +, lib +, fetchFromGitHub +, python3 +, dtc +, imagemagick +, isRelease ? false +, withTools ? true +, withChainloading ? false +, rust-bin ? null +, customLogo ? null +}: + +assert withChainloading -> rust-bin != null; + +let + pyenv = python3.withPackages (p: with p; [ + construct + pyserial + ]); + + rustenv = rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal.override { + targets = [ "aarch64-unknown-none-softfloat" ]; + }); +in stdenv.mkDerivation rec { + pname = "m1n1"; + version = "1.2.3"; + + src = fetchFromGitHub { + # tracking: https://github.com/AsahiLinux/PKGBUILDs/blob/stable/m1n1/PKGBUILD + owner = "AsahiLinux"; + repo = "m1n1"; + rev = "v${version}"; + hash = "sha256-HEhsg3/OkMvAHvu16VFun87SNBPin69CL6XllE7sb4g="; + fetchSubmodules = true; + }; + + makeFlags = [ "ARCH=${stdenv.cc.targetPrefix}" ] + ++ lib.optional isRelease "RELEASE=1" + ++ lib.optional withChainloading "CHAINLOADING=1"; + + nativeBuildInputs = [ + dtc + buildPackages.gcc + ] ++ lib.optional withChainloading rustenv + ++ lib.optional (customLogo != null) imagemagick; + + postPatch = '' + substituteInPlace proxyclient/m1n1/asm.py \ + --replace 'aarch64-linux-gnu-' 'aarch64-unknown-linux-gnu-' \ + --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 + + mkdir -p $out/build + cp build/m1n1.bin $out/build + '' + (lib.optionalString withTools '' + mkdir -p $out/{bin,script,toolchain-bin} + cp -r proxyclient $out/script + cp -r tools $out/script + + for toolpath in $out/script/proxyclient/tools/*.py; do + tool=$(basename $toolpath .py) + script=$out/bin/m1n1-$tool + cat > $script <<EOF +#!/bin/sh +${pyenv}/bin/python $toolpath "\$@" +EOF + chmod +x $script + done + + GCC=${buildPackages.gcc} + BINUTILS=${buildPackages.binutils-unwrapped} + + ln -s $GCC/bin/${stdenv.cc.targetPrefix}gcc $out/toolchain-bin/ + ln -s $GCC/bin/${stdenv.cc.targetPrefix}ld $out/toolchain-bin/ + ln -s $BINUTILS/bin/${stdenv.cc.targetPrefix}objcopy $out/toolchain-bin/ + ln -s $BINUTILS/bin/${stdenv.cc.targetPrefix}objdump $out/toolchain-bin/ + ln -s $GCC/bin/${stdenv.cc.targetPrefix}nm $out/toolchain-bin/ + '') + '' + runHook postInstall + ''; +} |