diff --git a/common/editors/emacs.nix b/common/editors/emacs.nix index 15944a7..17c7db7 100644 --- a/common/editors/emacs.nix +++ b/common/editors/emacs.nix @@ -1,11 +1,13 @@ -{ config, lib, pkgs, inputs, outputs, ... }: - { - - services.emacs = - { + config, + lib, + pkgs, + inputs, + outputs, + ... +}: { + services.emacs = { enable = true; package = pkgs.emacs; # replace with emacs-gtk, or a version provided by the community overlay if desired. - }; - + }; } diff --git a/common/gui/common.nix b/common/gui/common.nix index 88f659b..185fb4e 100644 --- a/common/gui/common.nix +++ b/common/gui/common.nix @@ -1,11 +1,14 @@ -{ config, lib, pkgs, inputs, outputs, ... }: - { - + config, + lib, + pkgs, + inputs, + outputs, + ... +}: { # Enable the X11 windowing system. services.xserver.enable = true; - # Configure keymap in X11 services.xserver = { layout = "us"; @@ -21,5 +24,4 @@ hardware.bluetooth.enable = true; programs.sway.enable = true; - } diff --git a/common/gui/hyprland.nix b/common/gui/hyprland.nix index 7c4196e..737641b 100644 --- a/common/gui/hyprland.nix +++ b/common/gui/hyprland.nix @@ -1,12 +1,14 @@ -{ config, pkgs, inputs, ... }: - { - imports = - [ - ./common.nix - ]; + config, + pkgs, + inputs, + ... +}: { + imports = [ + ./common.nix + ]; -# XDG Portals + # XDG Portals xdg = { autostart.enable = true; portal = { @@ -25,13 +27,13 @@ ''; }; }; -# Services + # Services services = { xserver = { enable = true; layout = "us"; xkbVariant = ""; - excludePackages = [ pkgs.xterm ]; + excludePackages = [pkgs.xterm]; videoDrivers = ["amdgpu"]; libinput = { enable = true; @@ -84,7 +86,7 @@ waybar = { enable = true; package = pkgs.waybar.overrideAttrs (oldAttrs: { - mesonFlags = oldAttrs.mesonFlags ++ [ "-Dexperimental=true" ]; + mesonFlags = oldAttrs.mesonFlags ++ ["-Dexperimental=true"]; }); }; thunar = { @@ -148,6 +150,5 @@ GTK_USE_PORTAL = "1"; NIXOS_XDG_OPEN_USE_PORTAL = "1"; WLR_NO_HARDWARE_CURSOR = "1"; - }; - + }; } diff --git a/common/networking/zerotier.nix b/common/networking/zerotier.nix index 45fd040..464ba90 100644 --- a/common/networking/zerotier.nix +++ b/common/networking/zerotier.nix @@ -1,17 +1,19 @@ -{ config, lib, pkgs, inputs, outputs, ... }: - { - + config, + lib, + pkgs, + inputs, + outputs, + ... +}: { services.zerotierone = { joinNetworks = [ "4e72329aec6688e3" ]; enable = true; - }; - networking.extraHosts = - '' + networking.extraHosts = '' 192.168.194.109 planex.far 192.168.194.210 farnsworth.far 192.168.194.24 zapp.far @@ -20,5 +22,4 @@ 192.168.194.38 cubert.far ''; - } diff --git a/common/nixos/common.nix b/common/nixos/common.nix index 0ffbf90..747a785 100644 --- a/common/nixos/common.nix +++ b/common/nixos/common.nix @@ -1,24 +1,28 @@ -{ config, lib, pkgs, inputs, outputs, ... }: - { - imports = - [ - ./packages.nix - ./users.nix - ./locale.nix - ]; + config, + lib, + pkgs, + inputs, + outputs, + ... +}: { + imports = [ + ./packages.nix + ./users.nix + ./locale.nix + ]; # nixpkgs.config.allowUnfree = true; - nix.settings.experimental-features = [ "nix-command" "flakes" ]; + nix.settings.experimental-features = ["nix-command" "flakes"]; nix.settings.auto-optimise-store = true; nix.optimise.automatic = true; nix.gc = { - automatic = true; - dates = "weekly"; - options = "--delete-older-than 14d"; + automatic = true; + dates = "weekly"; + options = "--delete-older-than 14d"; }; # This value determines the NixOS release from which the default @@ -28,5 +32,4 @@ # Before changing this value read the documentation for this option # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). system.stateVersion = "23.11"; # Did you read the comment? - } diff --git a/common/nixos/locale.nix b/common/nixos/locale.nix index 65d95f7..e1566ae 100644 --- a/common/nixos/locale.nix +++ b/common/nixos/locale.nix @@ -1,7 +1,11 @@ -{ config, lib, pkgs, inputs, outputs, ... }: - { - + config, + lib, + pkgs, + inputs, + outputs, + ... +}: { # Set your time zone. time.timeZone = "America/Los_Angeles"; @@ -19,5 +23,4 @@ LC_TELEPHONE = "en_US.UTF-8"; LC_TIME = "en_US.UTF-8"; }; - } diff --git a/common/nixos/packages.nix b/common/nixos/packages.nix index 8b10a73..7e34095 100644 --- a/common/nixos/packages.nix +++ b/common/nixos/packages.nix @@ -1,7 +1,11 @@ -{ config, lib, pkgs, inputs, outputs, ... }: - { - + config, + lib, + pkgs, + inputs, + outputs, + ... +}: { # Some programs need SUID wrappers, can be configured further or are # started in user sessions. programs.gnupg.agent = { @@ -9,7 +13,6 @@ enableSSHSupport = true; }; - # List packages installed in system profile. To search, run: # $ nix search wget environment.systemPackages = with pkgs; [ @@ -20,5 +23,4 @@ home-manager yadm ]; - } diff --git a/common/nixos/users.nix b/common/nixos/users.nix index 841a192..265f1d7 100644 --- a/common/nixos/users.nix +++ b/common/nixos/users.nix @@ -1,17 +1,20 @@ -{ config, lib, pkgs, inputs, outputs, ... }: - { - + config, + lib, + pkgs, + inputs, + outputs, + ... +}: { # Define a user account. Don't forget to set a password with 'passwd'. programs.zsh.enable = true; users.users.kdb424 = { isNormalUser = true; description = "Kyle Brown"; - extraGroups = [ "networkmanager" "wheel" ]; + extraGroups = ["networkmanager" "wheel"]; shell = pkgs.zsh; packages = with pkgs; [ yadm ]; }; - } diff --git a/flake.nix b/flake.nix index 0b8d490..2d3a254 100644 --- a/flake.nix +++ b/flake.nix @@ -12,7 +12,7 @@ # Home manager home-manager.url = "github:nix-community/home-manager"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; - + darwin = { url = "github:lnl7/nix-darwin"; inputs.nixpkgs.follows = "nixpkgs"; @@ -32,79 +32,85 @@ }; }; - outputs = { self, nixpkgs, home-manager, ... }@inputs: - let - inherit (self) outputs; - forAllSystems = nixpkgs.lib.genAttrs [ - "aarch64-linux" - "i686-linux" - "x86_64-linux" - "aarch64-darwin" - "x86_64-darwin" - ]; + outputs = { + self, + nixpkgs, + home-manager, + ... + } @ inputs: let + inherit (self) outputs; + forAllSystems = nixpkgs.lib.genAttrs [ + "aarch64-linux" + "i686-linux" + "x86_64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; - mkNixos = modules: nixpkgs.lib.nixosSystem { + mkNixos = modules: + nixpkgs.lib.nixosSystem { inherit modules; - specialArgs = { inherit inputs outputs; }; + specialArgs = {inherit inputs outputs;}; }; - mkDarwin = system: modules: inputs.darwin.lib.darwinSystem { + mkDarwin = system: modules: + inputs.darwin.lib.darwinSystem { inherit modules system inputs; - specialArgs = { inherit inputs outputs; }; + specialArgs = {inherit inputs outputs;}; }; - mkHome = modules: pkgs: home-manager.lib.homeManagerConfiguration { + mkHome = modules: pkgs: + home-manager.lib.homeManagerConfiguration { inherit modules pkgs; - extraSpecialArgs = { inherit inputs outputs; }; + extraSpecialArgs = {inherit inputs outputs;}; }; - in - rec { - # Your custom packages - # Acessible through 'nix build', 'nix shell', etc - #packages = forAllSystems (system: - # let pkgs = nixpkgs.legacyPackages.${system}; - # in import ./pkgs { inherit pkgs; } - #); - # Devshell for bootstrapping - # Acessible through 'nix develop' or 'nix-shell' (legacy) - devShells = forAllSystems (system: - let pkgs = nixpkgs.legacyPackages.${system}; - in import ./shell.nix { inherit pkgs; } - ); + in rec { + # Your custom packages + # Acessible through 'nix build', 'nix shell', etc + #packages = forAllSystems (system: + # let pkgs = nixpkgs.legacyPackages.${system}; + # in import ./pkgs { inherit pkgs; } + #); + # Devshell for bootstrapping + # Acessible through 'nix develop' or 'nix-shell' (legacy) + devShells = forAllSystems ( + system: let + pkgs = nixpkgs.legacyPackages.${system}; + in + import ./shell.nix {inherit pkgs;} + ); - # Your custom packages and modifications, exported as overlays - overlays = import ./overlays { inherit inputs; }; - # Reusable nixos modules you might want to export - # These are usually stuff you would upstream into nixpkgs - #nixosModules = import ./modules/nixos; - # Reusable home-manager modules you might want to export - # These are usually stuff you would upstream into home-manager - #homeManagerModules = import ./modules/home-manager; + # Your custom packages and modifications, exported as overlays + overlays = import ./overlays {inherit inputs;}; + # Reusable nixos modules you might want to export + # These are usually stuff you would upstream into nixpkgs + #nixosModules = import ./modules/nixos; + # Reusable home-manager modules you might want to export + # These are usually stuff you would upstream into home-manager + #homeManagerModules = import ./modules/home-manager; - # NixOS configuration entrypoint - # Available through 'nixos-rebuild --flake .#your-hostname' - nixosConfigurations = { - # M1 mac mini - farnsworth = mkNixos [ ./hosts/farnsworth ]; + # NixOS configuration entrypoint + # Available through 'nixos-rebuild --flake .#your-hostname' + nixosConfigurations = { + # M1 mac mini + farnsworth = mkNixos [./hosts/farnsworth]; - # Laptop - amy = mkNixos [ ./hosts/amy ]; - - }; - - #darwinConfigurations = { - # 14" M1-Pro macbook - #sef-macbook = mkDarwin "aarch64-darwin" [ ./darwin/hosts/macbook.nix ]; - - # 16" intel MBP (ShareFile dev) - #AMERMACC02FC2U2MD6R = mkDarwin "x86_64-darwin" [ ./darwin/hosts/work-macbook.nix ]; - #}; - - # Standalone home-manager configuration entrypoint - # Available through 'home-manager --flake .#your-username@your-hostname' - #homeConfigurations = { - # TODO: add generic standalone home-manager config - #}; + # Laptop + amy = mkNixos [./hosts/amy]; }; -} + #darwinConfigurations = { + # 14" M1-Pro macbook + #sef-macbook = mkDarwin "aarch64-darwin" [ ./darwin/hosts/macbook.nix ]; + + # 16" intel MBP (ShareFile dev) + #AMERMACC02FC2U2MD6R = mkDarwin "x86_64-darwin" [ ./darwin/hosts/work-macbook.nix ]; + #}; + + # Standalone home-manager configuration entrypoint + # Available through 'home-manager --flake .#your-username@your-hostname' + #homeConfigurations = { + # TODO: add generic standalone home-manager config + #}; + }; +} diff --git a/hosts/amy/default.nix b/hosts/amy/default.nix index bf28123..fcefe20 100644 --- a/hosts/amy/default.nix +++ b/hosts/amy/default.nix @@ -1,18 +1,22 @@ # Edit this configuration file to define what should be installed on # your system. Help is available in the configuration.nix(5) man page, on # https://search.nixos.org/options and in the NixOS manual (`nixos-help`). - -{ config, lib, pkgs, inputs, outputs, ... }: - { - imports = - [ # Include the results of the hardware scan. - ./hardware-configuration.nix - ../../common/nixos/common.nix - ../../common/networking/zerotier.nix - ../../common/gui/hyprland.nix - ../../common/editors/emacs.nix - ]; + config, + lib, + pkgs, + inputs, + outputs, + ... +}: { + imports = [ + # Include the results of the hardware scan. + ./hardware-configuration.nix + ../../common/nixos/common.nix + ../../common/networking/zerotier.nix + ../../common/gui/hyprland.nix + ../../common/editors/emacs.nix + ]; # Use the systemd-boot EFI boot loader. boot.loader.systemd-boot.enable = true; @@ -25,5 +29,4 @@ # Enable the OpenSSH daemon. services.openssh.enable = true; - } diff --git a/hosts/amy/hardware-configuration.nix b/hosts/amy/hardware-configuration.nix index a2eab6d..ddeb3de 100644 --- a/hosts/amy/hardware-configuration.nix +++ b/hosts/amy/hardware-configuration.nix @@ -1,36 +1,42 @@ # Do not modify this file! It was generated by ‘nixos-generate-config’ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. -{ config, lib, pkgs, modulesPath, ... }: - { - imports = - [ (modulesPath + "/installer/scan/not-detected.nix") - ]; + config, + lib, + pkgs, + modulesPath, + ... +}: { + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; - boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-amd" ]; - boot.extraModulePackages = [ ]; - boot.kernelParams = [ "psmouse.synaptics_intertouch=0" ]; + boot.initrd.availableKernelModules = ["nvme" "xhci_pci" "ahci" "usb_storage" "sd_mod" "rtsx_pci_sdmmc"]; + boot.initrd.kernelModules = []; + boot.kernelModules = ["kvm-amd"]; + boot.extraModulePackages = []; + boot.kernelParams = ["psmouse.synaptics_intertouch=0"]; - fileSystems."/" = - { device = "/dev/disk/by-uuid/965d7442-87cd-430b-ba33-b5022a88dda3"; - fsType = "ext4"; - }; + fileSystems."/" = { + device = "/dev/disk/by-uuid/965d7442-87cd-430b-ba33-b5022a88dda3"; + fsType = "ext4"; + }; boot.initrd.luks.devices."luks-4613d281-839b-483b-bb3c-6b151a43bf68".device = "/dev/disk/by-uuid/4613d281-839b-483b-bb3c-6b151a43bf68"; - fileSystems."/boot" = - { device = "/dev/disk/by-uuid/6B1C-C4A0"; - fsType = "vfat"; - }; + fileSystems."/boot" = { + device = "/dev/disk/by-uuid/6B1C-C4A0"; + fsType = "vfat"; + }; - swapDevices = [ { - device = "/var/lib/swapfile"; - size = 8*1024; - randomEncryption.enable = true; - } ]; + swapDevices = [ + { + device = "/var/lib/swapfile"; + size = 8 * 1024; + randomEncryption.enable = true; + } + ]; zramSwap = { enable = true; diff --git a/hosts/farnsworth/apple-silicon-support/default.nix b/hosts/farnsworth/apple-silicon-support/default.nix index 71a5dd0..3da8f37 100644 --- a/hosts/farnsworth/apple-silicon-support/default.nix +++ b/hosts/farnsworth/apple-silicon-support/default.nix @@ -1,6 +1,4 @@ -{ ... }: - -{ +{...}: { imports = [ ./modules/default.nix ]; diff --git a/hosts/farnsworth/apple-silicon-support/modules/boot-m1n1/default.nix b/hosts/farnsworth/apple-silicon-support/modules/boot-m1n1/default.nix index 39e94c5..69fc70a 100644 --- a/hosts/farnsworth/apple-silicon-support/modules/boot-m1n1/default.nix +++ b/hosts/farnsworth/apple-silicon-support/modules/boot-m1n1/default.nix @@ -1,5 +1,9 @@ -{ config, pkgs, lib, ... }: -let +{ + config, + pkgs, + lib, + ... +}: let pkgs' = config.hardware.asahi.pkgs; bootM1n1 = pkgs'.m1n1.override { @@ -29,7 +33,7 @@ in { boot.loader.systemd-boot.extraFiles = bootFiles; # ensure the installer has m1n1 in the image - system.extraDependencies = lib.mkForce [ bootM1n1 bootUBoot ]; + system.extraDependencies = lib.mkForce [bootM1n1 bootUBoot]; system.build.m1n1 = bootFiles."m1n1/boot.bin"; }; diff --git a/hosts/farnsworth/apple-silicon-support/modules/default.nix b/hosts/farnsworth/apple-silicon-support/modules/default.nix index d6f3976..4b9b3ae 100644 --- a/hosts/farnsworth/apple-silicon-support/modules/default.nix +++ b/hosts/farnsworth/apple-silicon-support/modules/default.nix @@ -1,5 +1,9 @@ -{ config, pkgs, lib, ... }: { + config, + pkgs, + lib, + ... +}: { imports = [ ./kernel ./mesa @@ -8,22 +12,21 @@ ./sound ]; - config = - let - cfg = config.hardware.asahi; - in { - nixpkgs.overlays = lib.mkBefore [ cfg.overlay ]; + 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; - }; + 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 { diff --git a/hosts/farnsworth/apple-silicon-support/modules/kernel/default.nix b/hosts/farnsworth/apple-silicon-support/modules/kernel/default.nix index 26d920f..98f9968 100644 --- a/hosts/farnsworth/apple-silicon-support/modules/kernel/default.nix +++ b/hosts/farnsworth/apple-silicon-support/modules/kernel/default.nix @@ -1,7 +1,10 @@ # the Asahi Linux kernel and options that must go along with it - -{ config, pkgs, lib, ... }: { + config, + pkgs, + lib, + ... +}: { config = { boot.kernelPackages = let pkgs' = config.hardware.asahi.pkgs; diff --git a/hosts/farnsworth/apple-silicon-support/modules/kernel/edge.nix b/hosts/farnsworth/apple-silicon-support/modules/kernel/edge.nix index 83abda6..b576571 100644 --- a/hosts/farnsworth/apple-silicon-support/modules/kernel/edge.nix +++ b/hosts/farnsworth/apple-silicon-support/modules/kernel/edge.nix @@ -1,7 +1,10 @@ # the Asahi Linux edge config and options that must go along with it - -{ config, pkgs, lib, ... }: { + config, + pkgs, + lib, + ... +}: { config = lib.mkIf config.hardware.asahi.addEdgeKernelConfig { boot.kernelPatches = [ { diff --git a/hosts/farnsworth/apple-silicon-support/modules/mesa/default.nix b/hosts/farnsworth/apple-silicon-support/modules/mesa/default.nix index 5c53ba3..cfa6147 100644 --- a/hosts/farnsworth/apple-silicon-support/modules/mesa/default.nix +++ b/hosts/farnsworth/apple-silicon-support/modules/mesa/default.nix @@ -1,37 +1,42 @@ -{ config, pkgs, lib, ... }: { + config, + pkgs, + lib, + ... +}: { config = let isMode = mode: (config.hardware.asahi.useExperimentalGPUDriver - && config.hardware.asahi.experimentalGPUInstallMode == mode); - in lib.mkMerge [ - (lib.mkIf config.hardware.asahi.useExperimentalGPUDriver { + && config.hardware.asahi.experimentalGPUInstallMode == mode); + in + lib.mkMerge [ + (lib.mkIf config.hardware.asahi.useExperimentalGPUDriver { + # install the drivers + hardware.opengl.package = config.hardware.asahi.pkgs.mesa-asahi-edge.drivers; - # install the drivers - hardware.opengl.package = config.hardware.asahi.pkgs.mesa-asahi-edge.drivers; - - # required for GPU kernel driver - hardware.asahi.addEdgeKernelConfig = true; - }) - (lib.mkIf (isMode "replace") { - # replace the Mesa linked into system packages with the Asahi version - # without rebuilding them to avoid rebuilding the world. - system.replaceRuntimeDependencies = [ - { original = pkgs.mesa; - replacement = config.hardware.asahi.pkgs.mesa-asahi-edge; - } - ]; - }) - (lib.mkIf (isMode "overlay") { - # replace the Mesa used in Nixpkgs with the Asahi version using an overlay, - # which requires rebuilding the world but ensures it is done faithfully - # (and in a way compatible with pure evaluation) - nixpkgs.overlays = [ - (final: prev: { - mesa = final.mesa-asahi-edge; - }) - ]; - }) - ]; + # required for GPU kernel driver + hardware.asahi.addEdgeKernelConfig = true; + }) + (lib.mkIf (isMode "replace") { + # replace the Mesa linked into system packages with the Asahi version + # without rebuilding them to avoid rebuilding the world. + system.replaceRuntimeDependencies = [ + { + original = pkgs.mesa; + replacement = config.hardware.asahi.pkgs.mesa-asahi-edge; + } + ]; + }) + (lib.mkIf (isMode "overlay") { + # replace the Mesa used in Nixpkgs with the Asahi version using an overlay, + # which requires rebuilding the world but ensures it is done faithfully + # (and in a way compatible with pure evaluation) + nixpkgs.overlays = [ + (final: prev: { + mesa = final.mesa-asahi-edge; + }) + ]; + }) + ]; options.hardware.asahi.useExperimentalGPUDriver = lib.mkOption { type = lib.types.bool; @@ -44,7 +49,7 @@ }; options.hardware.asahi.experimentalGPUInstallMode = lib.mkOption { - type = lib.types.enum [ "driver" "replace" "overlay" ]; + type = lib.types.enum ["driver" "replace" "overlay"]; default = "replace"; description = '' Mode to use to install the experimental GPU driver into the system. diff --git a/hosts/farnsworth/apple-silicon-support/modules/peripheral-firmware/default.nix b/hosts/farnsworth/apple-silicon-support/modules/peripheral-firmware/default.nix index 2a478e6..99eaf59 100644 --- a/hosts/farnsworth/apple-silicon-support/modules/peripheral-firmware/default.nix +++ b/hosts/farnsworth/apple-silicon-support/modules/peripheral-firmware/default.nix @@ -1,8 +1,13 @@ -{ config, pkgs, lib, ... }: { + config, + pkgs, + lib, + ... +}: { config = { assertions = lib.mkIf config.hardware.asahi.extractPeripheralFirmware [ - { assertion = config.hardware.asahi.peripheralFirmwareDirectory != null; + { + assertion = config.hardware.asahi.peripheralFirmwareDirectory != null; message = '' Asahi peripheral firmware extraction is enabled but the firmware location appears incorrect. @@ -14,11 +19,11 @@ pkgs' = config.hardware.asahi.pkgs; in lib.mkIf ((config.hardware.asahi.peripheralFirmwareDirectory != null) - && config.hardware.asahi.extractPeripheralFirmware) [ + && config.hardware.asahi.extractPeripheralFirmware) [ (pkgs.stdenv.mkDerivation { name = "asahi-peripheral-firmware"; - nativeBuildInputs = [ pkgs'.asahi-fwextract pkgs.cpio ]; + nativeBuildInputs = [pkgs'.asahi-fwextract pkgs.cpio]; buildCommand = '' mkdir extracted @@ -45,7 +50,8 @@ peripheralFirmwareDirectory = lib.mkOption { type = lib.types.nullOr lib.types.path; - default = lib.findFirst (path: builtins.pathExists (path + "/all_firmware.tar.gz")) null + default = + lib.findFirst (path: builtins.pathExists (path + "/all_firmware.tar.gz")) null [ # path when the system is operating normally /boot/asahi diff --git a/hosts/farnsworth/apple-silicon-support/modules/sound/default.nix b/hosts/farnsworth/apple-silicon-support/modules/sound/default.nix index 5713f1a..a475512 100644 --- a/hosts/farnsworth/apple-silicon-support/modules/sound/default.nix +++ b/hosts/farnsworth/apple-silicon-support/modules/sound/default.nix @@ -1,13 +1,16 @@ -{ config, pkgs, lib, ... }: - { + config, + pkgs, + lib, + ... +}: { options.hardware.asahi = { setupAlsaUcm = lib.mkOption { type = lib.types.bool; default = config.sound.enable; description = '' - Enable the Asahi-specific ALSA UCM2 configs in the global environment - so that headphone jack input and output work properly. + Enable the Asahi-specific ALSA UCM2 configs in the global environment + so that headphone jack input and output work properly. ''; }; }; diff --git a/hosts/farnsworth/apple-silicon-support/packages/alsa-ucm-conf-asahi/default.nix b/hosts/farnsworth/apple-silicon-support/packages/alsa-ucm-conf-asahi/default.nix index bb34f19..ad10e50 100644 --- a/hosts/farnsworth/apple-silicon-support/packages/alsa-ucm-conf-asahi/default.nix +++ b/hosts/farnsworth/apple-silicon-support/packages/alsa-ucm-conf-asahi/default.nix @@ -1,8 +1,8 @@ -{ lib -, fetchFromGitHub -, alsa-ucm-conf }: - -(alsa-ucm-conf.overrideAttrs (oldAttrs: rec { +{ + lib, + fetchFromGitHub, + alsa-ucm-conf, +}: (alsa-ucm-conf.overrideAttrs (oldAttrs: rec { version = "3"; src_asahi = fetchFromGitHub { @@ -12,8 +12,11 @@ rev = "v${version}"; hash = "sha256-TCCT0AJx0SdnTzzBaV94zuD2hrPqvk+9vTTuEQmpJjc="; }; - - postInstall = oldAttrs.postInstall or "" + '' - cp -r ${src_asahi}/ucm2 $out/share/alsa - ''; + + postInstall = + oldAttrs.postInstall + or "" + + '' + cp -r ${src_asahi}/ucm2 $out/share/alsa + ''; })) diff --git a/hosts/farnsworth/apple-silicon-support/packages/asahi-fwextract/default.nix b/hosts/farnsworth/apple-silicon-support/packages/asahi-fwextract/default.nix index 556beb5..674390a 100755 --- a/hosts/farnsworth/apple-silicon-support/packages/asahi-fwextract/default.nix +++ b/hosts/farnsworth/apple-silicon-support/packages/asahi-fwextract/default.nix @@ -1,11 +1,11 @@ -{ lib -, python3 -, fetchFromGitHub -, gzip -, gnutar -, lzfse +{ + lib, + python3, + fetchFromGitHub, + gzip, + gnutar, + lzfse, }: - python3.pkgs.buildPythonApplication rec { pname = "asahi-fwextract"; version = "0.6.9"; @@ -26,7 +26,7 @@ python3.pkgs.buildPythonApplication rec { --replace '"xf"' '"-x", "-I", "${gzip}/bin/gzip", "-f"' ''; - nativeBuildInputs = [ python3.pkgs.setuptools ]; + nativeBuildInputs = [python3.pkgs.setuptools]; doCheck = false; } diff --git a/hosts/farnsworth/apple-silicon-support/packages/linux-asahi/default.nix b/hosts/farnsworth/apple-silicon-support/packages/linux-asahi/default.nix index 4696a6f..fd4c9c5 100644 --- a/hosts/farnsworth/apple-silicon-support/packages/linux-asahi/default.nix +++ b/hosts/farnsworth/apple-silicon-support/packages/linux-asahi/default.nix @@ -1,145 +1,194 @@ -{ lib -, pkgs -, callPackage -, writeShellScriptBin -, writeText -, removeReferencesTo -, linuxPackagesFor -, _4KBuild ? false -, withRust ? false -, _kernelPatches ? [ ] -}: - -let +{ + lib, + pkgs, + callPackage, + writeShellScriptBin, + writeText, + removeReferencesTo, + linuxPackagesFor, + _4KBuild ? false, + withRust ? false, + _kernelPatches ? [], +}: let i = builtins.elemAt; # parse [ymn]|foo style configuration as found in a patch's extraConfig # into a list of k, v tuples - parseExtraConfig = config: - let - lines = - builtins.filter (s: s != "") (lib.strings.splitString "\n" config); - parseLine = line: let - t = lib.strings.splitString " " line; - join = l: builtins.foldl' (a: b: "${a} ${b}") - (builtins.head l) (builtins.tail l); - v = if (builtins.length t) > 2 then join (builtins.tail t) else (i t 1); - in [ "CONFIG_${i t 0}" v ]; - in map parseLine lines; + parseExtraConfig = config: let + lines = + builtins.filter (s: s != "") (lib.strings.splitString "\n" config); + parseLine = line: let + t = lib.strings.splitString " " line; + join = l: + builtins.foldl' (a: b: "${a} ${b}") + (builtins.head l) (builtins.tail l); + v = + if (builtins.length t) > 2 + then join (builtins.tail t) + else (i t 1); + in ["CONFIG_${i t 0}" v]; + in + map parseLine lines; # parse =lib.kernel.(yes|module|no)|lib.kernel.freeform "foo" # style configuration as found in a patch's extraStructuredConfig into # a list of k, v tuples - parseExtraStructuredConfig = config: lib.attrsets.mapAttrsToList - (k: v: [ "CONFIG_${k}" (v.tristate or v.freeform) ] ) config; + parseExtraStructuredConfig = config: + lib.attrsets.mapAttrsToList + (k: v: ["CONFIG_${k}" (v.tristate or v.freeform)]) + config; - parsePatchConfig = { extraConfig ? "", extraStructuredConfig ? {}, ... }: - (parseExtraConfig extraConfig) ++ - (parseExtraStructuredConfig extraStructuredConfig); + parsePatchConfig = { + extraConfig ? "", + extraStructuredConfig ? {}, + ... + }: + (parseExtraConfig extraConfig) + ++ (parseExtraStructuredConfig extraStructuredConfig); # parse CONFIG_=[ymn]|"foo" style configuration as found in a config file # into a list of k, v tuples - parseConfig = config: - let - parseLine = builtins.match ''(CONFIG_[[:upper:][:digit:]_]+)=(([ymn])|"([^"]*)")''; - # get either the [ymn] option or the "foo" option; whichever matched - t = l: let v = (i l 2); in [ (i l 0) (if v != null then v else (i l 3)) ]; - lines = lib.strings.splitString "\n" config; - in map t (builtins.filter (l: l != null) (map parseLine lines)); + parseConfig = config: let + parseLine = builtins.match ''(CONFIG_[[:upper:][:digit:]_]+)=(([ymn])|"([^"]*)")''; + # get either the [ymn] option or the "foo" option; whichever matched + t = l: let + v = i l 2; + in [ + (i l 0) + ( + if v != null + then v + else (i l 3) + ) + ]; + lines = lib.strings.splitString "\n" config; + in + map t (builtins.filter (l: l != null) (map parseLine lines)); origConfigfile = ./config; - linux-asahi-pkg = { stdenv, lib, fetchFromGitHub, fetchpatch, linuxKernel, - rustPlatform, rustc, rustfmt, rust-bindgen, ... } @ args: - let - origConfigText = builtins.readFile origConfigfile; + linux-asahi-pkg = { + stdenv, + lib, + fetchFromGitHub, + fetchpatch, + linuxKernel, + rustPlatform, + rustc, + rustfmt, + rust-bindgen, + ... + } @ args: let + origConfigText = builtins.readFile origConfigfile; - # extraConfig from all patches in order - extraConfig = - lib.fold (patch: ex: ex ++ (parsePatchConfig patch)) [] _kernelPatches; - # config file text for above - extraConfigText = let - text = k: v: if (v == "y") || (v == "m") || (v == "n") - then "${k}=${v}" else ''${k}="${v}"''; - in (map (t: text (i t 0) (i t 1)) extraConfig); + # extraConfig from all patches in order + extraConfig = + lib.fold (patch: ex: ex ++ (parsePatchConfig patch)) [] _kernelPatches; + # config file text for above + extraConfigText = let + text = k: v: + if (v == "y") || (v == "m") || (v == "n") + then "${k}=${v}" + else ''${k}="${v}"''; + in (map (t: text (i t 0) (i t 1)) extraConfig); - # final config as a text file path - configfile = if extraConfig == [] then origConfigfile else + # final config as a text file path + configfile = + if extraConfig == [] + then origConfigfile + else writeText "config" '' ${origConfigText} # Patches ${lib.strings.concatStringsSep "\n" extraConfigText} ''; - # final config as an attrset - config = let - makePair = t: lib.nameValuePair (i t 0) (i t 1); - configList = (parseConfig origConfigText) ++ extraConfig; - in builtins.listToAttrs (map makePair (lib.lists.reverseList configList)); - - # used to (ostensibly) keep compatibility for those running stable versions of nixos - rustOlder = version: withRust && (lib.versionOlder rustc.version version); - bindgenOlder = version: withRust && (lib.versionOlder rust-bindgen.unwrapped.version version); - - # used to fix issues when nixpkgs gets ahead of the kernel - rustAtLeast = version: withRust && (lib.versionAtLeast rustc.version version); - bindgenAtLeast = version: withRust && (lib.versionAtLeast rust-bindgen.unwrapped.version version); + # final config as an attrset + config = let + makePair = t: lib.nameValuePair (i t 0) (i t 1); + configList = (parseConfig origConfigText) ++ extraConfig; in + builtins.listToAttrs (map makePair (lib.lists.reverseList configList)); + + # used to (ostensibly) keep compatibility for those running stable versions of nixos + rustOlder = version: withRust && (lib.versionOlder rustc.version version); + bindgenOlder = version: withRust && (lib.versionOlder rust-bindgen.unwrapped.version version); + + # used to fix issues when nixpkgs gets ahead of the kernel + rustAtLeast = version: withRust && (lib.versionAtLeast rustc.version version); + bindgenAtLeast = version: withRust && (lib.versionAtLeast rust-bindgen.unwrapped.version version); + in (linuxKernel.manualConfig rec { - inherit stdenv lib; + inherit stdenv lib; - version = "6.5.0-asahi"; - modDirVersion = version; - extraMeta.branch = "6.5"; + version = "6.5.0-asahi"; + modDirVersion = version; + extraMeta.branch = "6.5"; - src = fetchFromGitHub { - # tracking: https://github.com/AsahiLinux/PKGBUILDs/blob/main/linux-asahi/PKGBUILD - owner = "AsahiLinux"; - repo = "linux"; - rev = "asahi-6.5-15"; - hash = "sha256-Rruk/Nrw425XerZjgDJ4PJ3c63CCycch1qz7vFxHPCE="; - }; + src = fetchFromGitHub { + # tracking: https://github.com/AsahiLinux/PKGBUILDs/blob/main/linux-asahi/PKGBUILD + owner = "AsahiLinux"; + repo = "linux"; + rev = "asahi-6.5-15"; + hash = "sha256-Rruk/Nrw425XerZjgDJ4PJ3c63CCycch1qz7vFxHPCE="; + }; - kernelPatches = [ - { name = "rust-bindgen-version"; - patch = ./rust-bindgen-version.patch; - } - ] ++ lib.optionals _4KBuild [ - # thanks to Sven Peter - # https://lore.kernel.org/linux-iommu/20211019163737.46269-1-sven@svenpeter.dev/ - { name = "sven-iommu-4k"; - patch = ./sven-iommu-4k.patch; - } - (builtins.throw "The Asahi 4K kernel patch is currently broken. Contributions to fix are welcome.") - ] ++ lib.optionals (!_4KBuild) [ - # patch the kernel to set the default size to 16k instead of modifying - # the config so we don't need to convert our config to the nixos - # infrastructure or patch it and thus introduce a dependency on the host - # system architecture - { name = "default-pagesize-16k"; - patch = ./default-pagesize-16k.patch; - } - ] ++ _kernelPatches; + kernelPatches = + [ + { + name = "rust-bindgen-version"; + patch = ./rust-bindgen-version.patch; + } + ] + ++ lib.optionals _4KBuild [ + # thanks to Sven Peter + # https://lore.kernel.org/linux-iommu/20211019163737.46269-1-sven@svenpeter.dev/ + { + name = "sven-iommu-4k"; + patch = ./sven-iommu-4k.patch; + } + (builtins.throw "The Asahi 4K kernel patch is currently broken. Contributions to fix are welcome.") + ] + ++ lib.optionals (!_4KBuild) [ + # patch the kernel to set the default size to 16k instead of modifying + # the config so we don't need to convert our config to the nixos + # infrastructure or patch it and thus introduce a dependency on the host + # system architecture + { + name = "default-pagesize-16k"; + patch = ./default-pagesize-16k.patch; + } + ] + ++ _kernelPatches; - inherit configfile config; - } // (args.argsOverride or {})).overrideAttrs (old: if withRust then { - nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ - rust-bindgen - rustfmt - rustc - removeReferencesTo - ]; - # HACK: references shouldn't have been there in the first place - # TODO: remove once 23.05 is obsolete - postFixup = (old.postFixup or "") + '' - if [ -f $dev/lib/modules/${old.version}/build/vmlinux ]; then - remove-references-to -t $out $dev/lib/modules/${old.version}/build/vmlinux - fi - remove-references-to -t $dev $out/Image - ''; - RUST_LIB_SRC = rustPlatform.rustLibSrc; - } else {}); - - linux-asahi = (callPackage linux-asahi-pkg { }); -in lib.recurseIntoAttrs (linuxPackagesFor linux-asahi) + inherit configfile config; + } + // (args.argsOverride or {})) + .overrideAttrs (old: + if withRust + then { + nativeBuildInputs = + (old.nativeBuildInputs or []) + ++ [ + rust-bindgen + rustfmt + rustc + removeReferencesTo + ]; + # HACK: references shouldn't have been there in the first place + # TODO: remove once 23.05 is obsolete + postFixup = + (old.postFixup or "") + + '' + if [ -f $dev/lib/modules/${old.version}/build/vmlinux ]; then + remove-references-to -t $out $dev/lib/modules/${old.version}/build/vmlinux + fi + remove-references-to -t $dev $out/Image + ''; + RUST_LIB_SRC = rustPlatform.rustLibSrc; + } + else {}); + linux-asahi = callPackage linux-asahi-pkg {}; +in + lib.recurseIntoAttrs (linuxPackagesFor linux-asahi) diff --git a/hosts/farnsworth/apple-silicon-support/packages/m1n1/default.nix b/hosts/farnsworth/apple-silicon-support/packages/m1n1/default.nix index 7955f47..db539a4 100644 --- a/hosts/farnsworth/apple-silicon-support/packages/m1n1/default.nix +++ b/hosts/farnsworth/apple-silicon-support/packages/m1n1/default.nix @@ -1,101 +1,108 @@ -{ stdenv -, buildPackages -, lib -, fetchFromGitHub -, python3 -, dtc -, imagemagick -, isRelease ? false -, withTools ? true -, withChainloading ? false -, rust-bin ? null -, customLogo ? null +{ + stdenv, + buildPackages, + lib, + fetchFromGitHub, + python3, + dtc, + imagemagick, + isRelease ? false, + withTools ? true, + withChainloading ? false, + rust-bin ? null, + customLogo ? null, }: +assert withChainloading -> rust-bin != null; let + pyenv = python3.withPackages (p: + with p; [ + construct + pyserial + ]); -assert withChainloading -> rust-bin != null; + rustenv = rust-bin.selectLatestNightlyWith (toolchain: + toolchain.minimal.override { + targets = ["aarch64-unknown-none-softfloat"]; + }); +in + stdenv.mkDerivation rec { + pname = "m1n1"; + version = "1.4.2"; -let - pyenv = python3.withPackages (p: with p; [ - construct - pyserial - ]); + src = fetchFromGitHub { + # tracking: https://github.com/AsahiLinux/PKGBUILDs/blob/main/m1n1/PKGBUILD + owner = "AsahiLinux"; + repo = "m1n1"; + rev = "v${version}"; + hash = "sha256-zPHLlhXUIX6MV2pnDkuSg4Pz8gB4YOZiaa8MuLasgPY="; + fetchSubmodules = true; + }; - rustenv = rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal.override { - targets = [ "aarch64-unknown-none-softfloat" ]; - }); -in stdenv.mkDerivation rec { - pname = "m1n1"; - version = "1.4.2"; + makeFlags = + ["ARCH=${stdenv.cc.targetPrefix}"] + ++ lib.optional isRelease "RELEASE=1" + ++ lib.optional withChainloading "CHAINLOADING=1"; - src = fetchFromGitHub { - # tracking: https://github.com/AsahiLinux/PKGBUILDs/blob/main/m1n1/PKGBUILD - owner = "AsahiLinux"; - repo = "m1n1"; - rev = "v${version}"; - hash = "sha256-zPHLlhXUIX6MV2pnDkuSg4Pz8gB4YOZiaa8MuLasgPY="; - fetchSubmodules = true; - }; + nativeBuildInputs = + [ + dtc + buildPackages.gcc + ] + ++ lib.optional withChainloading rustenv + ++ lib.optional (customLogo != null) imagemagick; - makeFlags = [ "ARCH=${stdenv.cc.targetPrefix}" ] - ++ lib.optional isRelease "RELEASE=1" - ++ lib.optional withChainloading "CHAINLOADING=1"; + postPatch = '' + substituteInPlace proxyclient/m1n1/asm.py \ + --replace 'aarch64-linux-gnu-' 'aarch64-unknown-linux-gnu-' \ + --replace 'TOOLCHAIN = ""' 'TOOLCHAIN = "'$out'/toolchain-bin/"' + ''; - nativeBuildInputs = [ - dtc - buildPackages.gcc - ] ++ lib.optional withChainloading rustenv - ++ lib.optional (customLogo != null) imagemagick; + 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 - postPatch = '' - substituteInPlace proxyclient/m1n1/asm.py \ - --replace 'aarch64-linux-gnu-' 'aarch64-unknown-linux-gnu-' \ - --replace 'TOOLCHAIN = ""' 'TOOLCHAIN = "'$out'/toolchain-bin/"' - ''; + rm bootlogo_128.png + convert bootlogo_256.png -resize 128x128 bootlogo_128.png + patchShebangs --build ./makelogo.sh + ./makelogo.sh + popd &>/dev/null + ''; - 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 + installPhase = + '' + runHook preInstall - rm bootlogo_128.png - convert bootlogo_256.png -resize 128x128 bootlogo_128.png - patchShebangs --build ./makelogo.sh - ./makelogo.sh - popd &>/dev/null - ''; + 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 - installPhase = '' - runHook preInstall + for toolpath in $out/script/proxyclient/tools/*.py; do + tool=$(basename $toolpath .py) + script=$out/bin/m1n1-$tool + cat > $script < $script <