tonybtw.com

tonybtw.com

https://git.tonybtw.com/tonybtw.com.git git://git.tonybtw.com/tonybtw.com.git
10,571 bytes raw
1
#+TITLE: Hyprland on NixOS (w/ UWSM)
2
#+AUTHOR: Tony, btw
3
#+date: 2025-10-08
4
#+HUGO_TITLE: Hyprland on NixOS (w/ UWSM)
5
#+HUGO_FRONT_MATTER_FORMAT: yaml
6
#+HUGO_CUSTOM_FRONT_MATTER: :image "/img/nixos-hyprland.png" :showTableOfContents true
7
#+HUGO_BASE_DIR: ~/repos/tonybtw.com
8
#+HUGO_SECTION: tutorial/nixos-hyprland
9
#+EXPORT_FILE_NAME: index
10
#+OPTIONS: toc:nil broken-links:mark
11
#+HUGO_AUTO_SET_HEADLINE_SECTION: nil
12
#+DESCRIPTION: This is a quick and painless tutorial on how to setup Hyprland on NixOS using flakes + home manager, and optionally using UWSM (the Universal Wayland Session Manager)
13
14
* Intro
15
16
It's the year 20xx. Everyone's prebuilt PC at best buy comes with Linux and hyprland installed by default. The apple stores have Macbooks with a new propietary version of hyprland called iLand. Your grandson asks you, "My laptop broke, but I don't know how to re-install my operating system. Can you help me??"
17
18
What's up guys, my name is Tony, and today, I'm going to give you a quick and painless guide on setting up Hyprland on NixOS optionally with UWSM.
19
20
Hyprland is a wayland compositor that really feels like the King of beginner friendly compositors. It just works out of the box, with clean and aesthetically pleasing animations, and its getting more and more people into wayland, and linux in general. If you are converting over from a Desktop Environment such as Gnome, or Kde plasma, and you want to start with a wayland compositor, Hyprland is a great entry level choice.
21
22
Setting it up with NixOS is quite easy, so let's jump straight into the installation process.
23
24
* Installation
25
26
We're jumping straight into the minimal iso, and we'll speed run this since you've probably seen it 3 times by now, but a written guide will be provided below the subscribe button.
27
28
First thing we need to do is run lsblk to know what our disk is named. We see its vda, so lets run
29
#+begin_src sh
30
cfdisk /dev/vda
31
#+end_src
32
33
And let's setup 2 partitions. First one will be 1gb, and lets change the type to EFI Filesystem, which is going to be our 1 gigabyte boot partition.
34
35
Secondly, we'll just hit enter twice to use the remaining space for our root file system. Let's write, type yes, and quit here.
36
37
Now lets make the filesystems.
38
39
#+begin_src sh
40
mkfs.ext4 -L nixos /dev/vda2
41
mkfs.fat -F 32 -n BOOT /dev/vda1
42
#+end_src
43
44
And lets mount these:
45
46
#+begin_src sh
47
mount /dev/vda2 /mnt
48
mount --mkdir /dev/vda1 /mnt/boot
49
#+end_src
50
51
And we can type lsblk to confirm here:
52
53
#+begin_src sh
54
[root@nixos:~]# lsblk
55
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
56
loop0    7:0    0  1.5G  1 loop /nix/.ro-store
57
sr0     11:0    1  1.6G  0 rom  /iso
58
vda    253:0    0   50G  0 disk
59
├─vda1 253:1    0    1G  0 part /mnt/boot
60
└─vda2 253:3    0   49G  0 part /mnt
61
#+end_src
62
63
And we're already ready to generate the nixos configuration file.
64
65
** Initial NixOS Config
66
67
[[https://nixos.org/manual/nixos/stable/index.html#sec-installation-manual][Official NixOS Installation Handbook]]
68
69
Alright, we're ready to generate the config file, so let's do so with the following command:
70
71
This part is going to be a lot of configuration and text editing, so if you want everything I've put into these files, just follow along this written article.
72
73
#+begin_src
74
nixos-generate-config --root /mnt
75
cd /mnt/etc/nixos/
76
#+end_src
77
78
Let's create flake.nix, and home.nix
79
80
(This is my minimal vimrc that I use even on install ISOs)
81
#+begin_src vim
82
filetype plugin indent on
83
set expandtab
84
set shiftwidth=4
85
set softtabstop=4
86
set tabstop=4
87
set number
88
set relativenumber
89
set smartindent
90
set showmatch
91
set backspace=indent,eol,start
92
syntax on
93
#+end_src
94
95
*** flake.nix
96
97
vim flake.nix
98
99
Jumping into our flake.nix, this is where we define where our packages come from, so both configuration.nix and home.nix can inherit them through the flake and use them consistently.
100
101
Couple of things worth noting here:
102
103
1. nixpkgs is shorthand for github:NixOS/nixpkgs/nixos-unstable
104
2. inputs.nixpkgs.follows = "nixpkgs": This prevents home-manager from pulling its own version of nixpkgs, keeping everything consistent and avoiding mismatched package sets.
105
3. This modules section tells our flake to build the system using configuration.nix, and to configure Home Manager for the tony user using home.nix, with some options set inline.
106
4. We include home-manager as a NixOS module here because we want Home Manager to be managed by the flake itself — meaning we don’t need to bootstrap it separately, and we don’t need to run home-manager switch. Instead, everything gets applied in one go with nixos-rebuild switch.
107
108
vim flake.nix
109
#+begin_src nix
110
{
111
  description = "Hyprland on Nixos";
112
113
  inputs = {
114
    nixpkgs.url = "nixpkgs/nixos-unstable";
115
    home-manager = {
116
      url = "github:nix-community/home-manager";
117
      inputs.nixpkgs.follows = "nixpkgs";
118
    };
119
  };
120
121
  outputs = { self, nixpkgs, home-manager, ... }: {
122
    nixosConfigurations.nixos-btw = nixpkgs.lib.nixosSystem {
123
      system = "x86_64-linux";
124
      modules = [
125
        ./configuration.nix
126
        home-manager.nixosModules.home-manager
127
        {
128
          home-manager = {
129
            useGlobalPkgs = true;
130
            useUserPackages = true;
131
            users.tony = import ./home.nix;
132
            backupFileExtension = "backup";
133
          };
134
        }
135
      ];
136
    };
137
  };
138
}
139
#+end_src
140
141
We're ready to move onto our configuration.nix file.
142
143
*** configuration.nix
144
145
One of the beautiful things about NixOS is that your system is defined in various config files. You can think of it almost like of how your window manager is defined with config files, and you can port your window manager dotfiles to another distro, or another computer, and use the same keybinds/options on both machines. Well nixos has a 'config file' that lives above those window manager dotfiles from a heirerarchical perspective.
146
147
Alright, so I'm going to start off by deleting a bunch of comments.
148
I'll change the hostname here to `nixos-btw`, because I'm using NixOS, by the way.
149
We'll remove the wpa supplicant option and just uncomment the NetworkManager block here. If you are using wifi, keep the wpa supplicant option, and remove the NetworkManager block instead.
150
For my situation, I am going to chnage the timezone to America/Los Angeles.
151
We can delete all these proxy settings comments.
152
153
#+begin_src nix
154
{ config, lib, pkgs, ... }:
155
156
{
157
  imports =
158
    [
159
      ./hardware-configuration.nix
160
    ];
161
162
  boot.loader.systemd-boot.enable = true;
163
  boot.loader.efi.canTouchEfiVariables = true;
164
165
  services.getty.autologinUser = "tony";
166
167
  networking.hostName = "nixos";
168
  networking.networkmanager.enable = true;
169
170
  time.timeZone = "America/Los_Angeles";
171
172
  programs.hyprland = {
173
    enable = true;
174
    withUWSM = true;
175
    xwayland.enable = true;
176
  };
177
178
  users.users.tony = {
179
    isNormalUser = true;
180
    extraGroups = [ "wheel" ];
181
    packages = with pkgs; [
182
      tree
183
    ];
184
  };
185
186
  programs.firefox.enable = true;
187
  environment.systemPackages = with pkgs; [
188
    vim
189
    wget
190
    foot
191
    waybar
192
    kitty
193
  ];
194
195
  nix.settings.experimental-features = [ "nix-command" "flakes" ];
196
  system.stateVersion = "25.05";
197
198
}
199
200
#+end_src
201
202
And we can use the getty auto login service above. Feel free to skip UWSM if you are not interested in it, as it is more or less deprecated.
203
204
Alright we're ready to move on to our home.nix.
205
206
*** home.nix
207
Let's set up our home.nix. we'll heavily modify this after installing nixos and logging in for the first time.
208
209
Just going to specify the home directory, enable git, and for a sanity check, let's setup a bash alias so we can confirm everything worked when we initially log in.
210
211
vim home.nix
212
#+begin_src nix
213
{ config, pkgs, ... }:
214
215
{
216
  home.username = "tony";
217
  home.homeDirectory = "/home/tony";
218
  home.stateVersion = "25.05";
219
  programs.git.enable = true;
220
  programs.bash = {
221
    enable = true;
222
    shellAliases = {
223
      btw = "echo i use nixos, btw";
224
    };
225
    profileExtra = ''
226
      if [ -z "$WAYLAND_DISPLAY" ] && [ "$XDG_VTNR" = 1 ]; then
227
        exec uwsm start -S hyprland-uwsm.desktop
228
      fi
229
    '';
230
  };
231
}
232
#+end_src
233
234
** Install:
235
236
Alright we're finally ready to install this. We can do that with this command here, to specify the location of the flake.
237
238
#+begin_src sh
239
nixos-install --flake /mnt/etc/nixos#nixos-btw
240
241
## type your password
242
nixos-enter --root /mnt -c 'passwd tony'
243
reboot
244
#+end_src
245
246
Make sure to create this password otherwise you wont be able to log in
247
248
Let's boot into our system!
249
250
* Create config file
251
252
And we see we are instantly booted into hyprland. Awesome. Let's do a little tinkering here so that our monitor is actually the correct resolution. So we see its super Q to open a terminal, and lets vim the config file. We'll clean this up later, but for now, lets just change this one line here:
253
254
To 1920x1080. For me, that should do it.
255
256
Alright, I'm going to clone a couple of my dotfiles for my terminal, my hyprland and my waybar configurations. This video is more of a how to install hyprland on nixos video, and I'll show a really cool nix feature after.
257
258
#+begin_src sh
259
mkdir ~/nixos-dotfiles/config
260
cd ~/nixos-dotfiles/config
261
git clone https://github.com/tonybanters/hypr
262
git clone https://github.com/tonybanters/waybay
263
git clone https://github.com/tonybanters/foot
264
#+end_src
265
266
So in home.nix lets specify that our configs are going to come from config like so:
267
268
#+begin_src nix
269
home.file.".config/hypr".source = ./config/hypr;
270
home.file.".config/waybar".source = ./config/waybar;
271
home.file.".config/foot".source = ./config/foot;
272
#+end_src
273
274
And we can rebuild like so:
275
276
#+begin_src
277
sudo nixos-rebuild swith --flake ~/nixos-dotifles#hyprland-btw
278
#+end_src
279
280
* Nix Search TV
281
So we messed around with nix shells already, lets actually show something that I use on a daily basis, called nix-search-tv. This guide was written up by my friend Emzy, and we can use it to install a great tool that helps us search for nix packages, and use commands to just jump right into a nix shell.
282
283
So let's add this to our home manager packages list:
284
285
#+begin_src nix
286
#home.nix
287
288
home.packages = with pkgs; [
289
  (pkgs.writeShellApplication {
290
    name = "ns";
291
    runtimeInputs = with pkgs; [
292
      fzf
293
      nix-search-tv
294
    ];
295
    text = builtins.readFile "${pkgs.nix-search-tv.src}/nixpkgs.sh";
296
  })
297
];
298
299
#+end_src
300
301
Now we can rebuild/switch again, and run ns to demo this. Incredible
302
303
* Outro
304
305
Alright, thats gonna be it for todays video. If you have any questions or recommendations on any other linux related content, as usual just drop a comment.
306
307
It wouldn't be a proper video without an obligatory neofetch.