Nixos is not your regular distro. Its “immutable” and “reproducible” and all that, things that most the of arch linux elites ignore before jumping into the nixos hype train. Instead of configuring your programs through ~/.config/appname files, we do it through .nix files. Instead of starting and stopping services with systemctl, we do it through .nix files. Instead of installing programs via a package manager, we do it through, you guessed it, .nix files. Most of the linux youtubers and average users do not fully explore nixos before going back to their old distro. They just configure their stuff in a big and ugly configuration.nix file. This blog will try to get you working hyprland on a flake powered nixos setup.
Basic Nix Commands
Rebuilding Nix System
Rebuilding Home Directory
Updating nix flake inputs
Flakes
A nix flake is a directory with a flake.nix and flake.lock that returns Nix expressions that can be used to install packages, run programs or in out case, create a whole ass NixOs configuration. Each flake consists of two parts defined in the flake.nix, inputs and outputs
Inputs: inputs are the equivalent of dependencies. They are the external resources or Flakes that a particular Flake needs to accomplish its tasks
Outpus: outputs refer to the different results or artifacts that a Flake can produce when it’s built or evaluated. Think of them as the things that a Flake can create or provide. In this case it provides us with a nixos configuration
Why flakes?
NixOS Flakes is a feature that enhances the Nix package manager’s capabilities by providing a structured and reproducible way to define and manage software packages and system configurations. It promotes consistency, immutability, and composability, making it particularly valuable for system administrators and developers who need to manage complex and reliable computing environments
Enabling Flakes
Currently flakes is a beta experimental feature that we have to manually enable
Then rebuild system with sudo nixos-rebuild switch
Basic Flake
Now of course this will not work, we still have to configure home manager and our system. Be sure to replace namish with your username.
Deriviations and overlays
This section is very important to understand. These two topics are really important to install programs that are not in the nix repos. In our config derivs will be placed at ./derivs and overlays are at ./overlays/default.nix
Deriviations
At a basic level, deriviations are just a way to build packages on your system. The structure of a Nix derivation is a set of specifications and instructions that define how to build and package a software component within the Nix package management system
Common Pieces of a nix deriviation:
Name and Version: A derivation typically starts with specifying the name and version of the software component you want to package.
Source: You specify the source code or binary of the software you’re packaging. This could be from a tar, github repo, a url or even local files
Build Process: This section outlines the steps to compile and build the software. You specify how to configure, compile, and install the software
Dependencies: You declare the dependencies required to build and run the software. Nix will ensure that these dependencies are available during the build process
Meta Info: You can include metadata about the package, such as its description and license information.
Example Deriviations
Overlays
Nix overlays are a mechanism in the Nix package manager that allows you to extend or modify the package set provided by the Nixpkgs repository. They are a way to add, replace, or customize packages and configurations without altering the global Nixpkgs repository. For example to use a custom fork of st we can make an overlay like this
For this to work, you need ./nixpkgs.nix and ./pkgs/default.nix
We can even use our deriviations to create an overlay
Example Deriviations
Overlays
Nix overlays are a mechanism in the Nix package manager that allows you to extend or modify the package set provided by the Nixpkgs repository. They are a way to add, replace, or customize packages and configurations without altering the global Nixpkgs repository. For example to use a custom fork of st we can make an overlay like this
For this to work, you need ./nixpkgs.nix and ./pkgs/default.nix
We can even use our deriviations to create an overlay
Configuring the system
First we will make two directories, ./hosts/frostbyte and ./hosts/shared. The first one would be for the main system itself and shared would be for setttings that would be common for each system (if you have more than 1 devices)
Also copy your existing hardware-configuration.nix to ./hosts/frostbyte/hardware-configuration.nix
Shared Settings
This will consist of:
Setting the timezone
Enabling network, bluetooth, sudo, polkit
User Config
Installing Fonts
Nix Settings
Actually Installing the overlays
System Specific configurations
Now this is used for:
Overlays
Networking
Services
BONUS — also learn how to install awesomewm
If you are wondering, we will be installing hyprland via home-manager
Home Manager
Home Manager gives you control over the user’s home environment. Home-Manager fosters user-specific profiles, accommodating distinct configurations for different users on the same system. Each user can have their own tailored environment, making it versatile and adaptable for both personal and multi-user systems
For this too, we will make two directories ./home/USER (replace USER with your username) and ./home/shared. The first one would be for user itself and shared would be for setttings that would be common for each user
Handling Colors
This is how the theme looks on awesome
rec is the programming equivalent of return. Now we can use this file to get the colors, whereever we want
Xresources
I think this piece of code pretty self explanantory
And then also import it
Hyprland
The only thing we have to do for installing hyprland is enable it. (now that i read this sentence again, it feels really dumb). Anyways create file ./home/USER/conf/ui/hyprland/default.nix
This was done considering you have wallpapers in .wallpapers/wave/wallpaper.png or something like that. And also do not forget to add in your extra config duh. 😑
And then import this file in your home.nix
Waybar
Instead of using the waybar in official nix packages repositories, we will use the one available from hyprland flake input we used.
and ofc import this too
Wezterm
Wezterm may not be the most minimal terminal, but is still better than that bloated piece of shit. Yes I have changed my terminal yet again. (future blog probably soon). Wezterms font rendering is the most alike to ST and it can also change colorschemes instantly, also has ligature support, and much more. (and i am not even using the git version). Create a directory ./home/USER/conf/term/wezterm and create two files default.nix and colors.nix
Dunst
For notifications, there are now many options for wayland but I am still going to be using dunst because I had the least trouble configuring it. Nix considers dunst to be service instead of program, therefore, programs.dunst becomes services.dunst. The configuration file for dunst will be at ./home/USER/conf/utils/dunst/default.nix
and the tradition continues
ZSH
zsh is my preferred shell (sorry fish noobs) so i will cover how to configure use zsh, create a file ./home/USER/conf/shell/zsh/default.nix
** ADDING PLUGINS- **
Instead of using something like zplug, zgen, zpm, we will just install them, through, you guessed it, nix. We will use this to install powerlevel10k
You will also need ./conf/shell/zsh/conf/powerlevel.zsh which tou can get from here
SHELL ALIASES-
Instead of adding aliases in initExtra we will do this
And in the end:
Music
This section will teach you how to set up mpd, ncmpcpp and playerctl on your system. It plays audio files, organizes playlists and maintains a music database, all while using very few resources. In order to interface with it, a separate client is needed. The client here is ncmpcpp
Here is the mpd configuration in nix
According to the arch wiki: Ncmpcpp is an mpd client (compatible with mopidy) with a UI very similar to ncmpc, but it provides new useful features such as support for regular expressions for library searches, extended song format, items filtering, the ability to sort playlists, and a local filesystem browser.
For ncmpcpp
Bonus - Creating Files
to write on a file on rebuilding home manager you can use home.file
for eg writing the .xinitrc file
you can also make bin files with this, just set executable to true
Dynamic GTK Theming
For dynamic themeing, we will just use phocus and then just subsititute the colors with patches. You are recommended to get your patches from here. So this is the derivation we need for it -
And then we can call it in the home.nix file
Nix Shell
Nix-shell is a command-line tool and concept within the Nix package manager that enables the creation of isolated development environments for software projects. It allows developers to specify the exact dependencies and environment required for a project, ensuring consistency and reproducibility across different systems and projects.
Here is an example shell.nix
To enter the shell we will use
Conclusion
whew, if you made it there, i hope you learned something from this. if there is an error you can contact me at discord @ chadcat7. For a reference you can check out my dots