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

Flake support, project reorganization, asahi overlay #47

Merged
merged 21 commits into from
Jan 31, 2023
Merged
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
7 changes: 7 additions & 0 deletions apple-silicon-support/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ ... }:

{
imports = [
./modules/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'.uboot-asahi.override {
m1n1 = bootM1n1;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,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
cfg = config.hardware.asahi;
in {
nixpkgs.overlays = lib.mkBefore [ cfg.overlay ];

hardware.asahi.pkgs =
if cfg.pkgsSystem != "aarch64-linux"
then
import (pkgs.path) {
crossSystem.system = "aarch64-linux";
localSystem.system = cfg.pkgsSystem;
overlays = [ cfg.overlay ];
}
else pkgs;
};

options.hardware.asahi = {
pkgsSystem = lib.mkOption {
Expand All @@ -35,5 +43,19 @@
with the system defined by `hardware.asahi.pkgsSystem`.
'';
};

overlay = lib.mkOption {
type = lib.mkOptionType {
name = "nixpkgs-overlay";
description = "nixpkgs overlay";
check = lib.isFunction;
merge = lib.mergeOneOption;
};
default = import ../packages/overlay.nix;
defaultText = "overlay provided with the module";
description = ''
The nixpkgs overlay for asahi packages.
'';
};
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
{ config, pkgs, lib, ... }:
{
config = {
boot.kernelPackages = config.hardware.asahi.pkgs.callPackage ./package.nix {
inherit (config.boot) kernelPatches;
_4KBuild = config.hardware.asahi.use4KPages;
withRust = config.hardware.asahi.withRust;
};
boot.kernelPackages = let
pkgs' = config.hardware.asahi.pkgs;
in
pkgs'.linux-asahi.override {
inherit (config.boot) kernelPatches;
_4KBuild = config.hardware.asahi.use4KPages;
withRust = config.hardware.asahi.withRust;
};

# we definitely want to use CONFIG_ENERGY_MODEL, and
# schedutil is a prerequisite for using it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
&& config.hardware.asahi.experimentalGPUInstallMode == mode);
in lib.mkMerge [
(lib.mkIf config.hardware.asahi.useExperimentalGPUDriver {
# make the Asahi Mesa available via an overlay so the user has access to it
# (being careful not to create infinite recursion if the user wants to overlay
# it over the original Mesa)
nixpkgs.overlays = [
(final: prev: {
mesa-asahi-edge = final.callPackage ./package.nix { inherit (prev) mesa; };
})
];

# install the drivers
hardware.opengl.package = pkgs.mesa-asahi-edge.drivers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@
];

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

nativeBuildInputs = [ asahi-fwextract pkgs.cpio ];
nativeBuildInputs = [ pkgs'.asahi-fwextract pkgs.cpio ];

buildCommand = ''
mkdir extracted
asahi-fwextract ${config.hardware.asahi.peripheralFirmwareDirectory} extracted
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
'';
})
];
mkdir -p $out/lib/firmware
cat extracted/firmware.cpio | cpio -id --quiet --no-absolute-filenames
mv vendorfw/* $out/lib/firmware
'';
})
];
};

options.hardware.asahi = {
Expand All @@ -43,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"
/boot/asahi
# path when the system is mounted in the installer
"/mnt/boot/asahi"
/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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
{ 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; }
{ lib
, pkgs
, callPackage
, writeShellScriptBin
, writeText
, linuxPackagesFor
, _4KBuild ? false
, withRust ? false
, kernelPatches ? [ ]
}:

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;

lib = localPkgs.lib;
inherit (localPkgs) runCommand;

parseExtraConfig = cfg: let
lines = builtins.filter (s: s != "") (lib.strings.splitString "\n" cfg);
Expand All @@ -15,7 +28,7 @@
"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" { } ''
Copy link
Owner

Choose a reason for hiding this comment

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

This has definitely broken hardware.asahi.buildPkgs. I am pretty sure the above comment is wrong. The real issue is that the config.nix file does not make its way to the ISO. Thus, when the configuration is evaluated, the runCommand needs to be executed to get the complete source code, but runCommand expects to run on a hardware.asahi.buildPkgs system and fails.

I want to keep the localPkgs hack for now (we don't need lib = localPkgs.lib though) and fix it later. That option will still be broken as it was for flakes users before, but it will be fine for the install scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the solution is to replace the "config.nix" IFD with a pure nix regex parser. It seems like it'll be pretty straightforward, and it can be upstreamed to nixpkgs since nixpkgs also uses an IFD currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

opened #51

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added back the localPkgs workaround for now.

echo "{ } // " > "$out"
while IFS='=' read key val; do
[ "x''${key#CONFIG_}" != "x$key" ] || continue
Expand All @@ -25,16 +38,16 @@
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
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
Expand Down Expand Up @@ -82,7 +95,7 @@
# 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 "$@"
'')
];
Expand All @@ -96,6 +109,6 @@
'';
} 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)

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ stdenv
, buildPackages
, lib
, fetchFromGitHub
, pkgsCross
, python3
, dtc
, imagemagick
Expand Down Expand Up @@ -36,13 +36,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
buildPackages.gcc
] ++ lib.optional withChainloading rustenv
++ lib.optional (customLogo != null) imagemagick;

Expand Down Expand Up @@ -86,14 +86,14 @@ EOF
chmod +x $script
done

GCC=${pkgsCross.aarch64-multiplatform.buildPackages.gcc}
BINUTILS=${pkgsCross.aarch64-multiplatform.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/
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
'';
Expand Down
8 changes: 8 additions & 0 deletions apple-silicon-support/packages/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
final: prev: {
linux-asahi = final.callPackage ./linux-asahi { };
m1n1 = final.callPackage ./m1n1 { };
uboot-asahi = final.callPackage ./uboot-asahi { };
asahi-fwextract = final.callPackage ./asahi-fwextract { };
mesa-asahi-edge = final.callPackage ./mesa-asahi-edge { inherit (prev) mesa; };
# TODO: package alsa-ucm-conf-asahi for headphone jack support
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{ lib
, fetchFromGitHub
, fetchpatch
, pkgs
, pkgsCross
, buildUBoot
, 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 {
}:

(buildUBoot rec {
src = fetchFromGitHub {
# tracking: https://github.com/AsahiLinux/PKGBUILDs/blob/stable/uboot-asahi/PKGBUILD
owner = "AsahiLinux";
Expand Down
9 changes: 0 additions & 9 deletions default.nix

This file was deleted.

44 changes: 44 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading