Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#34 Introduce asahi overlay #35

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ let
pins = import ./nix/pins.nix;
overlays = [
(import ./nix/overlay.nix)
(import ./nix/m1-support/overlay.nix) # our packages ambient
(import pins.rust-overlay)
];
in {
Expand Down
11 changes: 6 additions & 5 deletions nix/installer-bootstrap/installer-configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
# https://github.com/samueldr/cross-system/blob/master/configuration.nix

{ config, pkgs, lib, modulesPath, ... }:

{
let
pkgs' = config.hardware.asahi.pkgs;
in {
imports = [
(modulesPath + "/profiles/minimal.nix")
(modulesPath + "/profiles/installation-device.nix")
Expand All @@ -29,13 +30,13 @@
fileSystems = lib.mkOverride 60 config.lib.isoFileSystems;

boot.postBootCommands = let
asahi-fwextract = pkgs.callPackage ../m1-support/asahi-fwextract {};
inherit (pkgs') asahi-fwextract shadow cpio;
in ''
for o in $(</proc/cmdline); do
case "$o" in
live.nixos.passwd=*)
set -- $(IFS==; echo $o)
echo "nixos:$2" | ${pkgs.shadow}/bin/chpasswd
echo "nixos:$2" | ${shadow}/bin/chpasswd
;;
esac
done
Expand All @@ -48,7 +49,7 @@
umount /tmp/.fwsetup/esp

pushd /tmp/.fwsetup/
cat /tmp/.fwsetup/extracted/firmware.cpio | ${pkgs.cpio}/bin/cpio -id --quiet --no-absolute-filenames
cat /tmp/.fwsetup/extracted/firmware.cpio | ${cpio}/bin/cpio -id --quiet --no-absolute-filenames
mkdir -p /lib/firmware
mv vendorfw/* /lib/firmware
popd
Expand Down
6 changes: 4 additions & 2 deletions nix/m1-support/boot-m1n1/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{ config, pkgs, lib, ... }:
let
bootM1n1 = config.hardware.asahi.pkgs.callPackage ../m1n1 {
pkgs' = config.hardware.asahi.pkgs;

bootM1n1 = pkgs'.m1n1.override {
isRelease = true;
withTools = false;
customLogo = config.boot.m1n1CustomLogo;
};

bootUBoot = config.hardware.asahi.pkgs.callPackage ../u-boot {
bootUBoot = pkgs'.u-boot.override {
m1n1 = bootM1n1;
};

Expand Down
24 changes: 16 additions & 8 deletions nix/m1-support/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
./boot-m1n1
];

config = {
hardware.asahi.pkgs = if config.hardware.asahi.pkgsSystem != "aarch64-linux"
then import (pkgs.path) {
system = config.hardware.asahi.pkgsSystem;
crossSystem.system = "aarch64-linux";
}
else pkgs;
};
config =
let
tweaks =
if config.hardware.asahi.pkgsSystem == "aarch64-linux"
then {}
else {
system = config.hardware.asahi.pkgsSystem;
crossSystem.system = "aarch64-linux";
};

overlays = [
(import ./overlay.nix)
];
in {
hardware.asahi.pkgs = import pkgs.path (tweaks // { inherit overlays; });
};

options.hardware.asahi = {
pkgsSystem = lib.mkOption {
Expand Down
6 changes: 4 additions & 2 deletions nix/m1-support/kernel/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# the Asahi Linux kernel and options that must go along with it

{ config, pkgs, lib, ... }:
{
let
pkgs' = config.hardware.asahi.pkgs;
in {
config = {
boot.kernelPackages = config.hardware.asahi.pkgs.callPackage ./package.nix {
boot.kernelPackages = pkgs'.asahi-kernel.override {
inherit (config.boot) kernelPatches;
_4KBuild = config.hardware.asahi.use4KPages;
};
Expand Down
12 changes: 12 additions & 0 deletions nix/m1-support/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
self: super:
{
# nb. below may actually *require* overrides to reference
# nb. inconsistecy of pkg definition location is a smell
asahi-fwextract = self.callPackage ./asahi-fwextract {};
boot-m1n1 = self.callPackage ./boot-m1n1 {};
asahi-kernel = self.callPackage ./kernel/package.nix {};
m1n1 = self.callPackage ./m1n1 {};
peripheral-firmware = self.callPackage ./peripheral-firmware/package.nix {};
u-boot = self.callPackage ./u-boot {};
}

28 changes: 10 additions & 18 deletions nix/m1-support/peripheral-firmware/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{ config, pkgs, lib, ... }:
{
let
pkgs' = config.hardware.asahi.pkgs;
in {
config = {
assertions = lib.mkIf config.hardware.asahi.extractPeripheralFirmware [
{ assertion = config.hardware.asahi.peripheralFirmwareDirectory != null;
Expand All @@ -10,24 +12,14 @@
}
];

hardware.firmware = let
asahi-fwextract = pkgs.callPackage ../asahi-fwextract {};
in lib.mkIf ((config.hardware.asahi.peripheralFirmwareDirectory != null)
hardware.firmware = lib.mkIf (
(config.hardware.asahi.peripheralFirmwareDirectory != null)
&& config.hardware.asahi.extractPeripheralFirmware) [
(pkgs.stdenv.mkDerivation {
name = "asahi-peripheral-firmware";

nativeBuildInputs = [ asahi-fwextract pkgs.cpio ];

buildCommand = ''
mkdir extracted
asahi-fwextract ${/. + config.hardware.asahi.peripheralFirmwareDirectory} extracted

mkdir -p $out/lib/firmware
cat extracted/firmware.cpio | cpio -id --quiet --no-absolute-filenames
mv vendorfw/* $out/lib/firmware
'';
})
(
pkgs'.peripheral-firmware.override {
inherit (config.hardware.asahi) peripheralFirmwareDirectory;
}
)
];
};

Expand Down
18 changes: 18 additions & 0 deletions nix/m1-support/peripheral-firmware/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ pkgs
, peripheralFirmwareDirectory ? null # is this a smell?
,... }:
pkgs.stdenv.mkDerivation {
name = "asahi-peripheral-firmware";

nativeBuildInputs = with pkgs; [ asahi-fwextract cpio ];

buildCommand = ''
mkdir extracted
asahi-fwextract ${/. + peripheralFirmwareDirectory} extracted

mkdir -p $out/lib/firmware
cat extracted/firmware.cpio | cpio -id --quiet --no-absolute-filenames
mv vendorfw/* $out/lib/firmware
'';
}

4 changes: 0 additions & 4 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ in {
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;

Expand Down