diff options
| author | Tomuus <tomasz1.mrozinski@proton.me> | 2025-12-06 20:08:34 +0100 |
|---|---|---|
| committer | Tomuus <tomasz1.mrozinski@proton.me> | 2025-12-06 20:08:34 +0100 |
| commit | 865ad7ddec4ef3a6d349b1478ab22f826bae0546 (patch) | |
| tree | fd135c5173c618594086193ea38dff9d85be03ab | |
| parent | 892a9330e4a0af5add5da65f4ae11838bdee3d36 (diff) | |
Added my new laptop (lets gooooo)
| -rw-r--r-- | flake.nix | 15 | ||||
| -rw-r--r-- | hosts/Makbuk/apple-silicon-support/default.nix | 7 | ||||
| -rw-r--r-- | hosts/Makbuk/apple-silicon-support/modules/boot-m1n1/default.nix | 67 | ||||
| -rw-r--r-- | hosts/Makbuk/apple-silicon-support/modules/default.nix | 84 | ||||
| -rw-r--r-- | hosts/Makbuk/apple-silicon-support/modules/kernel/default.nix | 117 | ||||
| -rw-r--r-- | hosts/Makbuk/apple-silicon-support/modules/peripheral-firmware/default.nix | 82 | ||||
| -rw-r--r-- | hosts/Makbuk/apple-silicon-support/modules/sound/default.nix | 61 | ||||
| -rw-r--r-- | hosts/Makbuk/apple-silicon-support/packages/linux-asahi/default.nix | 63 | ||||
| -rw-r--r-- | hosts/Makbuk/apple-silicon-support/packages/overlay.nix | 4 | ||||
| -rw-r--r-- | hosts/Makbuk/apple-silicon-support/packages/uboot-asahi/default.nix | 46 | ||||
| -rw-r--r-- | hosts/Makbuk/configuration.nix | 24 | ||||
| -rw-r--r-- | hosts/Makbuk/hardware-configuration.nix | 30 | ||||
| -rw-r--r-- | hosts/common/system-properties.nix | 2 |
13 files changed, 601 insertions, 1 deletions
@@ -84,6 +84,21 @@ } ]; }; + + Makbuk = nixpkgs.lib.nixosSystem { + specialArgs = { inherit inputs mods unstbl userName fullName; }; + modules = [ + ./hosts/Makbuk.configuration.nix + #nvf.nixosModules.default + home-manager.nixosModules.home-manager { home-manager.users.${userName} = import ./home { inherit userName fullName; }; } #If it works DON'T TOUCH IT + { + #environment.systemPackages = [ + # self.packages.${system}.nvf + #]; + } + ]; + }; + }; }; } diff --git a/hosts/Makbuk/apple-silicon-support/default.nix b/hosts/Makbuk/apple-silicon-support/default.nix new file mode 100644 index 0000000..71a5dd0 --- /dev/null +++ b/hosts/Makbuk/apple-silicon-support/default.nix @@ -0,0 +1,7 @@ +{ ... }: + +{ + imports = [ + ./modules/default.nix + ]; +} diff --git a/hosts/Makbuk/apple-silicon-support/modules/boot-m1n1/default.nix b/hosts/Makbuk/apple-silicon-support/modules/boot-m1n1/default.nix new file mode 100644 index 0000000..1e10c1d --- /dev/null +++ b/hosts/Makbuk/apple-silicon-support/modules/boot-m1n1/default.nix @@ -0,0 +1,67 @@ +{ + config, + pkgs, + lib, + ... +}: +let + pkgs' = config.hardware.asahi.pkgs; + + bootM1n1 = + if (config.boot.m1n1CustomLogo != null) then + pkgs'.m1n1.override { + customLogo = config.boot.m1n1CustomLogo; + } + else + pkgs'.m1n1; + + bootUBoot = pkgs'.uboot-asahi.override { + m1n1 = bootM1n1; + }; + + bootFiles = { + "m1n1/boot.bin" = pkgs.runCommand "boot.bin" { } '' + cat ${bootM1n1}/lib/m1n1/m1n1.bin \ + ${config.boot.kernelPackages.kernel}/dtbs/apple/*.dtb \ + ${bootUBoot}/u-boot-nodtb.bin.gz \ + > $out + if [ -n "${config.boot.m1n1ExtraOptions}" ]; then + echo '${config.boot.m1n1ExtraOptions}' >> $out + fi + ''; + }; +in +{ + config = lib.mkIf config.hardware.asahi.enable { + # install m1n1 with the boot loader + boot.loader.grub.extraFiles = bootFiles; + boot.loader.systemd-boot.extraFiles = bootFiles; + + # ensure the installer has m1n1 in the image + system.extraDependencies = lib.mkForce [ + bootM1n1 + bootUBoot + ]; + system.build.m1n1 = bootFiles."m1n1/boot.bin"; + }; + + options.boot = { + m1n1ExtraOptions = lib.mkOption { + type = lib.types.str; + default = ""; + description = '' + Append extra options to the m1n1 boot binary. Might be useful for fixing + display problems on Mac minis. + https://github.com/AsahiLinux/m1n1/issues/159 + ''; + }; + + m1n1CustomLogo = lib.mkOption { + type = lib.types.nullOr lib.types.path; + default = null; + description = '' + Custom logo to build into m1n1. The path must point to a 256x256 PNG. + ''; + }; + }; +} diff --git a/hosts/Makbuk/apple-silicon-support/modules/default.nix b/hosts/Makbuk/apple-silicon-support/modules/default.nix new file mode 100644 index 0000000..3ed3fd6 --- /dev/null +++ b/hosts/Makbuk/apple-silicon-support/modules/default.nix @@ -0,0 +1,84 @@ +{ + config, + pkgs, + lib, + ... +}: +{ + imports = [ + ./kernel + ./peripheral-firmware + ./boot-m1n1 + ./sound + ]; + + config = + let + cfg = config.hardware.asahi; + in + lib.mkIf cfg.enable { + 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; + + # 900 is higher priority than mkDefault but lower than just setting + hardware.graphics.package = lib.mkOverride 900 ( + lib.warnIf (lib.versionAtLeast pkgs.mesa.version "25.3") '' + Mesa 25.3 is known to cause crashes in Firefox on Asahi GPUs. + Please pin nixpkgs c5ae371f1a6a7fd27823 or earlier if affected. + See https://github.com/nix-community/nixos-apple-silicon/issues/380 + for more info.'' pkgs.mesa + ); + }; + + options.hardware.asahi = { + enable = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Enable the basic Asahi Linux components, such as kernel and boot setup. + ''; + }; + + pkgsSystem = lib.mkOption { + type = lib.types.str; + default = "aarch64-linux"; + description = '' + System architecture that should be used to build the major Asahi + packages, if not the default aarch64-linux. This allows installing from + a cross-built ISO without rebuilding them during installation. + ''; + }; + + pkgs = lib.mkOption { + type = lib.types.raw; + description = '' + Package set used to build the major Asahi packages. Defaults to the + ambient set if not cross-built, otherwise re-imports the ambient set + 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. + ''; + }; + }; +} diff --git a/hosts/Makbuk/apple-silicon-support/modules/kernel/default.nix b/hosts/Makbuk/apple-silicon-support/modules/kernel/default.nix new file mode 100644 index 0000000..bdc347c --- /dev/null +++ b/hosts/Makbuk/apple-silicon-support/modules/kernel/default.nix @@ -0,0 +1,117 @@ +# the Asahi Linux kernel and options that must go along with it + +{ + config, + lib, + ... +}: +{ + config = lib.mkIf config.hardware.asahi.enable { + boot.kernelPackages = + let + pkgs' = config.hardware.asahi.pkgs; + in + pkgs'.linux-asahi.override { + _kernelPatches = config.boot.kernelPatches; + }; + + # we definitely want to use CONFIG_ENERGY_MODEL, and + # schedutil is a prerequisite for using it + # source: https://www.kernel.org/doc/html/latest/scheduler/sched-energy.html + powerManagement.cpuFreqGovernor = lib.mkOverride 800 "schedutil"; + + boot.initrd.availableKernelModules = [ + # list of initrd modules stolen from + # https://github.com/AsahiLinux/asahi-scripts/blob/f461f080a1d2575ae4b82879b5624360db3cff8c/initcpio/install/asahi + "apple-mailbox" + "apple_nvmem_spmi" + "nvme_apple" + "pinctrl-apple-gpio" + "macsmc" + "macsmc-power" + "macsmc-input" + "macsmc-hwmon" + "macsmc-reboot" + "i2c-pasemi-platform" + "tps6598x" + "apple-dart" + "dwc3" + "dwc3-of-simple" + "xhci-pci" + "pcie-apple" + "gpio_macsmc" + "phy-apple-atc" + "nvmem_apple_efuses" + "spi-apple" + "spi-hid-apple" + "spi-hid-apple-of" + "rtc-macsmc" + "spmi-apple-controller" + "apple-dockchannel" + "dockchannel-hid" + "apple-rtkit-helper" + + # additional stuff necessary to boot off USB for the installer + # and if the initrd (i.e. stage 1) goes wrong + "usb-storage" + "xhci-plat-hcd" + "usbhid" + "hid_generic" + ]; + + boot.kernelParams = [ + "earlycon" + "console=tty0" + "boot.shell_on_fail" + # Apple's SSDs are slow (~dozens of ms) at processing flush requests which + # slows down programs that make a lot of fsync calls. This parameter sets + # a delay in ms before actually flushing so that such requests can be + # coalesced. Be warned that increasing this parameter above zero (default + # is 1000) has the potential, though admittedly unlikely, risk of + # UNBOUNDED data corruption in case of power loss!!!! Don't even think + # about it on desktops!! + "nvme_apple.flush_interval=0" + ]; + + # U-Boot does not support EFI variables + boot.loader.efi.canTouchEfiVariables = lib.mkForce false; + + # U-Boot does not support switching console mode + boot.loader.systemd-boot.consoleMode = "0"; + + # GRUB has to be installed as removable if the user chooses to use it + boot.loader.grub = lib.mkDefault { + efiSupport = true; + efiInstallAsRemovable = true; + device = "nodev"; + }; + + # autosuspend was enabled as safe for the PCI SD card reader + # "Genesys Logic, Inc GL9755 SD Host Controller [17a0:9755] (rev 01)" + # by recent systemd versions, but this has a "negative interaction" + # with our kernel/SoC and causes random boot hangs. disable it! + services.udev.extraHwdb = '' + pci:v000017A0d00009755* + ID_AUTOSUSPEND=0 + ''; + }; + + imports = [ + (lib.mkRemovedOptionModule [ + "hardware" + "asahi" + "addEdgeKernelConfig" + ] "All edge kernel config options are now the default.") + (lib.mkRemovedOptionModule [ + "hardware" + "asahi" + "experimentalGPUInstallMode" + ] "This option became unnecessary with asahi support landing in mainline mesa.") + (lib.mkRemovedOptionModule [ + "hardware" + "asahi" + "useExperimentalGPUDriver" + ] "This option became unnecessary with asahi support landing in mainline mesa.") + (lib.mkRemovedOptionModule [ "hardware" "asahi" "withRust" ] "Rust support is now the default.") + ]; +} diff --git a/hosts/Makbuk/apple-silicon-support/modules/peripheral-firmware/default.nix b/hosts/Makbuk/apple-silicon-support/modules/peripheral-firmware/default.nix new file mode 100644 index 0000000..27f1f34 --- /dev/null +++ b/hosts/Makbuk/apple-silicon-support/modules/peripheral-firmware/default.nix @@ -0,0 +1,82 @@ +{ + config, + pkgs, + lib, + ... +}: +{ + config = lib.mkIf config.hardware.asahi.enable { + assertions = lib.mkIf config.hardware.asahi.extractPeripheralFirmware [ + { + assertion = config.hardware.asahi.peripheralFirmwareDirectory != null; + message = '' + Asahi peripheral firmware extraction is enabled but the firmware + location appears incorrect. + ''; + } + ]; + + hardware.firmware = + let + 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 = [ + pkgs'.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 + ''; + }) + ]; + }; + + options.hardware.asahi = { + extractPeripheralFirmware = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Automatically extract the non-free non-redistributable peripheral + firmware necessary for features like Wi-Fi. + ''; + }; + + peripheralFirmwareDirectory = lib.mkOption { + type = lib.types.nullOr lib.types.path; + + 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 + ]; + + description = '' + Path to the directory containing the non-free non-redistributable + peripheral firmware necessary for features like Wi-Fi. Ordinarily, this + will automatically point to the appropriate location on the ESP. Flake + users and those interested in maximum purity will want to copy those + files elsewhere and specify this manually. + + Currently, this consists of the files `all-firmware.tar.gz` and + `kernelcache*`. The official Asahi Linux installer places these files + in the `asahi` directory of the EFI system partition when creating it. + ''; + }; + }; +} diff --git a/hosts/Makbuk/apple-silicon-support/modules/sound/default.nix b/hosts/Makbuk/apple-silicon-support/modules/sound/default.nix new file mode 100644 index 0000000..a22aa09 --- /dev/null +++ b/hosts/Makbuk/apple-silicon-support/modules/sound/default.nix @@ -0,0 +1,61 @@ +{ + config, + options, + pkgs, + lib, + ... +}: + +{ + options.hardware.asahi = { + setupAsahiSound = lib.mkOption { + type = lib.types.bool; + default = config.hardware.asahi.enable; + description = '' + Set up the Asahi DSP components so that the speakers and headphone jack + work properly and safely. + ''; + }; + }; + + config = + let + cfg = config.hardware.asahi; + in + lib.mkIf (cfg.setupAsahiSound && cfg.enable) ( + lib.mkMerge [ + { + # can't be used by Asahi sound infrastructure + services.pulseaudio.enable = false; + # enable pipewire to run real-time and avoid audible glitches + security.rtkit.enable = true; + # set up pipewire with the supported capabilities (instead of pulseaudio) + # and asahi-audio configs and plugins + services.pipewire = { + enable = true; + alsa.enable = true; + pulse.enable = true; + + configPackages = [ pkgs.asahi-audio ]; + + wireplumber = { + enable = true; + + configPackages = [ pkgs.asahi-audio ]; + }; + }; + + # set up enivronment so that UCM configs are used as well + environment.variables.ALSA_CONFIG_UCM2 = "${pkgs.alsa-ucm-conf-asahi}/share/alsa/ucm2"; + systemd.user.services.pipewire.environment.ALSA_CONFIG_UCM2 = + config.environment.variables.ALSA_CONFIG_UCM2; + systemd.user.services.wireplumber.environment.ALSA_CONFIG_UCM2 = + config.environment.variables.ALSA_CONFIG_UCM2; + + # enable speakersafetyd to protect speakers + systemd.packages = [ pkgs.speakersafetyd ]; + services.udev.packages = [ pkgs.speakersafetyd ]; + } + ] + ); +} diff --git a/hosts/Makbuk/apple-silicon-support/packages/linux-asahi/default.nix b/hosts/Makbuk/apple-silicon-support/packages/linux-asahi/default.nix new file mode 100644 index 0000000..978aa83 --- /dev/null +++ b/hosts/Makbuk/apple-silicon-support/packages/linux-asahi/default.nix @@ -0,0 +1,63 @@ +{ + lib, + callPackage, + linuxPackagesFor, + _kernelPatches ? [ ], +}: + +let + linux-asahi-pkg = + { + stdenv, + lib, + fetchFromGitHub, + buildLinux, + ... + }: + buildLinux rec { + inherit stdenv lib; + + pname = "linux-asahi"; + version = "6.17.7"; + modDirVersion = version; + extraMeta.branch = "6.17"; + + src = fetchFromGitHub { + owner = "AsahiLinux"; + repo = "linux"; + tag = "asahi-6.17.7-2"; + hash = "sha256-wyuHcp9rEpOtNb8aRPkfX57XdcmpitklM4oew/YMRio="; + }; + + kernelPatches = [ + { + name = "Asahi config"; + patch = null; + structuredExtraConfig = with lib.kernel; { + # Needed for GPU + ARM64_16K_PAGES = yes; + + ARM64_MEMORY_MODEL_CONTROL = yes; + ARM64_ACTLR_STATE = yes; + + # Might lead to the machine rebooting if not loaded soon enough + APPLE_WATCHDOG = yes; + + # Can not be built as a module, defaults to no + APPLE_M1_CPU_PMU = yes; + + # Defaults to 'y', but we want to allow the user to set options in modprobe.d + HID_APPLE = module; + + APPLE_PMGR_MISC = yes; + APPLE_PMGR_PWRSTATE = yes; + }; + features.rust = true; + } + ] + ++ _kernelPatches; + }; + + linux-asahi = callPackage linux-asahi-pkg { }; +in +lib.recurseIntoAttrs (linuxPackagesFor linux-asahi) diff --git a/hosts/Makbuk/apple-silicon-support/packages/overlay.nix b/hosts/Makbuk/apple-silicon-support/packages/overlay.nix new file mode 100644 index 0000000..9228600 --- /dev/null +++ b/hosts/Makbuk/apple-silicon-support/packages/overlay.nix @@ -0,0 +1,4 @@ +final: prev: { + linux-asahi = final.callPackage ./linux-asahi { }; + uboot-asahi = final.callPackage ./uboot-asahi { }; +} diff --git a/hosts/Makbuk/apple-silicon-support/packages/uboot-asahi/default.nix b/hosts/Makbuk/apple-silicon-support/packages/uboot-asahi/default.nix new file mode 100644 index 0000000..8d6dd08 --- /dev/null +++ b/hosts/Makbuk/apple-silicon-support/packages/uboot-asahi/default.nix @@ -0,0 +1,46 @@ +{ + lib, + fetchFromGitHub, + buildUBoot, + m1n1, +}: + +(buildUBoot rec { + src = fetchFromGitHub { + # tracking: https://pagure.io/fedora-asahi/uboot-tools/commits/main + owner = "AsahiLinux"; + repo = "u-boot"; + rev = "asahi-v2025.07-1"; + hash = "sha256-WGpMd3ub+m0xWevPreYrLWpoQSz9sr1YmeOiU7kgPGs="; + }; + version = "2025.07-1-asahi"; + + defconfig = "apple_m1_defconfig"; + extraMeta.platforms = [ "aarch64-linux" ]; + filesToInstall = [ + "u-boot-nodtb.bin.gz" + "m1n1-u-boot.bin" + ]; + extraConfig = '' + CONFIG_IDENT_STRING=" ${version}" + CONFIG_VIDEO_FONT_4X6=n + CONFIG_VIDEO_FONT_8X16=n + CONFIG_VIDEO_FONT_SUN12X22=n + CONFIG_VIDEO_FONT_16X32=y + CONFIG_CMD_BOOTMENU=y + ''; +}).overrideAttrs + (o: { + # nixos's downstream patches are not applicable + patches = [ + ]; + + # DTC= flag somehow breaks DTC compilation so we remove it + makeFlags = builtins.filter (s: (!(lib.strings.hasPrefix "DTC=" s))) o.makeFlags; + + preInstall = '' + # compress so that m1n1 knows U-Boot's size and can find things after it + gzip -n u-boot-nodtb.bin + cat ${m1n1}/lib/m1n1/m1n1.bin arch/arm/dts/t[68]*.dtb u-boot-nodtb.bin.gz > m1n1-u-boot.bin + ''; + }) diff --git a/hosts/Makbuk/configuration.nix b/hosts/Makbuk/configuration.nix new file mode 100644 index 0000000..d39bd62 --- /dev/null +++ b/hosts/Makbuk/configuration.nix @@ -0,0 +1,24 @@ +#configuration.nix + +{ mods, ... }: + +{ + imports = [ + ./hardware-configuration.nix +# ./packages.nix +# ./cal.nix + ./../common +# ./tata.nix +# "${mods}/dev/cpp.nix" +# "${mods}/de/hyprland" +# "${mods}/bluetooth.nix" + ]; + networking.hostName = "Makbuk"; + + networking.wireless.iwd = { + enable = true; + settings.General.EndableNetworkConfiguration = true; + }; + + hardware.asahi.peripheralFirmwareDirectory = ./firmware; +} diff --git a/hosts/Makbuk/hardware-configuration.nix b/hosts/Makbuk/hardware-configuration.nix new file mode 100644 index 0000000..30ca8a7 --- /dev/null +++ b/hosts/Makbuk/hardware-configuration.nix @@ -0,0 +1,30 @@ +# 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") + ]; + + boot.initrd.availableKernelModules = [ "usb_storage" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/aa83b9c1-ea56-4fed-a304-48b5aba1cf15"; + fsType = "ext4"; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/1C4A-191C"; + fsType = "vfat"; + options = [ "fmask=0022" "dmask=0022" ]; + }; + + swapDevices = [ ]; + + nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux"; +} diff --git a/hosts/common/system-properties.nix b/hosts/common/system-properties.nix index 6ca2129..dd79f45 100644 --- a/hosts/common/system-properties.nix +++ b/hosts/common/system-properties.nix @@ -6,7 +6,7 @@ nix.settings.experimental-features = ["nix-command" "flakes"]; boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; + boot.loader.efi.canTouchEfiVariables = false; networking.networkmanager.enable = true; |
