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 16 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
9 changes: 0 additions & 9 deletions default.nix

This file was deleted.

115 changes: 115 additions & 0 deletions flake.lock

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

69 changes: 69 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
description = "Apple M1 support for NixOS";
oati marked this conversation as resolved.
Show resolved Hide resolved

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
tpwrules marked this conversation as resolved.
Show resolved Hide resolved
rust-overlay.url = "github:oxalica/rust-overlay";
flake-parts.url = "github:hercules-ci/flake-parts";
oati marked this conversation as resolved.
Show resolved Hide resolved
};

outputs = { self, flake-parts, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } (
{ withSystem, ... }: {
flake = {
overlays = rec {
asahi-overlay = import packages/overlay.nix;
default = asahi-overlay;
};

nixosModules = rec {
m1-support = ./nixos-module;
default = m1-support;
};
};

# build platforms supported for uboot in nixpkgs
systems = [ "aarch64-linux" "x86_64-linux" "i686-linux" ];
oati marked this conversation as resolved.
Show resolved Hide resolved

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
];
};

packages = {
inherit (pkgs) m1n1 uboot-asahi;
Copy link
Owner

Choose a reason for hiding this comment

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

Is it safe to inherit the kernel package here too? Being able to directly build the kernel and the configured-for-boot u-boot/m1n1 was the reason I had the config initially exposed but it sounds like that causes problems in the flake.

If not I will figure it out later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue I had with outputting the kernel package was NixOS/nix#4265, which also breaks nix flake show. Luckily we should be able to get rid of the IFD using pure nix, as I've mentioned below.

We could also output the installer config, but I think it's not as clear where the config should go in the output, especially since we need to account for different possible build platforms, so I wanted to avoid it if possible.


installer-bootstrap =
let
installer-system = inputs.nixpkgs.lib.nixosSystem {
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
{ hardware.asahi.pkgsSystem = system; }
];
};
in installer-system.config.system.build.isoImage;
};
};
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
{
imports = [
./installer-configuration.nix
../m1-support
../nixos-module
];

# 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
# directory for their own config.
installer.cloneConfigIncludes = [
"./installer-configuration.nix"
"./m1-support"
"./m1-support/nixos-module"
];

# copy the m1-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
cp ${./installer-configuration.nix} /etc/nixos/installer-configuration.nix
cp -r ${../m1-support} /etc/nixos/m1-support
cp -r ${../packages} ${../nixos-module} -t /etc/nixos/m1-support
tpwrules marked this conversation as resolved.
Show resolved Hide resolved
fi
'';
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
fileSystems = lib.mkOverride 60 config.lib.isoFileSystems;

boot.postBootCommands = let
asahi-fwextract = pkgs.callPackage ../m1-support/asahi-fwextract {};
inherit (config.hardware.asahi.pkgs) asahi-fwextract;
in ''
for o in $(</proc/cmdline); do
case "$o" in
Expand Down Expand Up @@ -61,13 +61,13 @@

isoImage.squashfsCompression = "zstd -Xcompression-level 6";

environment.systemPackages = [
pkgs.gptfdisk
pkgs.parted
pkgs.cryptsetup
pkgs.curl
pkgs.wget
pkgs.wormhole-william
environment.systemPackages = with pkgs; [
gptfdisk
parted
cryptsetup
curl
wget
wormhole-william
];

# save space and compilation time. might revise?
Expand Down
12 changes: 0 additions & 12 deletions nix/installer-bootstrap/default.nix

This file was deleted.

20 changes: 0 additions & 20 deletions nix/overlay.nix

This file was deleted.

15 changes: 0 additions & 15 deletions nix/pins.nix

This file was deleted.

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
38 changes: 30 additions & 8 deletions nix/m1-support/default.nix → nixos-module/default.nix
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;
};
tpwrules marked this conversation as resolved.
Show resolved Hide resolved

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
File renamed without changes.
Loading