Welcome to NixOS
In my opinion the best Linux distrobution. Why do I say this? Well as a wise man once said:
"It's garbage, but it's the best we have so far" - IogaMaster
Otherwise NixOS is amazing for its reproducability and in that its declarativity.
Getting Started
If you are new to NixOS and want help installing or setting everything up please take a look at these videos.
- Beginner Guide
- In-Depth Guide (HM/Flakes/Nix)
- Flakes and Home Manager Guide
- Another Beginner Guide
- Flakes Explanation
Aswell here are a few NixOS related channels to keep an eye on.
NixOS Issues and Fixes
The following is a collection of issues I have come across after switching to NixOS from Arch.
INFO
The following is updated for version 24.05 (Uakari)
Getting awesome-git
When I was moving from XMonad to AwesomeWM I found out that the setup I was trying to replicate needed the git
version of Awesome for using the ruled
module.
Here is the solution:
WARNING
Make sure to replace version
with the latest git commit number. You can leave hash empty and when you rebuild the system it will print an error with the correct hash, just input that and rebuild again.
xserver.windowManager.awesome = {
enable = true;
package = pkgs.awesome.overrideAttrs (old: {
version = "1f7ac8f9c7ab9fff7dd93ab4b29514ff3580efcf";
src = pkgs.fetchFromGitHub {
owner = "awesomeWM";
repo = "awesome";
rev = version;
hash = "sha256-D5CTo4FvGk2U3fkDHf/JL5f/O1779i92UcRpPn+lbpw=";
};
patches = [];
postPatch = ''
patchShebangs tests/examples/_postprocess.lua
'';
});
};
OBS Virtual Camera
Getting the OBS Virtual Camera is a bit more complex that it should be but oh well.
In configuration.nix
:
boot = {
extraModulePackages = with config.boot.kernelPackages; [ v4l2loopback ];
extraModprobeConfig = ''
options v4l2loopback devices=1 video_nr=1 card_label="OBS Cam" exclusive_caps=1
'';
};
Then just add OBS to your packages list or use home-manager's OBS program options.
USB Devices not working?
By default NTFS is disabled so you won't be able to access quite a few USB storage devices.
The below code snippet from configuration.nix
should fix this:
INFO
This will not work for absolutely all NTFS devices, some will need to be formatted to be used or you can access them from a computer using another OS.
boot.supportedFilesystems = [ "ntfs" ];
How to set DNS Server?
This one can be tricky but basically just add this to configuration.nix
:
networking.nameservers = [ "1.1.1.1" "1.0.0.1" ];
TIP
You can put in just one DNS address and it will still work.
If that does not work as expected and you are using NetworkManager for your internet then make sure to add this line.
networking = {
networkmanager = {
dns = "none";
};
};
MPD??????
Yes I know i spent about 4 hours tearing my hair out aswell.
But do not fear, I have the solution.
INFO
Replace ${user}
with your username or keep it the same if you have a user
variable set.
TIP
The below uses Pipewire, see the NixOS Wiki page for more information if you are using a different audio server.
configuration.nix
services = {
mpd = {
enable = true;
musicDirectory = "/home/${user}/Music";
user = "${user}";
extraConfig = ''
audio_output {
type "pipewire"
name "Pipewire Output"
}
'';
};
};
# Important
systemd = {
services = {
mpd.environment = {
XDG_RUNTIME_DIR = "/run/user/1000";
};
};
};
TIP
Also include mpdris2
in your packages list and autostart it(mpDris2 --music-dir=~/Music &
) if you want tools like Playerctl
to be able to interact with MPD.
GTK and QT Themes
I prefer to set these in my home-manager configuration so that is what these options will be for.
INFO
If you are using a theme that is avaliable in a NixOS package then just pass in the package and the name*. Else you can only pass in name, being the name of the folder that is locally avaliable in ~/.themes
TIP
The name of the theme can be gotten by running nix build nixpkgs#capitaine-cursors
(replace with your package name), then enter the result
directory and browse until you find the directory with the name of the theme you want, copy that exact directory name into the name
field.
home.nix
gtk = {
enable = true;
iconTheme = {
name = "oomox-gruvbox-dark";
package = pkgs.gruvbox-dark-icons-gtk;
};
cursorTheme = {
name = "capitaine-cursors-white";
package = pkgs.capitaine-cursors;
};
theme = {
name = "Awesthetic-dark";
};
};
To enable the QT theme that matches the GTK theme just add:
qt = {
enable = true;
platformTheme = "gtk";
};
And to use XDG popups that corrospond with the GTK theme you can add the XDG portals information to configuration.nix
like this:
INFO
There should also be a way to add these portal settings to home.nix
but I haven't used that yet.
xdg = {
portal = {
enable = true;
extraPortals = with pkgs; [
xdg-desktop-portal
xdg-desktop-portal-gtk
];
config.common.default = "*";
};
};
No polkit agent?
You can add a polkit agent fairly simply, this is most often used to attaching drives and performing certain write actions on drives.
configuration.nix
systemd = {
user.services.polkit-gnome-authentication-agent-1 = {
description = "polkit-gnome-authentication-agent-1";
wantedBy = ["graphical-session.target"];
wants = ["graphical-session.target"];
after = ["graphical-session.target"];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
Restart = "on-failure";
RestartSec = 1;
TimeoutStopSec = 10;
};
};
};
XDG MIMETYPES!!!
Another venture of mine that took many hours.
Set the following in home.nix
or your home-manager configuration file.
INFO
You don't need to make the .desktop
files, they are automatically found by NixOS. Their name wil almost always be the applications command and then append .desktop
.
TIP
Looking for a full list of mimetypes? Click here
xdg = {
mimeApps = {
enable = true;
defaultApplications = {
"inode/directory" = ["pcmanfm.desktop"]; # Directories
"text/plain" = ["emacsclient.desktop"]; # Plain text
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" = ["onlyoffice-desktopeditors.desktop"]; # .docx
"application/vnd.openxmlformats-officedocument.presentationml.presentation" = ["onlyoffice-desktopeditors.desktop"]; # .pptx
"application/pdf" = ["onlyoffice-desktopeditors.desktop"]; # .pdf
"application/zip" = ["xarchiver.desktop"];
"text/*" = ["emacsclient.desktop"]; # Any text files
"video/*" = ["mpv.desktop"]; # Any video files
"x-scheme-handler/https" = ["firefox.desktop"]; # Links
"x-scheme-handler/http" = ["firefox.desktop"]; # Links
"x-scheme-handler/mailto" = ["firefox.desktop"]; # Links
"image/*" = ["feh.desktop"]; # Images
"image/png" = ["feh.desktop"];
"image/jpeg" = ["feh.desktop"];
};
};
};
Automatically write common files
Home-manager provides the option to write some files at rebuild using the awesome utility home.file
Below is an example of this being used to write out the annoying but always neccesary .ssh/config
file.
home = {
file = {
".ssh/config".text = ''
Host gitlab.com
IdentityFile ~/.ssh/gitlab
Host github.com
IdentityFile ~/.ssh/gitlab
'';
};
};
Setting up Anime-Game-Launcher
This one is definatley more complicated and requires you to have flakes setup.
In your flake.nix
:
inputs = {
aagl = {
url = "github:ezKEa/aagl-gtk-on-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
aagl,
}
Then under nixosConfigurations
nixosConfigurations = {
yourSystemName = lib.nixosSystem {
# ... Your code
modules = [
# Your imports and modules
{
nix.settings = aagl.nixConfig;
imports = [ aagl.nixosModules.default ];
programs.anime-game-launcher.enable = true; # Impact Game
programs.honkers-railway-launcher.enable = true; # Railway game
programs.honkers-launcher.enable = true; # 3rd game
}
];
};
};
INFO
For reasons I can't type the actual game names here but basically pick any of the game you want from the ones the code snippet and just remove the programs
you don't want.
Using a specific Linux kernel version
The wiki explains how to do this pretty well but I thought I would expand on it a bit more.
In configuration.nix
# Change pkgs.linux_6_1 to the sub major kernel package version you want. ^Note1
boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.linux_6_1.override {
argsOverride = rec {
src = pkgs.fetchurl {
# Change "v6.x" to the major version number of the kernel version you want, as an example if you want "4.19.60" you would replace "v6.x" with "v4.x"
url = "mirror://kernel/linux/kernel/v6.x/linux-${version}.tar.xz";
# Leave the hash empty and when you rebuild it will print the correct hash which you just put in there.
hash = "";
};
version = "6.1.75";
modDirVersion = "6.1.75";
};
});
Note 1
To see the avaliable sub major package version run the following commands in order.
nix repl
:l <nixpkgs>
pkgs.linuxPackages
Look for the closest package verion to the one you want, if you want 4.19.60
you would use pkgs.linuxPackages_4_19
.
Note 2
If you just want to use the latest linux kernel just use boot.kernelPackages = pkgs.linuxPackages_latest
Using a specific Nvidia driver version
WARNING
As of early March 2024 the production driver updated from 535
to 550
. This is a breaking change for some people especially those on Wayland. Below is how you can use 535
.
{ pkgs, config, libs, ... }:
{
services.xserver.videoDrivers = ["nvidia"];
hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
};
hardware.nvidia = {
modesetting.enable = true;
open = false;
nvidiaSettings = false;
};
hardware.nvidia.package = let
rcu_patch = pkgs.fetchpatch {
url = "https://github.com/gentoo/gentoo/raw/c64caf53/x11-drivers/nvidia-drivers/files/nvidia-drivers-470.223.02-gpl-pfn_valid.patch";
hash = "sha256-eZiQQp2S/asE7MfGvfe6dA/kdCvek9SYa/FFGp24dVg=";
};
in config.boot.kernelPackages.nvidiaPackages.mkDriver {
version = "535.154.05";
sha256_64bit = "sha256-fpUGXKprgt6SYRDxSCemGXLrEsIA6GOinp+0eGbqqJg=";
sha256_aarch64 = "sha256-G0/GiObf/BZMkzzET8HQjdIcvCSqB1uhsinro2HLK9k=";
openSha256 = "sha256-wvRdHguGLxS0mR06P5Qi++pDJBCF8pJ8hr4T8O6TJIo=";
settingsSha256 = "sha256-9wqoDEWY4I7weWW05F4igj1Gj9wjHsREFMztfEmqm10=";
persistencedSha256 = "sha256-d0Q3Lk80JqkS1B54Mahu2yY/WocOqFFbZVBh+ToGhaE=";
patches = [ rcu_patch ];
};
}
If you still just want the latest or some quick updates use the below options!
TIP
Make sure to review the driver versions for each preset before using it!
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.beta;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.production;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_470;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_390;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_340;
Auto Login without Display Manager
After a while of not being able to find a Display Manager that works with Hyprland I decided to just give up and move to Greetd
a very simple login manager.
This will also work for X11.
services = {
greetd = {
enable = true;
settings = {
initial_session = {
# Change "Hyprland" to the command to run your window manager. ^Note1
command = "Hyprland";
# Change "${user}" to your username or to your username variable.
user = "${user}";
};
# By adding default_session it ensures you can still access the tty terminal if you logout of your windows manager otherwise you would just relaunch into it.
default_session = {
# Again here just change "-cmd Hyprland" to "-cmd your-start-command".
command = "${pkgs.greetd.tuigreet}/bin/tuigreet --greeting 'Welcome To NixOS' --asterisks --remember --remember-user-session --time -cmd Hyprland";
# DO NOT CHANGE THIS USER
user = "greeter";
};
};
};
};
Note 1
If you are on X11 and want to use startx
to launch your window manager then make sure you have services.xserver.displayManager.startx.enable = true;
NvChad Setup
Since NvChad-v2.5 alot of information on how to setup NvChad on NixOS has become outdated, but thankfully one single person on reddit provided a solution which I will quote here.
- Clone the
NvChad/starter
repository in your NixOS configurations folder. - In your
home.nix
. Make sure to change./nvchad
to the location of the cloned starter repository relative to the postion of yourhome.nix
file.
home.file.".config/nvim" = {
source = ./nvchad;
recursive = true;
force = true;
}
- Make any changes to the starter config and then rebuild your system.
Note
Everytime you make changes to a specific nvim plugin config you will need to remove that plugin folder from ~/.local/share/nvim/lazy/<plugin-name>
or there may be issues with the plugin.