From d109ab6d89a583da789f82e3b13d602b147ba0db Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Sat, 14 Jan 2023 20:48:33 -0600 Subject: [PATCH 01/21] add flake.nix --- flake.lock | 115 ++++++++++++++++++++++++++++ flake.nix | 55 +++++++++++++ nix/installer-bootstrap/default.nix | 1 + nix/overlay.nix | 24 ++---- 4 files changed, 176 insertions(+), 19 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..97ad241f --- /dev/null +++ b/flake.lock @@ -0,0 +1,115 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1673362319, + "narHash": "sha256-Pjp45Vnj7S/b3BRpZEVfdu8sqqA6nvVjvYu59okhOyI=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "82c16f1682cf50c01cb0280b38a1eed202b3fe9f", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1673606088, + "narHash": "sha256-wdYD41UwNwPhTdMaG0AIe7fE1bAdyHe6bB4HLUqUvck=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "37b97ae3dd714de9a17923d004a2c5b5543dfa6d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1672350804, + "narHash": "sha256-jo6zkiCabUBn3ObuKXHGqqORUMH27gYDIFFfLq5P4wg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "677ed08a50931e38382dbef01cba08a8f7eac8f6", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1665296151, + "narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "14ccaaedd95a488dd7ae142757884d8e125b3363", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1673576998, + "narHash": "sha256-I6vYVejEWTao+Ze/F6VFSTFxu6/X2OPT3Eu4AM/zzec=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "ca474ccdd5f81ed742328e15dae38bb57a1006e3", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..228a905b --- /dev/null +++ b/flake.nix @@ -0,0 +1,55 @@ +{ + description = "Apple M1 support for NixOS"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = { self, flake-parts, ... }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } ( + { withSystem, ... }: { + systems = [ "aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ]; + + flake = { + overlays.default = import nix/overlay.nix; + + # TODO: make the nixos module use our overlay + nixosModules = rec { + m1-support = nix/m1-support; + default = m1-support; + }; + + packages.aarch64-linux = withSystem "aarch64-linux" ( + { pkgs, ... }: { + inherit (pkgs) m1n1 u-boot asahi-fwextract; + + # exposing installer-config breaks `nix flake show` + # https://github.com/NixOS/nix/issues/4265 + + installer-bootstrap = + let installer-config = pkgs.callPackage nix/installer-bootstrap {}; + in installer-config.system.build.isoImage; + } + ); + }; + + perSystem = { system, pkgs, ... }: { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ + inputs.rust-overlay.overlays.default + self.overlays.default + ]; + }; + + packages = { + installer-bootstrap-cross = + let installer-config-cross = pkgs.callPackage nix/installer-bootstrap { crossBuild = true; }; + in installer-config-cross.system.build.isoImage; + }; + }; + } + ); +} diff --git a/nix/installer-bootstrap/default.nix b/nix/installer-bootstrap/default.nix index 1ed4ee4b..7a7afadb 100644 --- a/nix/installer-bootstrap/default.nix +++ b/nix/installer-bootstrap/default.nix @@ -1,5 +1,6 @@ { pkgs, crossBuild ? false }: (import (pkgs.path + "/nixos/lib/eval-config.nix") { + inherit (pkgs) system; specialArgs = { modulesPath = pkgs.path + "/nixos/modules"; }; modules = [ ./iso-configuration.nix diff --git a/nix/overlay.nix b/nix/overlay.nix index 12d6ee40..0a64d24a 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -1,20 +1,6 @@ -self: super: -let - pkgs = self; - lib = pkgs.lib; -in { - # main scope - nixos-m1 = lib.makeScope pkgs.newScope (self: let - installer-config = self.callPackage ./installer-bootstrap {}; - installer-config-cross = self.callPackage ./installer-bootstrap { crossBuild = true; }; - in { - m1n1 = self.callPackage ./m1-support/m1n1 {}; - u-boot = self.callPackage ./m1-support/u-boot {}; - asahi-fwextract = self.callPackage ./m1-support/asahi-fwextract {}; - - installer-bootstrap = installer-config.system.build.isoImage; - installer-bootstrap-cross = installer-config-cross.system.build.isoImage; - - inherit installer-config installer-config-cross; - }); +final: prev: { + m1n1 = final.callPackage ./m1-support/m1n1 {}; + u-boot = final.callPackage ./m1-support/u-boot {}; + asahi-fwextract = final.callPackage ./m1-support/asahi-fwextract {}; + # TODO: package alsa-ucm-conf-asahi for headphone jack support } From cbd3029a9c4d98616677a787aeefa70eb363b402 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Sun, 15 Jan 2023 12:14:57 -0600 Subject: [PATCH 02/21] remove default.nix and pins.nix --- default.nix | 9 --------- nix/pins.nix | 15 --------------- 2 files changed, 24 deletions(-) delete mode 100644 default.nix delete mode 100644 nix/pins.nix diff --git a/default.nix b/default.nix deleted file mode 100644 index 7c7bd995..00000000 --- a/default.nix +++ /dev/null @@ -1,9 +0,0 @@ -let - pins = import ./nix/pins.nix; - overlays = [ - (import ./nix/overlay.nix) - (import pins.rust-overlay) - ]; -in { - nixpkgs ? pins.nixpkgs -}: (import nixpkgs { overlays = overlays; }).nixos-m1 diff --git a/nix/pins.nix b/nix/pins.nix deleted file mode 100644 index 6531c0d8..00000000 --- a/nix/pins.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ - # https://hydra.nixos.org/jobset/mobile-nixos/unstable/evals - # these evals have a cross-compiled stdenv available - nixpkgs = fetchTarball { - name = "nixpkgs-unstable-2023-01-15"; - url = "https://github.com/NixOS/nixpkgs/archive/6dccdc458512abce8d19f74195bb20fdb067df50.tar.gz"; - sha256 = "sha256:1is1icy39vvij73zv74qxc644agrgwpfvn5375k974ifx7s64inn"; - }; - - rust-overlay = fetchTarball { - name = "rust-overlay-2022-10-25"; - url = "https://github.com/oxalica/rust-overlay/archive/79b6e66bb76537c96707703f08630765e46148d1.tar.gz"; - sha256 = "sha256:0n5k3jdigp8bdwanwpnwyiapcvi9yn18dx2fg2vwrr937z8mlhii"; - }; -} From 66b3dc4bc32f9e921fed9eda5ae75d9ed8dc717f Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Sun, 15 Jan 2023 14:17:44 -0600 Subject: [PATCH 03/21] reorganize the project into `packages`, `nixos-module`, and `installer-bootstrap` note: installer-bootstrap won't build at this commit --- flake.nix | 8 ++++---- .../default.nix | 0 .../installer-configuration.nix | 2 +- .../iso-configuration.nix | 0 nix/overlay.nix | 6 ------ {nix/m1-support => nixos-module}/boot-m1n1/default.nix | 4 ++-- {nix/m1-support => nixos-module}/default.nix | 0 {nix/m1-support => nixos-module}/kernel/default.nix | 2 +- {nix/m1-support => nixos-module}/kernel/edge.nix | 0 {nix/m1-support => nixos-module}/mesa/default.nix | 2 +- .../peripheral-firmware/default.nix | 2 +- .../asahi-fwextract/add_entry_point.patch | 0 {nix/m1-support => packages}/asahi-fwextract/default.nix | 0 {nix/m1-support => packages}/kernel/config | 0 .../kernel/default-pagesize-16k.patch | 0 .../kernel/package.nix => packages/kernel/default.nix | 0 {nix/m1-support => packages}/kernel/sven-iommu-4k.patch | 0 {nix/m1-support => packages}/m1n1/default.nix | 0 .../mesa/package.nix => packages/mesa/default.nix | 0 packages/overlay.nix | 6 ++++++ {nix/m1-support => packages}/u-boot/default.nix | 0 21 files changed, 16 insertions(+), 16 deletions(-) rename {nix/installer-bootstrap => installer-bootstrap}/default.nix (100%) rename {nix/installer-bootstrap => installer-bootstrap}/installer-configuration.nix (98%) rename {nix/installer-bootstrap => installer-bootstrap}/iso-configuration.nix (100%) delete mode 100644 nix/overlay.nix rename {nix/m1-support => nixos-module}/boot-m1n1/default.nix (90%) rename {nix/m1-support => nixos-module}/default.nix (100%) rename {nix/m1-support => nixos-module}/kernel/default.nix (99%) rename {nix/m1-support => nixos-module}/kernel/edge.nix (100%) rename {nix/m1-support => nixos-module}/mesa/default.nix (96%) rename {nix/m1-support => nixos-module}/peripheral-firmware/default.nix (97%) rename {nix/m1-support => packages}/asahi-fwextract/add_entry_point.patch (100%) rename {nix/m1-support => packages}/asahi-fwextract/default.nix (100%) rename {nix/m1-support => packages}/kernel/config (100%) rename {nix/m1-support => packages}/kernel/default-pagesize-16k.patch (100%) rename nix/m1-support/kernel/package.nix => packages/kernel/default.nix (100%) rename {nix/m1-support => packages}/kernel/sven-iommu-4k.patch (100%) rename {nix/m1-support => packages}/m1n1/default.nix (100%) rename nix/m1-support/mesa/package.nix => packages/mesa/default.nix (100%) create mode 100644 packages/overlay.nix rename {nix/m1-support => packages}/u-boot/default.nix (100%) diff --git a/flake.nix b/flake.nix index 228a905b..1829adfe 100644 --- a/flake.nix +++ b/flake.nix @@ -13,11 +13,11 @@ systems = [ "aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ]; flake = { - overlays.default = import nix/overlay.nix; + overlays.default = import packages/overlay.nix; # TODO: make the nixos module use our overlay nixosModules = rec { - m1-support = nix/m1-support; + m1-support = ./nixos-module; default = m1-support; }; @@ -29,7 +29,7 @@ # https://github.com/NixOS/nix/issues/4265 installer-bootstrap = - let installer-config = pkgs.callPackage nix/installer-bootstrap {}; + let installer-config = pkgs.callPackage ./installer-bootstrap {}; in installer-config.system.build.isoImage; } ); @@ -46,7 +46,7 @@ packages = { installer-bootstrap-cross = - let installer-config-cross = pkgs.callPackage nix/installer-bootstrap { crossBuild = true; }; + let installer-config-cross = pkgs.callPackage ./installer-bootstrap { crossBuild = true; }; in installer-config-cross.system.build.isoImage; }; }; diff --git a/nix/installer-bootstrap/default.nix b/installer-bootstrap/default.nix similarity index 100% rename from nix/installer-bootstrap/default.nix rename to installer-bootstrap/default.nix diff --git a/nix/installer-bootstrap/installer-configuration.nix b/installer-bootstrap/installer-configuration.nix similarity index 98% rename from nix/installer-bootstrap/installer-configuration.nix rename to installer-bootstrap/installer-configuration.nix index db18f370..430d9a22 100644 --- a/nix/installer-bootstrap/installer-configuration.nix +++ b/installer-bootstrap/installer-configuration.nix @@ -29,7 +29,7 @@ fileSystems = lib.mkOverride 60 config.lib.isoFileSystems; boot.postBootCommands = let - asahi-fwextract = pkgs.callPackage ../m1-support/asahi-fwextract {}; + asahi-fwextract = pkgs.callPackage ../packages/asahi-fwextract {}; in '' for o in $( Date: Sun, 15 Jan 2023 17:55:21 -0600 Subject: [PATCH 04/21] fix installer-bootstrap to fit the new project structure --- installer-bootstrap/default.nix | 12 ++++++------ installer-bootstrap/installer-configuration.nix | 17 ++++++++++------- installer-bootstrap/iso-configuration.nix | 7 ++++--- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/installer-bootstrap/default.nix b/installer-bootstrap/default.nix index 7a7afadb..733202e1 100644 --- a/installer-bootstrap/default.nix +++ b/installer-bootstrap/default.nix @@ -4,10 +4,10 @@ specialArgs = { modulesPath = pkgs.path + "/nixos/modules"; }; modules = [ ./iso-configuration.nix - ] ++ (if crossBuild then [ { - nixpkgs.crossSystem = { - system = "aarch64-linux"; - }; - hardware.asahi.pkgsSystem = pkgs.stdenv.system; - } ] else [ ]); + ] ++ ( + pkgs.lib.optional crossBuild { + nixpkgs.crossSystem.system = "aarch64-linux"; + hardware.asahi.pkgsSystem = pkgs.stdenv.system; + } + ); }).config diff --git a/installer-bootstrap/installer-configuration.nix b/installer-bootstrap/installer-configuration.nix index 430d9a22..03bb490b 100644 --- a/installer-bootstrap/installer-configuration.nix +++ b/installer-bootstrap/installer-configuration.nix @@ -29,6 +29,9 @@ fileSystems = lib.mkOverride 60 config.lib.isoFileSystems; boot.postBootCommands = let + # TODO: this is wrong! we need to make sure that this path is valid + # when building the iso *and* when this file is copied into the final + # configuration. This is currently broken in the final configuration. asahi-fwextract = pkgs.callPackage ../packages/asahi-fwextract {}; in '' for o in $( Date: Sun, 15 Jan 2023 20:12:35 -0600 Subject: [PATCH 05/21] remove the distinction between installer-bootstrap and installer-bootstrap-cross --- flake.nix | 15 +++++---------- installer-bootstrap/default.nix | 11 +++++------ nixos-module/default.nix | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/flake.nix b/flake.nix index 1829adfe..6f241709 100644 --- a/flake.nix +++ b/flake.nix @@ -24,13 +24,6 @@ packages.aarch64-linux = withSystem "aarch64-linux" ( { pkgs, ... }: { inherit (pkgs) m1n1 u-boot asahi-fwextract; - - # exposing installer-config breaks `nix flake show` - # https://github.com/NixOS/nix/issues/4265 - - installer-bootstrap = - let installer-config = pkgs.callPackage ./installer-bootstrap {}; - in installer-config.system.build.isoImage; } ); }; @@ -45,9 +38,11 @@ }; packages = { - installer-bootstrap-cross = - let installer-config-cross = pkgs.callPackage ./installer-bootstrap { crossBuild = true; }; - in installer-config-cross.system.build.isoImage; + # exposing installer-config breaks `nix flake show` + # https://github.com/NixOS/nix/issues/4265 + installer-bootstrap = + let installer-config = import ./installer-bootstrap { inherit pkgs; }; + in installer-config.system.build.isoImage; }; }; } diff --git a/installer-bootstrap/default.nix b/installer-bootstrap/default.nix index 733202e1..83ab6150 100644 --- a/installer-bootstrap/default.nix +++ b/installer-bootstrap/default.nix @@ -1,13 +1,12 @@ -{ pkgs, crossBuild ? false }: +{ pkgs }: (import (pkgs.path + "/nixos/lib/eval-config.nix") { - inherit (pkgs) system; specialArgs = { modulesPath = pkgs.path + "/nixos/modules"; }; modules = [ ./iso-configuration.nix - ] ++ ( - pkgs.lib.optional crossBuild { + { nixpkgs.crossSystem.system = "aarch64-linux"; - hardware.asahi.pkgsSystem = pkgs.stdenv.system; + nixpkgs.localSystem.system = pkgs.system; + hardware.asahi.pkgsSystem = pkgs.system; } - ); + ]; }).config diff --git a/nixos-module/default.nix b/nixos-module/default.nix index 50cfd4b4..be17fd4b 100644 --- a/nixos-module/default.nix +++ b/nixos-module/default.nix @@ -10,8 +10,8 @@ config = { hardware.asahi.pkgs = if config.hardware.asahi.pkgsSystem != "aarch64-linux" then import (pkgs.path) { - system = config.hardware.asahi.pkgsSystem; crossSystem.system = "aarch64-linux"; + localSystem.system = config.hardware.asahi.pkgsSystem; } else pkgs; }; From feb4490bcc2148e5d4f4f42337ead1b65a2a0f14 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Sun, 15 Jan 2023 21:14:53 -0600 Subject: [PATCH 06/21] use nixpkgs `lib.nixosSystem` to build the installer adjust project structure --- flake.nix | 22 ++++++++++++++----- installer-bootstrap/default.nix | 12 ---------- .../default.nix | 0 .../installer-configuration.nix | 0 4 files changed, 16 insertions(+), 18 deletions(-) delete mode 100644 installer-bootstrap/default.nix rename installer-bootstrap/iso-configuration.nix => iso-configuration/default.nix (100%) rename {installer-bootstrap => iso-configuration}/installer-configuration.nix (100%) diff --git a/flake.nix b/flake.nix index 6f241709..c6a7b061 100644 --- a/flake.nix +++ b/flake.nix @@ -10,8 +10,6 @@ outputs = { self, flake-parts, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } ( { withSystem, ... }: { - systems = [ "aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ]; - flake = { overlays.default = import packages/overlay.nix; @@ -28,6 +26,9 @@ ); }; + # all nixpkgs systems + systems = inputs.nixpkgs.lib.systems.flakeExposed; + perSystem = { system, pkgs, ... }: { _module.args.pkgs = import inputs.nixpkgs { inherit system; @@ -38,11 +39,20 @@ }; packages = { - # exposing installer-config breaks `nix flake show` - # https://github.com/NixOS/nix/issues/4265 installer-bootstrap = - let installer-config = import ./installer-bootstrap { inherit pkgs; }; - in installer-config.system.build.isoImage; + let + installer-system = inputs.nixpkgs.lib.nixosSystem { + specialArgs = { modulesPath = inputs.nixpkgs + "/nixos/modules"; }; + modules = [ + ./iso-configuration + { + nixpkgs.crossSystem.system = "aarch64-linux"; + nixpkgs.localSystem.system = system; + hardware.asahi.pkgsSystem = system; + } + ]; + }; + in installer-system.config.system.build.isoImage; }; }; } diff --git a/installer-bootstrap/default.nix b/installer-bootstrap/default.nix deleted file mode 100644 index 83ab6150..00000000 --- a/installer-bootstrap/default.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ pkgs }: -(import (pkgs.path + "/nixos/lib/eval-config.nix") { - specialArgs = { modulesPath = pkgs.path + "/nixos/modules"; }; - modules = [ - ./iso-configuration.nix - { - nixpkgs.crossSystem.system = "aarch64-linux"; - nixpkgs.localSystem.system = pkgs.system; - hardware.asahi.pkgsSystem = pkgs.system; - } - ]; -}).config diff --git a/installer-bootstrap/iso-configuration.nix b/iso-configuration/default.nix similarity index 100% rename from installer-bootstrap/iso-configuration.nix rename to iso-configuration/default.nix diff --git a/installer-bootstrap/installer-configuration.nix b/iso-configuration/installer-configuration.nix similarity index 100% rename from installer-bootstrap/installer-configuration.nix rename to iso-configuration/installer-configuration.nix From 08f27aeba41e2155a29c92b4bdc9548999fd5918 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Mon, 16 Jan 2023 15:31:56 -0600 Subject: [PATCH 07/21] make the nixos module and installer use our overlay --- flake.nix | 1 - iso-configuration/installer-configuration.nix | 5 +-- nixos-module/boot-m1n1/default.nix | 6 ++- nixos-module/default.nix | 38 +++++++++++++++---- nixos-module/kernel/default.nix | 13 ++++--- nixos-module/mesa/default.nix | 8 ---- nixos-module/peripheral-firmware/default.nix | 31 +++++++-------- .../{mesa => mesa-asahi-edge}/default.nix | 0 packages/overlay.nix | 2 + 9 files changed, 61 insertions(+), 43 deletions(-) rename packages/{mesa => mesa-asahi-edge}/default.nix (100%) diff --git a/flake.nix b/flake.nix index c6a7b061..9318a139 100644 --- a/flake.nix +++ b/flake.nix @@ -13,7 +13,6 @@ flake = { overlays.default = import packages/overlay.nix; - # TODO: make the nixos module use our overlay nixosModules = rec { m1-support = ./nixos-module; default = m1-support; diff --git a/iso-configuration/installer-configuration.nix b/iso-configuration/installer-configuration.nix index 03bb490b..d5b80350 100644 --- a/iso-configuration/installer-configuration.nix +++ b/iso-configuration/installer-configuration.nix @@ -29,10 +29,7 @@ fileSystems = lib.mkOverride 60 config.lib.isoFileSystems; boot.postBootCommands = let - # TODO: this is wrong! we need to make sure that this path is valid - # when building the iso *and* when this file is copied into the final - # configuration. This is currently broken in the final configuration. - asahi-fwextract = pkgs.callPackage ../packages/asahi-fwextract {}; + inherit (config.hardware.asahi.pkgs) asahi-fwextract; in '' for o in $( Date: Sun, 15 Jan 2023 23:45:08 -0600 Subject: [PATCH 08/21] update flake.nix --- flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 9318a139..824c50c8 100644 --- a/flake.nix +++ b/flake.nix @@ -28,7 +28,8 @@ # all nixpkgs systems systems = inputs.nixpkgs.lib.systems.flakeExposed; - perSystem = { system, pkgs, ... }: { + perSystem = { system, ... }: { + # override the `pkgs` argument used by flake-parts modules _module.args.pkgs = import inputs.nixpkgs { inherit system; overlays = [ From 14a4ef53f6a093c8f606f2ed90753361dfe29072 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Mon, 16 Jan 2023 18:36:43 -0600 Subject: [PATCH 09/21] update package names --- flake.nix | 2 +- nixos-module/boot-m1n1/default.nix | 2 +- packages/{kernel => linux-asahi}/config | 0 packages/{kernel => linux-asahi}/default-pagesize-16k.patch | 0 packages/{kernel => linux-asahi}/default.nix | 0 packages/{kernel => linux-asahi}/sven-iommu-4k.patch | 0 packages/overlay.nix | 4 ++-- packages/{u-boot => uboot-asahi}/default.nix | 0 8 files changed, 4 insertions(+), 4 deletions(-) rename packages/{kernel => linux-asahi}/config (100%) rename packages/{kernel => linux-asahi}/default-pagesize-16k.patch (100%) rename packages/{kernel => linux-asahi}/default.nix (100%) rename packages/{kernel => linux-asahi}/sven-iommu-4k.patch (100%) rename packages/{u-boot => uboot-asahi}/default.nix (100%) diff --git a/flake.nix b/flake.nix index 824c50c8..c507489f 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,7 @@ packages.aarch64-linux = withSystem "aarch64-linux" ( { pkgs, ... }: { - inherit (pkgs) m1n1 u-boot asahi-fwextract; + inherit (pkgs) m1n1 uboot-asahi asahi-fwextract; } ); }; diff --git a/nixos-module/boot-m1n1/default.nix b/nixos-module/boot-m1n1/default.nix index e24afef9..39e94c56 100644 --- a/nixos-module/boot-m1n1/default.nix +++ b/nixos-module/boot-m1n1/default.nix @@ -8,7 +8,7 @@ let customLogo = config.boot.m1n1CustomLogo; }; - bootUBoot = pkgs'.u-boot.override { + bootUBoot = pkgs'.uboot-asahi.override { m1n1 = bootM1n1; }; diff --git a/packages/kernel/config b/packages/linux-asahi/config similarity index 100% rename from packages/kernel/config rename to packages/linux-asahi/config diff --git a/packages/kernel/default-pagesize-16k.patch b/packages/linux-asahi/default-pagesize-16k.patch similarity index 100% rename from packages/kernel/default-pagesize-16k.patch rename to packages/linux-asahi/default-pagesize-16k.patch diff --git a/packages/kernel/default.nix b/packages/linux-asahi/default.nix similarity index 100% rename from packages/kernel/default.nix rename to packages/linux-asahi/default.nix diff --git a/packages/kernel/sven-iommu-4k.patch b/packages/linux-asahi/sven-iommu-4k.patch similarity index 100% rename from packages/kernel/sven-iommu-4k.patch rename to packages/linux-asahi/sven-iommu-4k.patch diff --git a/packages/overlay.nix b/packages/overlay.nix index 28d4a568..90549520 100644 --- a/packages/overlay.nix +++ b/packages/overlay.nix @@ -1,7 +1,7 @@ final: prev: { - linux-asahi = final.callPackage ./kernel { }; + linux-asahi = final.callPackage ./linux-asahi { }; m1n1 = final.callPackage ./m1n1 { }; - u-boot = final.callPackage ./u-boot { }; + uboot-asahi = final.callPackage ./uboot-asahi { }; asahi-fwextract = final.callPackage ./asahi-fwextract { }; mesa-asahi-edge = final.callPackage ./mesa-asahi-edge { }; # TODO: package alsa-ucm-conf-asahi for headphone jack support diff --git a/packages/u-boot/default.nix b/packages/uboot-asahi/default.nix similarity index 100% rename from packages/u-boot/default.nix rename to packages/uboot-asahi/default.nix From 4fe63258823a253e1ea7e91336c90f9783d1fed7 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Mon, 16 Jan 2023 19:24:04 -0600 Subject: [PATCH 10/21] improve flake.nix export m1n1 and uboot-asahi for cross-compilation remove asahi-fwextract from package outputs --- flake.nix | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index c507489f..24b76f0b 100644 --- a/flake.nix +++ b/flake.nix @@ -11,24 +11,21 @@ flake-parts.lib.mkFlake { inherit inputs; } ( { withSystem, ... }: { flake = { - overlays.default = import packages/overlay.nix; + overlays = rec { + asahi-overlay = import packages/overlay.nix; + default = asahi-overlay; + }; nixosModules = rec { m1-support = ./nixos-module; default = m1-support; }; - - packages.aarch64-linux = withSystem "aarch64-linux" ( - { pkgs, ... }: { - inherit (pkgs) m1n1 uboot-asahi asahi-fwextract; - } - ); }; - # all nixpkgs systems - systems = inputs.nixpkgs.lib.systems.flakeExposed; + # build platforms supported for uboot in nixpkgs + systems = [ "aarch64-linux" "x86_64-linux" "i686-linux" ]; - perSystem = { system, ... }: { + perSystem = { system, pkgs, ... }: { # override the `pkgs` argument used by flake-parts modules _module.args.pkgs = import inputs.nixpkgs { inherit system; @@ -39,6 +36,8 @@ }; packages = { + inherit (pkgs) m1n1 uboot-asahi; + installer-bootstrap = let installer-system = inputs.nixpkgs.lib.nixosSystem { From 5c91fea469f78dcf3b7f72c6346200e036f34bf9 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Tue, 17 Jan 2023 09:13:55 -0600 Subject: [PATCH 11/21] nixos-module: add overlay with mkBefore --- nixos-module/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos-module/default.nix b/nixos-module/default.nix index 28e361a6..1ae87bb9 100644 --- a/nixos-module/default.nix +++ b/nixos-module/default.nix @@ -11,7 +11,7 @@ let cfg = config.hardware.asahi; in { - nixpkgs.overlays = [ cfg.overlay ]; + nixpkgs.overlays = lib.mkBefore [ cfg.overlay ]; hardware.asahi.pkgs = if cfg.pkgsSystem != "aarch64-linux" From 4066a941bfb449f41c0716b6d7a45d89140e7055 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Wed, 18 Jan 2023 22:21:04 -0600 Subject: [PATCH 12/21] nixos-module: use `lib.findFirst` in the default firmware directory --- nixos-module/peripheral-firmware/default.nix | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/nixos-module/peripheral-firmware/default.nix b/nixos-module/peripheral-firmware/default.nix index 328b12ac..39bd6fbe 100644 --- a/nixos-module/peripheral-firmware/default.nix +++ b/nixos-module/peripheral-firmware/default.nix @@ -44,20 +44,15 @@ peripheralFirmwareDirectory = lib.mkOption { type = lib.types.nullOr lib.types.path; - default = let - paths = [ + + default = lib.findFirst (path: builtins.pathExists (path + "/all_firmware.tar.gz")) null + [ # path when the system is operating normally "/boot/asahi" # path when the system is mounted in the installer "/mnt/boot/asahi" ]; - validPaths = (builtins.filter - (p: builtins.pathExists (p + "/all_firmware.tar.gz")) - paths) ++ [ null ]; - - firstPath = builtins.elemAt validPaths 0; - in if firstPath != null then "${/. + firstPath}" else null; description = '' Path to the directory containing the non-free non-redistributable peripheral firmware necessary for features like Wi-Fi. Ordinarily, this From 96f70c89efcedfed0de67c12bcd42f7180786212 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Thu, 19 Jan 2023 10:24:57 -0600 Subject: [PATCH 13/21] set up cross-compilation logic for pure evaluation stop using `pkgsCross.aarch64-multiplatform` --- flake.nix | 1 + packages/linux-asahi/default.nix | 24 +++++++++++++++--------- packages/m1n1/default.nix | 17 +++++++++++------ packages/uboot-asahi/default.nix | 14 ++++++++------ 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/flake.nix b/flake.nix index 24b76f0b..6f423554 100644 --- a/flake.nix +++ b/flake.nix @@ -27,6 +27,7 @@ perSystem = { system, pkgs, ... }: { # override the `pkgs` argument used by flake-parts modules + # TODO: import nixpkgs with cross-compilation _module.args.pkgs = import inputs.nixpkgs { inherit system; overlays = [ diff --git a/packages/linux-asahi/default.nix b/packages/linux-asahi/default.nix index c618ab75..941bff53 100644 --- a/packages/linux-asahi/default.nix +++ b/packages/linux-asahi/default.nix @@ -1,9 +1,15 @@ -{ pkgs, _4KBuild ? false, withRust ? false, kernelPatches ? [ ] }: let - localPkgs = - # we do this so the config can be read on any system and not affect - # the output hash - if builtins ? currentSystem then import (pkgs.path) { system = builtins.currentSystem; } - else pkgs; +{ pkgs, _4KBuild ? false, withRust ? false, kernelPatches ? [ ] }: + +let + # we do this so the config IFDs will have the same output hash + # when evaluated in the cross system + # + # TODO: is this really necessary? the hash shoud remain the same + # as long as `hardware.asahi.pkgsSystem` is set correctly. + localPkgs = import (pkgs.path) { + crossSystem = pkgs.stdenv.buildPlatform; + localSystem = pkgs.stdenv.buildPlatform; + }; lib = localPkgs.lib; @@ -25,7 +31,7 @@ echo "{ }" >> $out '').outPath; - linux_asahi_pkg = { stdenv, lib, fetchFromGitHub, fetchpatch, linuxKernel, + linux-asahi-pkg = { stdenv, lib, fetchFromGitHub, fetchpatch, linuxKernel, rustPlatform, rustfmt, rust-bindgen, ... } @ args: let configfile = if kernelPatches == [ ] then ./config else @@ -96,6 +102,6 @@ ''; } else {}); - linux_asahi = (pkgs.callPackage linux_asahi_pkg { }); -in pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux_asahi) + linux-asahi = (pkgs.callPackage linux-asahi-pkg { }); +in pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux-asahi) diff --git a/packages/m1n1/default.nix b/packages/m1n1/default.nix index 30d2b775..2977f9a7 100644 --- a/packages/m1n1/default.nix +++ b/packages/m1n1/default.nix @@ -1,7 +1,7 @@ -{ stdenv +{ pkgs +, stdenv , lib , fetchFromGitHub -, pkgsCross , python3 , dtc , imagemagick @@ -15,6 +15,11 @@ assert withChainloading -> rust-bin != null; let + crossPkgs = import pkgs.path { + crossSystem.system = "aarch64-linux"; + localSystem.system = pkgs.stdenv.buildPlatform.system; + }; + pyenv = python3.withPackages (p: with p; [ construct pyserial @@ -36,13 +41,13 @@ in stdenv.mkDerivation rec { fetchSubmodules = true; }; - makeFlags = [ "ARCH=aarch64-unknown-linux-gnu-" ] + makeFlags = [ "ARCH=${stdenv.cc.targetPrefix}" ] ++ lib.optional isRelease "RELEASE=1" ++ lib.optional withChainloading "CHAINLOADING=1"; nativeBuildInputs = [ dtc - pkgsCross.aarch64-multiplatform.buildPackages.gcc + crossPkgs.buildPackages.gcc ] ++ lib.optional withChainloading rustenv ++ lib.optional (customLogo != null) imagemagick; @@ -86,8 +91,8 @@ EOF chmod +x $script done - GCC=${pkgsCross.aarch64-multiplatform.buildPackages.gcc} - BINUTILS=${pkgsCross.aarch64-multiplatform.buildPackages.binutils-unwrapped} + GCC=${crossPkgs.buildPackages.gcc} + BINUTILS=${crossPkgs.buildPackages.binutils-unwrapped} ln -s $GCC/bin/*-gcc $out/toolchain-bin/ ln -s $GCC/bin/*-ld $out/toolchain-bin/ diff --git a/packages/uboot-asahi/default.nix b/packages/uboot-asahi/default.nix index 95a9afd6..457e8b15 100644 --- a/packages/uboot-asahi/default.nix +++ b/packages/uboot-asahi/default.nix @@ -2,13 +2,15 @@ , fetchFromGitHub , fetchpatch , pkgs -, pkgsCross , m1n1 -}: let - # u-boot's buildInputs get a different hash and don't build right if we try to - # cross-build for aarch64 on itself for whatever reason - buildPkgs = if pkgs.stdenv.system == "aarch64-linux" then pkgs else pkgsCross.aarch64-multiplatform; -in (buildPkgs.buildUBoot rec { +}: + +let + crossPkgs = import pkgs.path { + crossSystem.system = "aarch64-linux"; + localSystem.system = pkgs.stdenv.buildPlatform.system; + }; +in (crossPkgs.buildUBoot rec { src = fetchFromGitHub { # tracking: https://github.com/AsahiLinux/PKGBUILDs/blob/stable/uboot-asahi/PKGBUILD owner = "AsahiLinux"; From 7d984c2202b219dbbbc4534bf7682be0923cbaf0 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Thu, 19 Jan 2023 11:31:49 -0600 Subject: [PATCH 14/21] make pkgs more explicit and consistent --- flake.nix | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index 6f423554..45ee4975 100644 --- a/flake.nix +++ b/flake.nix @@ -27,9 +27,9 @@ perSystem = { system, pkgs, ... }: { # override the `pkgs` argument used by flake-parts modules - # TODO: import nixpkgs with cross-compilation _module.args.pkgs = import inputs.nixpkgs { - inherit system; + crossSystem.system = "aarch64-linux"; + localSystem.system = system; overlays = [ inputs.rust-overlay.overlays.default self.overlays.default @@ -42,14 +42,23 @@ installer-bootstrap = let installer-system = inputs.nixpkgs.lib.nixosSystem { - specialArgs = { modulesPath = inputs.nixpkgs + "/nixos/modules"; }; + inherit system; + + # make sure this matches the post-install + # `hardware.asahi.pkgsSystem` + pkgs = import inputs.nixpkgs { + crossSystem.system = "aarch64-linux"; + localSystem.system = system; + overlays = [ self.overlays.default ]; + }; + + specialArgs = { + modulesPath = inputs.nixpkgs + "/nixos/modules"; + }; + modules = [ ./iso-configuration - { - nixpkgs.crossSystem.system = "aarch64-linux"; - nixpkgs.localSystem.system = system; - hardware.asahi.pkgsSystem = system; - } + { hardware.asahi.pkgsSystem = system; } ]; }; in installer-system.config.system.build.isoImage; From 83612110cee91c6eb326275b641f1a2ce3ee98d9 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:30:16 -0600 Subject: [PATCH 15/21] remove nixpkgs re-imports --- packages/linux-asahi/default.nix | 41 +++++++++++++++----------------- packages/m1n1/default.nix | 15 ++++-------- packages/uboot-asahi/default.nix | 9 ++----- 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/packages/linux-asahi/default.nix b/packages/linux-asahi/default.nix index 941bff53..7223340b 100644 --- a/packages/linux-asahi/default.nix +++ b/packages/linux-asahi/default.nix @@ -1,18 +1,15 @@ -{ pkgs, _4KBuild ? false, withRust ? false, kernelPatches ? [ ] }: +{ lib +, callPackage +, runCommand +, writeShellScriptBin +, writeText +, linuxPackagesFor +, _4KBuild ? false +, withRust ? false +, kernelPatches ? [ ] +}: let - # we do this so the config IFDs will have the same output hash - # when evaluated in the cross system - # - # TODO: is this really necessary? the hash shoud remain the same - # as long as `hardware.asahi.pkgsSystem` is set correctly. - localPkgs = import (pkgs.path) { - crossSystem = pkgs.stdenv.buildPlatform; - localSystem = pkgs.stdenv.buildPlatform; - }; - - lib = localPkgs.lib; - parseExtraConfig = cfg: let lines = builtins.filter (s: s != "") (lib.strings.splitString "\n" cfg); perLine = line: let @@ -21,7 +18,7 @@ let "CONFIG_${builtins.elemAt kv 0}=${builtins.elemAt kv 1}"; in lib.strings.concatMapStringsSep "\n" perLine lines; - readConfig = configfile: import (localPkgs.runCommand "config.nix" { } '' + readConfig = configfile: import (runCommand "config.nix" { } '' echo "{ } // " > "$out" while IFS='=' read key val; do [ "x''${key#CONFIG_}" != "x$key" ] || continue @@ -35,12 +32,12 @@ let rustPlatform, rustfmt, rust-bindgen, ... } @ args: let configfile = if kernelPatches == [ ] then ./config else - pkgs.writeText "config" '' - ${builtins.readFile ./config} + writeText "config" '' + ${builtins.readFile ./config} - # Patches - ${lib.strings.concatMapStringsSep "\n" ({extraConfig ? "", ...}: parseExtraConfig extraConfig) kernelPatches} - ''; + # Patches + ${lib.strings.concatMapStringsSep "\n" ({extraConfig ? "", ...}: parseExtraConfig extraConfig) kernelPatches} + ''; _kernelPatches = kernelPatches; in @@ -88,7 +85,7 @@ let # is running, so we give the kernel build a rustc that wraps the real rustc # while setting the appropriate environment variable during its execution. # https://github.com/NixOS/nixpkgs/pull/209113 - (pkgs.writeShellScriptBin "rustc" '' + (writeShellScriptBin "rustc" '' NIX_LDFLAGS=-lgcc ${rustPlatform.rust.rustc}/bin/rustc "$@" '') ]; @@ -102,6 +99,6 @@ let ''; } else {}); - linux-asahi = (pkgs.callPackage linux-asahi-pkg { }); -in pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux-asahi) + linux-asahi = (callPackage linux-asahi-pkg { }); +in lib.recurseIntoAttrs (linuxPackagesFor linux-asahi) diff --git a/packages/m1n1/default.nix b/packages/m1n1/default.nix index 2977f9a7..da666640 100644 --- a/packages/m1n1/default.nix +++ b/packages/m1n1/default.nix @@ -1,5 +1,5 @@ -{ pkgs -, stdenv +{ stdenv +, buildPackages , lib , fetchFromGitHub , python3 @@ -15,11 +15,6 @@ assert withChainloading -> rust-bin != null; let - crossPkgs = import pkgs.path { - crossSystem.system = "aarch64-linux"; - localSystem.system = pkgs.stdenv.buildPlatform.system; - }; - pyenv = python3.withPackages (p: with p; [ construct pyserial @@ -47,7 +42,7 @@ in stdenv.mkDerivation rec { nativeBuildInputs = [ dtc - crossPkgs.buildPackages.gcc + buildPackages.gcc ] ++ lib.optional withChainloading rustenv ++ lib.optional (customLogo != null) imagemagick; @@ -91,8 +86,8 @@ EOF chmod +x $script done - GCC=${crossPkgs.buildPackages.gcc} - BINUTILS=${crossPkgs.buildPackages.binutils-unwrapped} + GCC=${buildPackages.gcc} + BINUTILS=${buildPackages.binutils-unwrapped} ln -s $GCC/bin/*-gcc $out/toolchain-bin/ ln -s $GCC/bin/*-ld $out/toolchain-bin/ diff --git a/packages/uboot-asahi/default.nix b/packages/uboot-asahi/default.nix index 457e8b15..d9126314 100644 --- a/packages/uboot-asahi/default.nix +++ b/packages/uboot-asahi/default.nix @@ -1,16 +1,11 @@ { lib , fetchFromGitHub , fetchpatch -, pkgs +, buildUBoot , m1n1 }: -let - crossPkgs = import pkgs.path { - crossSystem.system = "aarch64-linux"; - localSystem.system = pkgs.stdenv.buildPlatform.system; - }; -in (crossPkgs.buildUBoot rec { +(buildUBoot rec { src = fetchFromGitHub { # tracking: https://github.com/AsahiLinux/PKGBUILDs/blob/stable/uboot-asahi/PKGBUILD owner = "AsahiLinux"; From 32ebdd7384a98f6a55d0fd9aac6c8281b5818a06 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Thu, 19 Jan 2023 15:55:47 -0600 Subject: [PATCH 16/21] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nixpkgs': 'github:nixos/nixpkgs/37b97ae3dd714de9a17923d004a2c5b5543dfa6d' (2023-01-13) → 'github:nixos/nixpkgs/2d38b664b4400335086a713a0036aafaa002c003' (2023-01-17) • Updated input 'rust-overlay': 'github:oxalica/rust-overlay/ca474ccdd5f81ed742328e15dae38bb57a1006e3' (2023-01-13) → 'github:oxalica/rust-overlay/5f7315b9800e2e500e6834767a57e39f7dbfd495' (2023-01-19) --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 97ad241f..e0d317ee 100644 --- a/flake.lock +++ b/flake.lock @@ -35,11 +35,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1673606088, - "narHash": "sha256-wdYD41UwNwPhTdMaG0AIe7fE1bAdyHe6bB4HLUqUvck=", + "lastModified": 1673947312, + "narHash": "sha256-xx/2nRwRy3bXrtry6TtydKpJpqHahjuDB5sFkQ/XNDE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "37b97ae3dd714de9a17923d004a2c5b5543dfa6d", + "rev": "2d38b664b4400335086a713a0036aafaa002c003", "type": "github" }, "original": { @@ -96,11 +96,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1673576998, - "narHash": "sha256-I6vYVejEWTao+Ze/F6VFSTFxu6/X2OPT3Eu4AM/zzec=", + "lastModified": 1674095406, + "narHash": "sha256-RexH/1rZTiX4OhdYkuJP3MuANJ+JRgoLKL60iHm//T0=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "ca474ccdd5f81ed742328e15dae38bb57a1006e3", + "rev": "5f7315b9800e2e500e6834767a57e39f7dbfd495", "type": "github" }, "original": { From 74112e27cea97a9ae35194d8c281955f203df5f0 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Mon, 23 Jan 2023 00:13:39 -0600 Subject: [PATCH 17/21] simplify flake dependencies --- flake.lock | 87 +++++------------------------------------------------- flake.nix | 70 ++++++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 112 deletions(-) diff --git a/flake.lock b/flake.lock index e0d317ee..fded32fa 100644 --- a/flake.lock +++ b/flake.lock @@ -1,106 +1,35 @@ { "nodes": { - "flake-parts": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib" - }, - "locked": { - "lastModified": 1673362319, - "narHash": "sha256-Pjp45Vnj7S/b3BRpZEVfdu8sqqA6nvVjvYu59okhOyI=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "82c16f1682cf50c01cb0280b38a1eed202b3fe9f", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "flake-utils": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1673947312, - "narHash": "sha256-xx/2nRwRy3bXrtry6TtydKpJpqHahjuDB5sFkQ/XNDE=", + "lastModified": 1673796341, + "narHash": "sha256-1kZi9OkukpNmOaPY7S5/+SlCDOuYnP3HkXHvNDyLQcc=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2d38b664b4400335086a713a0036aafaa002c003", + "rev": "6dccdc458512abce8d19f74195bb20fdb067df50", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-lib": { - "locked": { - "dir": "lib", - "lastModified": 1672350804, - "narHash": "sha256-jo6zkiCabUBn3ObuKXHGqqORUMH27gYDIFFfLq5P4wg=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "677ed08a50931e38382dbef01cba08a8f7eac8f6", - "type": "github" - }, - "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1665296151, - "narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "14ccaaedd95a488dd7ae142757884d8e125b3363", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", "repo": "nixpkgs", + "rev": "6dccdc458512abce8d19f74195bb20fdb067df50", "type": "github" } }, "root": { "inputs": { - "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay" } }, "rust-overlay": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs_2" - }, + "flake": false, "locked": { - "lastModified": 1674095406, - "narHash": "sha256-RexH/1rZTiX4OhdYkuJP3MuANJ+JRgoLKL60iHm//T0=", + "lastModified": 1674440843, + "narHash": "sha256-kMCGL1wADpbcgGiMgj1pcOxbLy2zfmzsn46YCMWwtIE=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "5f7315b9800e2e500e6834767a57e39f7dbfd495", + "rev": "57b363f390f031b8b8d26235c2d21b0ad5a84640", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 45ee4975..509c31db 100644 --- a/flake.nix +++ b/flake.nix @@ -2,41 +2,47 @@ description = "Apple M1 support for NixOS"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - rust-overlay.url = "github:oxalica/rust-overlay"; - flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs = { + # https://hydra.nixos.org/jobset/mobile-nixos/unstable/evals + # these evals have a cross-compiled stdenv available + url = "github:nixos/nixpkgs/6dccdc458512abce8d19f74195bb20fdb067df50"; + }; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + flake = false; + }; }; - outputs = { self, flake-parts, ... }@inputs: - flake-parts.lib.mkFlake { inherit inputs; } ( - { withSystem, ... }: { - flake = { - overlays = rec { - asahi-overlay = import packages/overlay.nix; - default = asahi-overlay; - }; + outputs = { self, ... }@inputs: + let + # build platforms supported for uboot in nixpkgs + systems = [ "aarch64-linux" "x86_64-linux" ]; # "i686-linux" omitted - nixosModules = rec { - m1-support = ./nixos-module; - default = m1-support; - }; + forAllSystems = inputs.nixpkgs.lib.genAttrs systems; + in + { + overlays = rec { + asahi-overlay = import packages/overlay.nix; + default = asahi-overlay; }; - # build platforms supported for uboot in nixpkgs - systems = [ "aarch64-linux" "x86_64-linux" "i686-linux" ]; - - perSystem = { system, pkgs, ... }: { - # override the `pkgs` argument used by flake-parts modules - _module.args.pkgs = import inputs.nixpkgs { - crossSystem.system = "aarch64-linux"; - localSystem.system = system; - overlays = [ - inputs.rust-overlay.overlays.default - self.overlays.default - ]; - }; + nixosModules = rec { + m1-support = ./nixos-module; + default = m1-support; + }; - packages = { + packages = forAllSystems (system: + let + pkgs = import inputs.nixpkgs { + crossSystem.system = "aarch64-linux"; + localSystem.system = system; + overlays = [ + (import inputs.rust-overlay) + self.overlays.default + ]; + }; + in { inherit (pkgs) m1n1 uboot-asahi; installer-bootstrap = @@ -62,8 +68,6 @@ ]; }; in installer-system.config.system.build.isoImage; - }; - }; - } - ); + }); + }; } From e90b07b6f12e72115209252f0cc7651926f19166 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Mon, 23 Jan 2023 19:37:18 -0600 Subject: [PATCH 18/21] reorganize nixos module use `apple-silicon-support/modules` and `apple-silicon-support/packages` --- apple-silicon-support/default.nix | 7 +++++++ .../modules}/boot-m1n1/default.nix | 0 .../modules}/default.nix | 0 .../modules}/kernel/default.nix | 0 .../modules}/kernel/edge.nix | 0 .../modules}/mesa/default.nix | 0 .../modules}/peripheral-firmware/default.nix | 0 .../packages}/asahi-fwextract/add_entry_point.patch | 0 .../packages}/asahi-fwextract/default.nix | 0 .../packages}/linux-asahi/config | 0 .../linux-asahi/default-pagesize-16k.patch | 0 .../packages}/linux-asahi/default.nix | 0 .../packages}/linux-asahi/sven-iommu-4k.patch | 0 .../packages}/m1n1/default.nix | 0 .../packages}/mesa-asahi-edge/default.nix | 0 .../packages}/overlay.nix | 0 .../packages}/uboot-asahi/default.nix | 0 flake.nix | 10 +++++----- iso-configuration/default.nix | 13 ++++++------- 19 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 apple-silicon-support/default.nix rename {nixos-module => apple-silicon-support/modules}/boot-m1n1/default.nix (100%) rename {nixos-module => apple-silicon-support/modules}/default.nix (100%) rename {nixos-module => apple-silicon-support/modules}/kernel/default.nix (100%) rename {nixos-module => apple-silicon-support/modules}/kernel/edge.nix (100%) rename {nixos-module => apple-silicon-support/modules}/mesa/default.nix (100%) rename {nixos-module => apple-silicon-support/modules}/peripheral-firmware/default.nix (100%) rename {packages => apple-silicon-support/packages}/asahi-fwextract/add_entry_point.patch (100%) rename {packages => apple-silicon-support/packages}/asahi-fwextract/default.nix (100%) rename {packages => apple-silicon-support/packages}/linux-asahi/config (100%) rename {packages => apple-silicon-support/packages}/linux-asahi/default-pagesize-16k.patch (100%) rename {packages => apple-silicon-support/packages}/linux-asahi/default.nix (100%) rename {packages => apple-silicon-support/packages}/linux-asahi/sven-iommu-4k.patch (100%) rename {packages => apple-silicon-support/packages}/m1n1/default.nix (100%) rename {packages => apple-silicon-support/packages}/mesa-asahi-edge/default.nix (100%) rename {packages => apple-silicon-support/packages}/overlay.nix (100%) rename {packages => apple-silicon-support/packages}/uboot-asahi/default.nix (100%) diff --git a/apple-silicon-support/default.nix b/apple-silicon-support/default.nix new file mode 100644 index 00000000..71a5dd0f --- /dev/null +++ b/apple-silicon-support/default.nix @@ -0,0 +1,7 @@ +{ ... }: + +{ + imports = [ + ./modules/default.nix + ]; +} diff --git a/nixos-module/boot-m1n1/default.nix b/apple-silicon-support/modules/boot-m1n1/default.nix similarity index 100% rename from nixos-module/boot-m1n1/default.nix rename to apple-silicon-support/modules/boot-m1n1/default.nix diff --git a/nixos-module/default.nix b/apple-silicon-support/modules/default.nix similarity index 100% rename from nixos-module/default.nix rename to apple-silicon-support/modules/default.nix diff --git a/nixos-module/kernel/default.nix b/apple-silicon-support/modules/kernel/default.nix similarity index 100% rename from nixos-module/kernel/default.nix rename to apple-silicon-support/modules/kernel/default.nix diff --git a/nixos-module/kernel/edge.nix b/apple-silicon-support/modules/kernel/edge.nix similarity index 100% rename from nixos-module/kernel/edge.nix rename to apple-silicon-support/modules/kernel/edge.nix diff --git a/nixos-module/mesa/default.nix b/apple-silicon-support/modules/mesa/default.nix similarity index 100% rename from nixos-module/mesa/default.nix rename to apple-silicon-support/modules/mesa/default.nix diff --git a/nixos-module/peripheral-firmware/default.nix b/apple-silicon-support/modules/peripheral-firmware/default.nix similarity index 100% rename from nixos-module/peripheral-firmware/default.nix rename to apple-silicon-support/modules/peripheral-firmware/default.nix diff --git a/packages/asahi-fwextract/add_entry_point.patch b/apple-silicon-support/packages/asahi-fwextract/add_entry_point.patch similarity index 100% rename from packages/asahi-fwextract/add_entry_point.patch rename to apple-silicon-support/packages/asahi-fwextract/add_entry_point.patch diff --git a/packages/asahi-fwextract/default.nix b/apple-silicon-support/packages/asahi-fwextract/default.nix similarity index 100% rename from packages/asahi-fwextract/default.nix rename to apple-silicon-support/packages/asahi-fwextract/default.nix diff --git a/packages/linux-asahi/config b/apple-silicon-support/packages/linux-asahi/config similarity index 100% rename from packages/linux-asahi/config rename to apple-silicon-support/packages/linux-asahi/config diff --git a/packages/linux-asahi/default-pagesize-16k.patch b/apple-silicon-support/packages/linux-asahi/default-pagesize-16k.patch similarity index 100% rename from packages/linux-asahi/default-pagesize-16k.patch rename to apple-silicon-support/packages/linux-asahi/default-pagesize-16k.patch diff --git a/packages/linux-asahi/default.nix b/apple-silicon-support/packages/linux-asahi/default.nix similarity index 100% rename from packages/linux-asahi/default.nix rename to apple-silicon-support/packages/linux-asahi/default.nix diff --git a/packages/linux-asahi/sven-iommu-4k.patch b/apple-silicon-support/packages/linux-asahi/sven-iommu-4k.patch similarity index 100% rename from packages/linux-asahi/sven-iommu-4k.patch rename to apple-silicon-support/packages/linux-asahi/sven-iommu-4k.patch diff --git a/packages/m1n1/default.nix b/apple-silicon-support/packages/m1n1/default.nix similarity index 100% rename from packages/m1n1/default.nix rename to apple-silicon-support/packages/m1n1/default.nix diff --git a/packages/mesa-asahi-edge/default.nix b/apple-silicon-support/packages/mesa-asahi-edge/default.nix similarity index 100% rename from packages/mesa-asahi-edge/default.nix rename to apple-silicon-support/packages/mesa-asahi-edge/default.nix diff --git a/packages/overlay.nix b/apple-silicon-support/packages/overlay.nix similarity index 100% rename from packages/overlay.nix rename to apple-silicon-support/packages/overlay.nix diff --git a/packages/uboot-asahi/default.nix b/apple-silicon-support/packages/uboot-asahi/default.nix similarity index 100% rename from packages/uboot-asahi/default.nix rename to apple-silicon-support/packages/uboot-asahi/default.nix diff --git a/flake.nix b/flake.nix index 509c31db..902697a6 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Apple M1 support for NixOS"; + description = "Apple Silicon support for NixOS"; inputs = { nixpkgs = { @@ -23,13 +23,13 @@ in { overlays = rec { - asahi-overlay = import packages/overlay.nix; - default = asahi-overlay; + apple-silicon-overlay = import ./apple-silicon-support/packages/overlay.nix; + default = apple-silicon-overlay; }; nixosModules = rec { - m1-support = ./nixos-module; - default = m1-support; + apple-silicon-support = ./apple-silicon-support; + default = apple-silicon-support; }; packages = forAllSystems (system: diff --git a/iso-configuration/default.nix b/iso-configuration/default.nix index cd99a406..dacda568 100644 --- a/iso-configuration/default.nix +++ b/iso-configuration/default.nix @@ -3,23 +3,22 @@ { imports = [ ./installer-configuration.nix - ../nixos-module + ../apple-silicon-support ]; # include those modules so the user can rebuild the install iso. that's not - # especially useful at this point, but the user will need the m1-support + # especially useful at this point, but the user will need the apple-silicon-support # directory for their own config. installer.cloneConfigIncludes = [ "./installer-configuration.nix" - "./m1-support/nixos-module" + "./apple-silicon-support" ]; - # copy the m1-support and installer configs into the iso + # copy the apple-silicon-support and installer configs into the iso boot.postBootCommands = lib.optionalString config.installer.cloneConfig '' - if ! [ -e /etc/nixos/m1-support ]; then - mkdir -p /etc/nixos/m1-support + if ! [ -e /etc/nixos/apple-silicon-support ]; then cp ${./installer-configuration.nix} /etc/nixos/installer-configuration.nix - cp -r ${../packages} ${../nixos-module} -t /etc/nixos/m1-support + cp -r ${../apple-silicon-support} /etc/nixos/apple-silicon-support fi ''; } From 677aacff1fd6b7260b34248902eef80d674da56a Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Mon, 30 Jan 2023 01:01:51 -0600 Subject: [PATCH 19/21] fix default peripheral firmware paths --- apple-silicon-support/modules/peripheral-firmware/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apple-silicon-support/modules/peripheral-firmware/default.nix b/apple-silicon-support/modules/peripheral-firmware/default.nix index 39bd6fbe..2a478e6d 100644 --- a/apple-silicon-support/modules/peripheral-firmware/default.nix +++ b/apple-silicon-support/modules/peripheral-firmware/default.nix @@ -48,9 +48,9 @@ default = lib.findFirst (path: builtins.pathExists (path + "/all_firmware.tar.gz")) null [ # path when the system is operating normally - "/boot/asahi" + /boot/asahi # path when the system is mounted in the installer - "/mnt/boot/asahi" + /mnt/boot/asahi ]; description = '' From 516c0aa988e42e14c65c142e27e13ccab2e31555 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Mon, 30 Jan 2023 01:02:04 -0600 Subject: [PATCH 20/21] fix cross-compilation for packages --- .../packages/linux-asahi/default.nix | 12 +++++++++++- apple-silicon-support/packages/m1n1/default.nix | 10 +++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/apple-silicon-support/packages/linux-asahi/default.nix b/apple-silicon-support/packages/linux-asahi/default.nix index 7223340b..faa2e844 100644 --- a/apple-silicon-support/packages/linux-asahi/default.nix +++ b/apple-silicon-support/packages/linux-asahi/default.nix @@ -1,6 +1,6 @@ { lib +, pkgs , callPackage -, runCommand , writeShellScriptBin , writeText , linuxPackagesFor @@ -10,6 +10,16 @@ }: let + # TODO: use a pure nix regex parser instead of an IFD, and remove this workaround + localPkgs = if builtins ? currentSystem + then import (pkgs.path) { + crossSystem.system = builtins.currentSystem; + localSystem.system = builtins.currentSystem; + } + else pkgs; + + inherit (localPkgs) runCommand; + parseExtraConfig = cfg: let lines = builtins.filter (s: s != "") (lib.strings.splitString "\n" cfg); perLine = line: let diff --git a/apple-silicon-support/packages/m1n1/default.nix b/apple-silicon-support/packages/m1n1/default.nix index da666640..ee5450fd 100644 --- a/apple-silicon-support/packages/m1n1/default.nix +++ b/apple-silicon-support/packages/m1n1/default.nix @@ -89,11 +89,11 @@ EOF GCC=${buildPackages.gcc} BINUTILS=${buildPackages.binutils-unwrapped} - ln -s $GCC/bin/*-gcc $out/toolchain-bin/ - ln -s $GCC/bin/*-ld $out/toolchain-bin/ - ln -s $BINUTILS/bin/*-objcopy $out/toolchain-bin/ - ln -s $BINUTILS/bin/*-objdump $out/toolchain-bin/ - ln -s $GCC/bin/*-nm $out/toolchain-bin/ + 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 ''; From 27ff0705a6b26631e10dc8dfb73e47e4bf2342d7 Mon Sep 17 00:00:00 2001 From: Erin <79354991+oati@users.noreply.github.com> Date: Mon, 30 Jan 2023 10:23:19 -0600 Subject: [PATCH 21/21] fix mesa overlay --- apple-silicon-support/packages/overlay.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple-silicon-support/packages/overlay.nix b/apple-silicon-support/packages/overlay.nix index 90549520..635a41db 100644 --- a/apple-silicon-support/packages/overlay.nix +++ b/apple-silicon-support/packages/overlay.nix @@ -3,6 +3,6 @@ final: prev: { m1n1 = final.callPackage ./m1n1 { }; uboot-asahi = final.callPackage ./uboot-asahi { }; asahi-fwextract = final.callPackage ./asahi-fwextract { }; - mesa-asahi-edge = final.callPackage ./mesa-asahi-edge { }; + mesa-asahi-edge = final.callPackage ./mesa-asahi-edge { inherit (prev) mesa; }; # TODO: package alsa-ucm-conf-asahi for headphone jack support }