minimal example config
Hello,
I'm relatively new to NixOS, in the sense that I've only created configurations so far and haven't delved deeper into the language. Would it be possible to create a minimal example configuration that makes use of hardware features with Wayland? With all the options and GitHub discussions, it's difficult for me to understand what's happening.
Maybe there is already an example repository from which I can start?
Hi, I was in the same place you are. I'll share a few resources.
- Once installed, if you want graphics acceleration, you need to add this to your /etc/nixos/configuration:
hardware.asahi = {
useExperimentalGPUDriver = true;
experimentalGPUInstallMode = "replace";
setupAsahiSound = true;
};
These are a few other things that took me a while to figure out:
Persistant Battery Charge Limit at 80%:
services.udev.extraRules = ''
SUBSYSTEM=="power_supply", KERNEL=="macsmc-battery", ATTR{charge_control_end_threshold}="80"
'';
Enable the notch (I prefer the extra real estate and just move my dock up to the top like on macos):
boot.kernelParams = [ "apple_dcp.show_notch=1" ];
You can take a look at my config but it is using a multi host flake. (My asahi system is the 'nixi' one in my flake). So if you are using channels, it will look a little different.
There is another persons repo that I look at as well for help. They also use flakes but its a much better setup than mine: https://github.com/yusefnapora/nix-config/blob/main/nixos/hosts/asahi/default.nix
I feel like there should be a piece added to the documentation on how to enable hardware graphics acceleration as that is what most people want but I hope that helps.
If you do anything that takes a bit of ram, I recommend that you enable zram in your config.
zramSwap.enable = true;
also this can be handy on a laptop:
services.logind.extraConfig = ''
# don’t shutdown when power button is short-pressed
HandlePowerKey=ignore
'';
Thank you very much. That was helpful.
Do you have any suggestions to improve battery life? When I first installed it with plain sway, the battery drained 9% an hour when ideling. Now it is about 14% and I am not running (or at least I think I do not) any heavy background tasks.
Is there something special related to apple silicon when taking care of the battery life in nixos?
No Nixos specific unfortunately. I think that is an Asahi related problem. I have tried a few different services but none of them really did anything and the Asahi devs don't recommend it as the do their own power optimizations. The biggest thing I have found is keeping the brightness down. The screen is the biggest battery consumer. And there is a current issue, last I checked, the speakersafetyd uses the p-core instead of the e-cores so I have found that using wired headphones instead of the speakers also helps a bit.
@darbster145 I just checked out your suggestion (https://github.com/yusefnapora/nix-config/blob/main/nixos/hosts/asahi/default.nix).
I noticed, that the hardware.asahi.peripheralFirmwareDirectory option is not set. Is this not required?
What is the purpose of peripheralFirmware then?
earlier I suggested to enable zram but that is outdated, you should use zswap instead see: https://github.com/tpwrules/nixos-apple-silicon/issues/253
@darbster145 I just checked out your suggestion (https://github.com/yusefnapora/nix-config/blob/main/nixos/hosts/asahi/default.nix). I noticed, that the
hardware.asahi.peripheralFirmwareDirectoryoption is not set. Is this not required? What is the purpose of peripheralFirmware then?
The peripheralFirmware is the firmware for wifi, bluetooth, etc. There are three options with the hardware.asahi.peripheralFirmwareDirectory that you can set.
-
hardware.asahi.perpheralFirmwareDirectory = true;This will let you specify the directory for the firmware that you extracted during the set up if you followed the instructions. This is done to keep reproducibility as the firmware will not just unless you re-extract it yourself. -
hardware.asahi.peripheralFirmwareDirectory = false;This will not look for a firmware directory and it will not extract the firmware at boot. This means that wifi, bluetooth, etc will not work. You probably do not want to set this for any reason. -
Don't include
hardware.asahi.peripheralFirmwareDirectoryat all which is what I do. This will always extract the firmware for wifi, bluetooth, etc each time it boots. This also breaks reproducibility because there is a chance the firmware would be different between each boot.
I chose option three because I don't care about having 100% reproducibility on my asahi-nixos system and I did not want to rebuild the ./firmware directory each time macOS updated its firmware. In order to do this though you have to use the --impure flake when rebuilding. So my full build command, for example, is sudo nixos-rebuild switch --flake . --impure. If you leave out --impure with flakes, you will get a warns saying the build is not re-producible and won't build.
Hope that makes sense.
@darbster145
Thanks, I that was very helpful.
So in order to get the latest firmware, I need to execute sudo nixos-rebuild switch --flake . --impure without setting hardware.asahi.peripheralFirmwareDirectory?
And the latest firmware is then extracted somehow from the latest asahi kernel?