Skip to content

m1n1: init at 1.4.21#420888

Merged
flokli merged 1 commit into
masterfrom
unknown repository
Jul 28, 2025
Merged

m1n1: init at 1.4.21#420888
flokli merged 1 commit into
masterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Jun 29, 2025

Part of upstreaming nixos-apple-silicon's m1n1 pkg. There are some parts of the m1n1 package in nixos-apple-silicon that I didn't know how to replicate properly such as the cross-building (which I don't think is needed), custom logos, and this snippet:

    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

Among others, there's probably a lot to revise here or remove if we don't need it.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other contributing documentation in corresponding paths.

Add a 👍 reaction to pull requests you find important.

m1n1: init at 1.4.21

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Jun 29, 2025
@ghost ghost requested a review from flokli June 29, 2025 00:22
Comment thread pkgs/by-name/m1/m1n1/package.nix Outdated
@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 29, 2025

Removed strictDeps = true; that was left in.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 29, 2025

I'm thinking about just simplifying down the builder code as much as possible and be closer to what the fedora rpm has which are just the components needed for an asahi installation.

diff --git a/pkgs/by-name/m1/m1n1/package.nix b/pkgs/by-name/m1/m1n1/package.nix
index a174079462e0..b5b10ec0b7b8 100644
--- a/pkgs/by-name/m1/m1n1/package.nix
+++ b/pkgs/by-name/m1/m1n1/package.nix
@@ -7,15 +7,9 @@
   source-code-pro,
   imagemagick,
   nix-update-script,
-  withChainloading ? true,
+  withChainloading ? false,
 }:
 let
-  pyenv = python3.withPackages (
-    p: with p; [
-      construct
-      pyserial
-    ]
-  );
   stdenvOpts = {
     targetPlatform = {
       system = "aarch64-none-elf";
@@ -57,6 +51,14 @@ stdenv.mkDerivation (finalAttrs: {
     substituteInPlace font/makefont.sh \
       --replace-fail "convert" "magick"
     patchShebangs .
+
+    font=${source-code-pro}/share/fonts/opentype/SourceCodePro-Bold.otf
+
+    pushd font
+    rm SourceCodePro-Bold.ttf font.bin font_retina.bin
+    ./makefont.sh 8 16 12 $font font.bin
+    ./makefont.sh 16 32 25 $font font_retina.bin
+    popd
   '';
 
   cargoRoot = "rust";
@@ -65,7 +67,12 @@ stdenv.mkDerivation (finalAttrs: {
   nativeBuildInputs =
     [
       imagemagick
-      pyenv
+      (python3.withPackages (
+        p: with p; [
+          construct
+          pyserial
+        ]
+      ))
     ]
     ++ lib.optionals withChainloading [
       rustPackages.cargo
@@ -79,38 +86,14 @@ stdenv.mkDerivation (finalAttrs: {
 
   enableParallelBuilding = true;
 
-  # Replace embedded font with nixpkgs
-  preConfigure = ''
-    font=${source-code-pro}/share/fonts/opentype/SourceCodePro-Bold.otf
-
-    pushd font
-    rm SourceCodePro-Bold.ttf font.bin font_retina.bin
-    ./makefont.sh 8 16 12 $font font.bin
-    ./makefont.sh 16 32 25 $font font_retina.bin
-    popd
-  '';
-
   installPhase = ''
     runHook preInstall
 
     install -Dm644 udev/80-m1n1.rules -t $out/lib/udev/rules.d/
     install -Dm644 build/m1n1.{bin,macho} -t $out/lib/m1n1/
-
     find {proxyclient,tools} -type f -exec install -Dm755 "{}" "$out/libexec/m1n1/{}" \;
-
     install -Dm644 m1n1.conf.example $out/etc/m1n1.conf
-
-    GCC=${buildPackages.gcc}
-    BINUTILS=${buildPackages.binutils-unwrapped}
-
-    mkdir -p $out/libexec/m1n1/toolchain-bin/
-    ln -s $GCC/bin/gcc $out/libexec/m1n1/toolchain-bin/
-    ln -s $GCC/bin/ld $out/libexec/m1n1/toolchain-bin/
-    ln -s $BINUTILS/bin/objcopy $out/libexec/m1n1/toolchain-bin/
-    ln -s $BINUTILS/bin/objdump $out/libexec/m1n1/toolchain-bin/
-    ln -s $GCC/bin/nm $out/libexec/m1n1/toolchain-bin/
-
-    install -Dm644 {README.md,m1n1.conf.example} -t $out/share/m1n1/doc/
+    install -Dm644 README.md -t $out/share/m1n1/doc/
     find 3rdparty_licenses -type f -exec install -Dm644 "{}" -t $out/share/m1n1/licenses/ \;
 
     runHook postInstall

@ghost ghost marked this pull request as draft June 29, 2025 17:55
@ghost ghost marked this pull request as ready for review June 30, 2025 02:16
@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 30, 2025

I decided to go with a minimum-required approach and greatly reduced the complexity of this derivation builder, using the Fedora RPM build as my model.

Comment thread pkgs/by-name/m1/m1n1/package.nix Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually don't list licenses of build dependencies here, but only these of the project we're building (which is MIT).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change applied.

@ghost ghost marked this pull request as draft June 30, 2025 16:13
@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 30, 2025

Marking this as draft until I make sure to do proper integration testing with the nixos-apple-silicon flake downstream. I'll post my results here.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 30, 2025

A customLogo parameter can also be added and brought over from downstream in case we would want to apply Nix branding.

@flokli
Copy link
Copy Markdown
Member

flokli commented Jun 30, 2025

A customLogo parameter can also be added and brought over from downstream in case we would want to apply Nix branding.

That one would be nice, tbh.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 30, 2025

Removed submodules as they're not being used anymore.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 30, 2025

My first pass for branding via nixos-icons

diff --git a/pkgs/by-name/m1/m1n1/package.nix b/pkgs/by-name/m1/m1n1/package.nix
index 8b3303f34934..d8f7e36fef1b 100644
--- a/pkgs/by-name/m1/m1n1/package.nix
+++ b/pkgs/by-name/m1/m1n1/package.nix
@@ -4,7 +4,9 @@
   fetchFromGitHub,
   imagemagick,
   source-code-pro,
+  nixos-icons,
   nix-update-script,
+  withNixBranding ? true,
 }:
 stdenv.mkDerivation (finalAttrs: {
   pname = "m1n1";
@@ -21,13 +23,24 @@ stdenv.mkDerivation (finalAttrs: {
     imagemagick
   ];
 
-  postConfigure = ''
-    patchShebangs --build font/makefont.sh
-    FONT_PATH=${source-code-pro}/share/fonts/opentype/SourceCodePro-Bold.otf
-    rm font/{SourceCodePro-Bold.ttf,font.bin,font_retina.bin}
-    ./font/makefont.sh 8 16 12 $FONT_PATH font/font.bin
-    ./font/makefont.sh 16 32 25 $FONT_PATH font/font_retina.bin
-  '';
+  postConfigure =
+    ''
+      patchShebangs --build font/makefont.sh
+      FONT_PATH=${source-code-pro}/share/fonts/opentype/SourceCodePro-Bold.otf
+      rm font/{SourceCodePro-Bold.ttf,font.bin,font_retina.bin}
+      ./font/makefont.sh 8 16 12 $FONT_PATH font/font.bin
+      ./font/makefont.sh 16 32 25 $FONT_PATH font/font_retina.bin
+    ''
+    + lib.optionalString withNixBranding ''
+      ln -fs ${nixos-icons}/share/icons/hicolor/256x256/apps/nix-snowflake.png \
+             bootlogo_256.png
+      ln -fs ${nixos-icons}/share/icons/hicolor/128x128/apps/nix-snowflake.png \
+             bootlogo_128.png
+      ln -fs ${nixos-icons}/share/icons/hicolor/48x48/apps/nix-snowflake.png \
+             bootlogo_48.png
+      patchShebangs --build ./data/makelogo.sh
+      ./data/makelogo.sh
+    '';
 
   makeFlags = [
     "RELEASE=1"

@flokli
Copy link
Copy Markdown
Member

flokli commented Jul 1, 2025

My first pass for branding via nixos-icons

Can we just include the customLogo code from nixos-apple-silicon for now? People might want to use their own logo, we can add a NixOS-specific branding later, and it can just reuse that mechanism.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 3, 2025

Okay so what nixos-apple-silicon does it just that it expects a path to a 256x256 png image and then uses imagemagick to resize it to the appropriate dimensions.

Maybe this method would be better (the phase this is done in is still tentative and I'm wondering whether postPatch would be a good fit)

diff --git a/pkgs/by-name/m1/m1n1/package.nix b/pkgs/by-name/m1/m1n1/package.nix
index 8b3303f34934..29947570f3ea 100644
--- a/pkgs/by-name/m1/m1n1/package.nix
+++ b/pkgs/by-name/m1/m1n1/package.nix
@@ -5,6 +5,9 @@
   imagemagick,
   source-code-pro,
   nix-update-script,
+  nixos-icons,
+  customLogo ? nixos-icons,
+  withCustomBranding ? false,
 }:
 stdenv.mkDerivation (finalAttrs: {
   pname = "m1n1";
@@ -21,13 +24,31 @@ stdenv.mkDerivation (finalAttrs: {
     imagemagick
   ];
 
-  postConfigure = ''
-    patchShebangs --build font/makefont.sh
-    FONT_PATH=${source-code-pro}/share/fonts/opentype/SourceCodePro-Bold.otf
-    rm font/{SourceCodePro-Bold.ttf,font.bin,font_retina.bin}
-    ./font/makefont.sh 8 16 12 $FONT_PATH font/font.bin
-    ./font/makefont.sh 16 32 25 $FONT_PATH font/font_retina.bin
-  '';
+  # If a custom logo is desired, all three attributes must be overridden.
+  env = {
+    IMG256 = "${customLogo}/share/icons/hicolor/256x256/apps/nix-snowflake.png";
+    IMG128 = "${customLogo}/share/icons/hicolor/128x128/apps/nix-snowflake.png";
+    IMG48 = "${customLogo}/share/icons/hicolor/48x48/apps/nix-snowflake.png";
+  };
+
+  preConfigure =
+    ''
+      patchShebangs --build font/makefont.sh
+      FONT_PATH=${source-code-pro}/share/fonts/opentype/SourceCodePro-Bold.otf
+      rm font/{SourceCodePro-Bold.ttf,font.bin,font_retina.bin}
+      ./font/makefont.sh 8 16 12 $FONT_PATH font/font.bin
+      ./font/makefont.sh 16 32 25 $FONT_PATH font/font_retina.bin
+    ''
+    + lib.optionalString withCustomBranding ''
+      ln -fs ${finalAttrs.env.IMG256} \
+             bootlogo_256.png
+      ln -fs ${finalAttrs.env.IMG128} \
+             bootlogo_128.png
+      ln -fs ${finalAttrs.env.IMG48} \
+             bootlogo_48.png
+      patchShebangs --build ./data/makelogo.sh
+      ./data/makelogo.sh
+    '';
 
   makeFlags = [
     "RELEASE=1"

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 3, 2025

Force pushed and rebased on current master.

@flokli
Copy link
Copy Markdown
Member

flokli commented Jul 3, 2025

No, I would not use env like this. And having customLogo and customBranding is confusing. Even more so that customLogo now needs to be a directory with share/icons/hicolor/*x*/apps/nix-snowflake.png

I'm proposing to land it very much like it is at nixos-apple-silicon:

https://github.com/nix-community/nixos-apple-silicon/blob/3ddc251d2acce5019b0fa770e224d068610a34e4/apple-silicon-support/packages/m1n1/default.nix#L65-L73

This is currently a lot of feature-creep, which is not necessary to reduce the amount of custom packages.

In a followup PR, once this has trickled through and we can make sure this is the expression being used, we could debate on adding another consumer of this tooling, setting customLogo to a NixOS-branded one, but that's all for later.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 3, 2025

I think a custom interface like that (and the other interfaces in m1n1) should be done in a follow-up PR then since it's not strictly necessary and I think you're a better author for that than me.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 3, 2025

I've ported this m1n1 to nixos-apple-silicon, I was able to produce a bootable iso with this patch which just involved renaming paths to match the one in the newer m1n1 derivation.

diff --git a/apple-silicon-support/modules/boot-m1n1/default.nix b/apple-silicon-support/modules/boot-m1n1/default.nix
index ccbd40b..2798e26 100644
--- a/apple-silicon-support/modules/boot-m1n1/default.nix
+++ b/apple-silicon-support/modules/boot-m1n1/default.nix
@@ -2,11 +2,7 @@
 let
   pkgs' = config.hardware.asahi.pkgs;
 
-  bootM1n1 = pkgs'.m1n1.override {
-    isRelease = true;
-    withTools = false;
-    customLogo = config.boot.m1n1CustomLogo;
-  };
+  bootM1n1 = pkgs'.m1n1;
 
   bootUBoot = pkgs'.uboot-asahi.override {
     m1n1 = bootM1n1;
@@ -14,7 +10,7 @@ let
 
   bootFiles = {
     "m1n1/boot.bin" = pkgs.runCommand "boot.bin" {} ''
-      cat ${bootM1n1}/build/m1n1.bin > $out
+      cat ${bootM1n1}/lib/m1n1/m1n1.bin > $out
       cat ${config.boot.kernelPackages.kernel}/dtbs/apple/*.dtb >> $out
       cat ${bootUBoot}/u-boot-nodtb.bin.gz >> $out
       if [ -n "${config.boot.m1n1ExtraOptions}" ]; then
diff --git a/apple-silicon-support/packages/m1n1/default.nix b/apple-silicon-support/packages/m1n1/default.nix
index 95645d8..8b3303f 100644
--- a/apple-silicon-support/packages/m1n1/default.nix
+++ b/apple-silicon-support/packages/m1n1/default.nix
@@ -1,110 +1,60 @@
-{ stdenv
-, buildPackages
-, lib
-, fetchFromGitHub
-, python3
-, dtc
-, imagemagick
-, isRelease ? false
-, withTools ? true
-, withChainloading ? false
-, customLogo ? null
+{
+  lib,
+  stdenv,
+  fetchFromGitHub,
+  imagemagick,
+  source-code-pro,
+  nix-update-script,
 }:
-
-let
-  pyenv = python3.withPackages (p: with p; [
-    construct
-    pyserial
-  ]);
-
-  stdenvOpts = {
-    targetPlatform.system = "aarch64-none-elf";
-    targetPlatform.rust.rustcTarget = "${stdenv.hostPlatform.parsed.cpu.name}-unknown-none-softfloat";
-    targetPlatform.rust.rustcTargetSpec = "${stdenv.hostPlatform.parsed.cpu.name}-unknown-none-softfloat";
-  };
-  rust = buildPackages.rust.override {
-    stdenv = lib.recursiveUpdate buildPackages.stdenv stdenvOpts;
-  };
-  rustPackages = rust.packages.stable.overrideScope (f: p: {
-    rustc-unwrapped = p.rustc-unwrapped.override {
-      stdenv = lib.recursiveUpdate p.rustc-unwrapped.stdenv stdenvOpts;
-    };
-  });
-  rustPlatform = buildPackages.makeRustPlatform rustPackages;
-
-in stdenv.mkDerivation rec {
+stdenv.mkDerivation (finalAttrs: {
   pname = "m1n1";
   version = "1.4.21";
 
   src = fetchFromGitHub {
-    # tracking: https://src.fedoraproject.org/rpms/m1n1
     owner = "AsahiLinux";
     repo = "m1n1";
-    rev = "v${version}";
-    hash = "sha256-PEjTaSwcsV8PzM9a3rDWMYXGX9FlrM0oeElrP5HYRPg=";
-    fetchSubmodules = true;
+    tag = "v${finalAttrs.version}";
+    hash = "sha256-0ZnDexY/Sf2TJFfUv/YelCctFJVENffWqBU0r0azD0M=";
   };
-  cargoVendorDir = ".";
-
-  makeFlags = [ "ARCH=${stdenv.cc.targetPrefix}" ]
-    ++ lib.optional isRelease "RELEASE=1"
-    ++ lib.optional withChainloading "CHAINLOADING=1";
 
   nativeBuildInputs = [
-    dtc
-  ] ++ lib.optionals withChainloading [rustPackages.rustc rustPackages.cargo rustPlatform.cargoSetupHook]
-    ++ 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/"'
+    imagemagick
+  ];
+
+  postConfigure = ''
+    patchShebangs --build font/makefont.sh
+    FONT_PATH=${source-code-pro}/share/fonts/opentype/SourceCodePro-Bold.otf
+    rm font/{SourceCodePro-Bold.ttf,font.bin,font_retina.bin}
+    ./font/makefont.sh 8 16 12 $FONT_PATH font/font.bin
+    ./font/makefont.sh 16 32 25 $FONT_PATH font/font_retina.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
+  makeFlags = [
+    "RELEASE=1"
+  ];
 
-    rm bootlogo_128.png
-    convert bootlogo_256.png -resize 128x128 bootlogo_128.png
-    patchShebangs --build ./makelogo.sh
-    ./makelogo.sh
-    popd &>/dev/null
-  '';
+  enableParallelBuilding = true;
 
   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
+    install -Dm644 udev/80-m1n1.rules -t $out/lib/udev/rules.d/
+    install -Dm644 build/m1n1.{bin,macho} -t $out/lib/m1n1/
+    install -Dm644 m1n1.conf.example $out/etc/m1n1.conf
 
-    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
   '';
-}
+
+  passthru = {
+    updateScript = nix-update-script { };
+  };
+
+  meta = {
+    description = "Bootloader to bridge the Apple (XNU) boot to Linux boot";
+    homepage = "https://github.com/AsahiLinux/m1n1";
+    changelog = "https://github.com/AsahiLinux/m1n1/releases/tag/${finalAttrs.src.tag}";
+    license = lib.licenses.mit;
+    maintainers = with lib.maintainers; [ normalcea ];
+    platforms = [ "aarch64-linux" ];
+  };
+})
diff --git a/apple-silicon-support/packages/uboot-asahi/default.nix b/apple-silicon-support/packages/uboot-asahi/default.nix
index b13ca52..ca1a54f 100644
--- a/apple-silicon-support/packages/uboot-asahi/default.nix
+++ b/apple-silicon-support/packages/uboot-asahi/default.nix
@@ -39,6 +39,6 @@
   preInstall = ''
     # compress so that m1n1 knows U-Boot's size and can find things after it
     gzip -n u-boot-nodtb.bin
-    cat ${m1n1}/build/m1n1.bin arch/arm/dts/t[68]*.dtb u-boot-nodtb.bin.gz > m1n1-u-boot.bin
+    cat ${m1n1}/lib/m1n1/m1n1.bin arch/arm/dts/t[68]*.dtb u-boot-nodtb.bin.gz > m1n1-u-boot.bin
   '';
 })

@ghost ghost marked this pull request as ready for review July 3, 2025 20:54
@ghost ghost marked this pull request as draft July 3, 2025 21:18
@ghost ghost marked this pull request as ready for review July 3, 2025 21:44
@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 3, 2025

I wanted to triple check building the iso from an updated nixpkgs input in nixos-apple-silicon

This m1n1 should be functionally suitable. The other interfaces like cross-comp and logo overrides can be better iterated afterwards.

@flokli
Copy link
Copy Markdown
Member

flokli commented Jul 4, 2025

I wanted to triple check building the iso from an updated nixpkgs input in nixos-apple-silicon

This m1n1 should be functionally suitable. The other interfaces like cross-comp and logo overrides can be better iterated afterwards.

I think cross-comp is nice, we shouldn't actively drop code people added to make it work. I'm ok with dropping code that became unnecessary, but we shouldn't actively break cross-comp because we don't want to copy a few lines more (and reason which ones are still needed).

There's other things in the m1n1 output, like like all the tools to interact with the bootloader from elsewhere.
I'm not 100% sure what the right approach for this is (maybe the tools should be split into another package), but we can't delete the package from nixos-apple-silicon without having a replacement.

I propose to draft this PR, and do some of the cleanup/restructuring in nixos-apple-silicon before moving it over. It seems too risky to me to end up breaking users with the current approach.

Copy link
Copy Markdown
Member

@flokli flokli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See last comment, tools should probably be split off, and general cleanup happen in nixos-apple-silicon.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 4, 2025

tools to interact with the bootloader from elsewhere.

I've looked at the tools and I don't think they're applicable to nixpkgs/nixos. Nixos-apple-silicon doesn't use them and they are no instructions or documentation for using them, it's very easy to not realize they even exist. I personally have no understanding of what they do or how to use them. (edit: and I don't think they should be kept just because it existed before for nixos-apple-silicon users)

For cross-comp, I set meta.platforms to "aarch64-linux" since we can just have hydra cache m1n1, cross comp afaik requires compiling a Rust compiler target (what stdenvOpts variable was doing) and feels like more just a necessity since nixos-apple-silicon doesn't have its own cache (it only just started having CI for creating an iso from GitHub releases) and so cross-compilation was a practical and historical necessity. I think cross-comp can be added back in, but it's not necessary for nixos-apple-silicon users (who just need $out/lib/m1n1/m1n1.bin in asahi uboot).

I agree to setting this as a draft for now.

Related

It would be nice to have more user input on users of nixos on apple silicon. Maybe the right approach now is to try to get a Fedora SIG-like structure going? If we want to see what interfaces users would want we need more users themselves to comment on it.

https://asahilinux.org/docs/alt/policy/

Your project to implement Apple Silicon support in your distro of choice must be directly supported - or otherwise acknowledged - by your distro's official maintainers. This may vary depending on your distro's policy and organisational structure, however typically this will take the form of an official taskforce/group endorsed by the distro, e.g. the Fedora Asahi SIG, Gentoo Asahi Project, or Debian's Team Bananas.

We should propose the creation of an Asahi topic room in matrix (https://wiki.nixos.org/wiki/MatrixRooms). Things like having an Asahi team from teams.nix may also be good to steward over all the asahi-related packaging efforts and invite more asahi nix users into the fold.

Edit:

@flokli

If you want full disclosure on the reason why I'm upstreaming these packages: my intended end-goal is to see the upstreaming of everything in nix-community/nixos-apple-silicon proper (bootstrap installer, kernel, hardware options) into nixpkgs, eventually, nix-community/nixos-apple-silicon would just be documentation rather than a flake input (or be an experimental/opinionated flake input which has things like tooling programs that imho most users won't interact with).

This would allow us to have NixOS stable releases for Asahi hardware as currently nixos-apple-silicon users are on the unstable branch of nixpkgs and using stable nixos is not supported/not documented. I don't think as it stands currently we would qualify as an alternative distribution in the same level as fedora asahi remix if we don't aggressively pursue upstreaming.

TL;DR: I'm not interested in contributing/maintaining to nix-community/nixos-apple-silicon long-term and in my opinion, moving everything into nixpkgs will be very beneficial in the long run.

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jul 16, 2025
@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 16, 2025

I'm still stuck on the branding code. My main concern is that I don't see it being needed unless we have a nixos-apple-silicon special brand, otherwise, it does not matter to users about the image displayed. We'll still have to maintain a asahi-kernel downstream so unless that changes and there's an exception made (not holding my breath for that) or asahi upstreams everything they need (many kernel cycles down the line), there's no sense for branding within this PR.

Replacing the vendored fonts (which I took from the rpm spec) is more obviously needed.

@alyssais
Copy link
Copy Markdown
Member

I don't see any reason we can't figure that out later, after the initial addition of the package.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 16, 2025

- install -Dm644 m1n1.conf.example $out/share/etc/m1n1.conf
+ install -Dm644 m1n1.conf.example -t $out/share/doc/m1n1/

I moved the conf example to docs because I don't think it's customary to install files into $out/etc

@tpwrules
Copy link
Copy Markdown
Contributor

tpwrules commented Jul 16, 2025

With m1n1 in Nixpkgs, I could use my own kernel override and easily use NixOS on Apple Silicon without needing any extra third-party Nix code.

We also need Asahi's fork of u-boot to get a boot environment, plus the NixOS config to glue it all together with the kernel device trees. If one assumes the device trees do not change much, you could just override the kernel today.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 17, 2025

@tpwrules

The latest version of Uboot has upstream support and it looks like asahi-uboot won't be required (I'm currently writing this from my MBA which booted via uboot 2025.7). Unless there's an issue with this current basic implementation, I don't see any reason to block this PR as it only prevents further work from being submitted.

@flokli
Copy link
Copy Markdown
Member

flokli commented Jul 17, 2025

@tpwrules

The latest version of Uboot has upstream support and it looks like asahi-uboot won't be required (I'm currently writing this from my MBA which booted via uboot 2025.7). Unless there's an issue with this current basic implementation, I don't see any reason to block this PR as it only prevents further work from being submitted.

Mainline U-Boot is still missing 14 commits, see https://github.com/AsahiLinux/u-boot/commits/asahi/. I don't think we should ship something missing these in nixpkgs, it might cause more confusion.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 17, 2025

Mainline U-Boot is still missing 14 commits,

Hm I see, these were added very recently after the release and I'm assuming these will be upstreamed as well in the next uboot release in October (or be a new tagged release of asahi-uboot when Fedora Asahi Remix 43 releases). The asahi-uboot releases can still be tracked in nixos-apple-silicon. I disagree that this would cause confusion because it's pretty clear that it's upstream uboot and not the asahi fork. I think it would be a good idea to give people tools to create and hack on their own apple silicon modules by upstreaming as much as we can to nixpkgs.

Either way, that shouldn't affect the decision to upstream m1n1 since it's not a forked project like uboot. This isn't a PR to remove m1n1 from github:nix-community/nixos-apple-silicon but to upstream a common, good enough m1n1 package for nixpkgs.

@tpwrules
Copy link
Copy Markdown
Contributor

tpwrules commented Jul 17, 2025

If you are waiting for my explicit approval, I will try to do some testing this weekend. Please don’t feel it’s necessary though.

Regarding my earlier comment, the point is that some NixOS code will always be needed to glue the boot components together and stick them in the right place, and that code is unlikely to live in Nixpkgs proper. Without that code, having m1n1 and u-boot available doesn’t mean much. Using the Asahi kernel is also mostly possible without that code.

For what it’s worth, back near the beginning of the Asahi project I did a patch to u-boot so that the device trees did not need to be intermingled with m1n1 and could instead be loaded by u-boot using standard mechanisms, but the Asahi folks were quite uninterested. This would have made using an arbitrary kernel without managing the boot components easier. Maybe their opinion has changed in the intervening years but I’m not sure off the top of my head where the patch ran off to.

This PR does of course move us closer to the right NixOS code being useful in a default case which isn’t a bad thing.

@alyssais
Copy link
Copy Markdown
Member

alyssais commented Jul 18, 2025 via email

@tpwrules
Copy link
Copy Markdown
Contributor

I could be wrong but it seemed a lot more suited to nixos-hardware to me. But I am not the arbiter of that.

@alyssais
Copy link
Copy Markdown
Member

alyssais commented Jul 18, 2025 via email

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 18, 2025

In any case, these objections aren't related to the implementation of m1n1 derivation in this PR, nor would this being merged cause adverse consequences to downstream Nix projects and nixos-apple-silicon.

I feel like we are having a much larger discussion about how to approach Asahi Linux porting as a whole which should be handled in other communication channels outside of the PR tracker (and preferably handled before the work gets done and submitted for review).


And speaking frankly, I feel unable to contribute to downstream nixos-apple-silicon as none of my own PRs have been responded to and some others are just waiting already approved. There hasn't been any activity in it by the maintainers for 2+ weeks and counting (and there are 3 maintainers listed).

In the end, if I want to develop on porting Asahi to NixOS, upstreaming the existing codebase feels like my only outlet, so I feel dejected when listed maintainers of nixos-apple-silicon come into this PR requesting changes and declaring we should wait and yet no movement happens downstream.

I don't like confronting people on timelines in open source projects, but weeks of stalling and radio silence isn't productive. Especially when I submit PRs like nix-community/nixos-apple-silicon#314 that don't touch functionality and only exist to make the project more open to contributors and there's no response for weeks (besides the +1s from other users).

@alyssais
Copy link
Copy Markdown
Member

alyssais commented Jul 19, 2025 via email

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 20, 2025

I added back the licenses of the embedded libraries, none of which can really be un-vendored (besides source-code-pro but it's still included within the source).

@ghost
Copy link
Copy Markdown
Author

ghost commented Jul 20, 2025

For testing purposes: you can use my flake input for easy testing on your system which makes 1 commit to integrate this m1n1.

inputs.nixos-apple-silicon.url = "github:normalcea/nixos-apple-silicon/use-m1n1";

Copy link
Copy Markdown
Contributor

@tpwrules tpwrules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested (and am writing this from a machine running the test flake branch) but have some comments and questions about the derivation.

Nothing is severe enough to block merging but I think it could be cleaned further to better match the earlier-stated goals.

Comment thread pkgs/by-name/m1/m1n1/package.nix Outdated
Comment thread pkgs/by-name/m1/m1n1/package.nix Outdated
Comment thread pkgs/by-name/m1/m1n1/package.nix Outdated
Comment thread pkgs/by-name/m1/m1n1/package.nix Outdated
Copy link
Copy Markdown
Contributor

@tpwrules tpwrules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Jul 28, 2025
@alyssais alyssais requested a review from flokli July 28, 2025 12:11
Comment thread pkgs/by-name/m1/m1n1/package.nix Outdated
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. labels Jul 28, 2025
@flokli flokli merged commit 732a532 into NixOS:master Jul 28, 2025
25 of 29 checks passed
@ghost ghost deleted the asahi-m1n1-init branch July 29, 2025 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants