Nixos with Hyprland and Distrobox
Published on
I want Nixos so that my OS in Git and that I can run it on multiple machines. But some packages and many projects require FHS. I also want a pre-configured, desktop-environment-like experience with hyprland so that I don’t have to do everything myself.
Hpyrland
You don’t need to build a desktop environment from individual parts. The community has already packaged a great Hyprland experience. You’ll use Nix Flakes to pull it in.
1. Enable Flakes.
In your configuration.nix, add this:
nix.settings.experimental-features = [ "nix-command" "flakes" ];
2. Create your flake.nix.
This is the entry point for your entire system. It pulls in Nixpkgs (the package collection) and the community Hyprland configuration.
# ~/nixos-config/flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
hyprland.url = "github:nix-community/hyprland";
};
outputs = { self, nixpkgs, hyprland, ... }: {
nixosConfigurations.your-hostname = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
hyprland.nixosModules.default # This gives you the pre-configured desktop
];
};
};
}
3. Set up your configuration.nix.
Point to your hardware config and enable Hyprland.
# ~/nixos-config/configuration.nix
{ pkgs, ... }:
{
imports = [ ./hardware-configuration.nix ];
# Set your hostname to match the flake output
networking.hostName = "your-hostname";
# Enable Hyprland
programs.hyprland.enable = true;
programs.hyprland.xwayland.enable = true; # For X11 apps
# Basic user and system settings
users.users.your-username.isNormalUser = true;
users.users.your-username.extraGroups = [ "wheel" "video" ];
# Add essential packages here
environment.systemPackages = with pkgs; [ firefox kitty ];
system.stateVersion = "23.11"; # Or your version
}
4. Build.
From your config directory (~/nixos-config):
sudo nixos-rebuild switch --flake .#your-hostname
Reboot
Distrobox
Use custom docker images for isolated dev environments that reflect production servers (which have FHS). I create my custom image with CUDA and all required dev-tools like vim installed. Then I mount in my dot-files on start. This gives me an isolated environment others (including my future self) can use in the future, give a clear path to production, let’s me transfer the dev-env to a more powerful server when I need it and I don’t have to fight with nix if I don’t want to.
1. Define your base image with a Dockerfile.
This file lists the instructions to build a container with all your standard tools, like the CUDA toolkit, Python, and dependencies for your dotfiles.
# Dockerfile
# Start with NVIDIA's official image to get CUDA right
FROM nvidia/cuda:12.3.1-base-ubuntu22.04
# Avoid interactive prompts during build
ENV DEBIAN_FRONTEND=noninteractive
# Install your tools. Crucially, include dependencies for your dotfiles.
RUN apt-get update && apt-get install -y \
build-essential \
git \
zsh \
neovim \
python3-pip \
ripgrep \
fd-find \
&& rm -rf /var/lib/apt/lists/*
2. Build the image.
You only need to do this when you change your Dockerfile. Use Podman (simpler) or Docker.
podman build -t my-dev-base .
3. Mount your dotfiles.
To make tools inside the container use your existing configs, create a ~/.distroboxrc file on your host. This ensures any new container gets these mounts.
# ~/.distroboxrc
additional_mounts="/home/your-username/.config/nvim"
additional_mounts="/home/your-username/.zshrc"
Important: Your dotfiles will only work if their dependencies (ripgrep, LSPs, etc.) are installed in the Dockerfile.
4. Create your project container. Now, spinning up a complete, personalized dev environment is a single command.
distrobox create --name my-new-project --image localhost/my-dev-base
To use it, just run distrobox enter my-new-project.
For VS Code, install it on your NixOS host, then use the Dev Containers extension to “Attach to Running Container…”. The GUI runs natively, while the terminal, debugger, and language servers all run inside your isolated Distrobox environment. It’s the ideal setup.
Distrobox on Arch
You can try Distrobox right now, it is not NixOS-specific. You can and should try it on your current Arch system to get a feel for it. The Dockerfile and configs are directly portable.
# 1. Install tools
sudo pacman -S distrobox podman
# 2. Create your Dockerfile and ~/.distroboxrc as shown above
# 3. Build your custom image
podman build -t my-dev-base .
# 4. Create and enter a container using your image
distrobox create --name arch-test --image localhost/my-dev-base
distrobox enter arch-test
You’re now running a fully configured environment.