/nixos-config

Personal NixOS-WSL config

Primary LanguageNix

Personal config for NixOS (multi-host, WSL and non-WSL)

What Is Included

This config is a take on a productive terminal-driven development environment based on my own preferences. However, it is trivial to customize to your liking both by removing and adding tools that you prefer.

  • The default editor is Micro
  • The default shell is fish
  • Docker desktop on Windows integration is enabled by default
  • The prompt is Starship
  • fzf, lsd, zoxide, and broot are integrated into fish by default
    • These can all be disabled easily by setting enable = false in home.nix, or just removing the lines all together
  • direnv is integrated into fish by default
  • git config is generated in home.nix with options provided to enable private HTTPS clones with secret tokens
  • fish config is generated in home.nix and includes a bunch of plugins

How to install

From the great book NixOS and Flakes

Before running the commands below, ensure hostname (networking.hostname or wsl.wslConf.network.hostname) and username in your /etc/nixos/configuration.nix are set to a supported value in this config.

git clone git@github.com:maicol07/nixos-config.git $HOME/.config/nixos
sudo mv /etc/nixos /etc/nixos.bak  # Backup the original configuration

cd $HOME/.config/nixos

# If /etc/nixos/nixos.bak/hardware-configuration.nix exists, copy it to the new config
if [ -f /etc/nixos.bak/hardware-configuration.nix ]; then
  sudo cp /etc/nixos.bak/hardware-configuration.nix "./hardware/<host>/hardware-configuration.nix"
  # Add to git (repo is located in $HOME/.config/nixos)
  git add "./hardware/<host>/hardware-configuration.nix"
fi

# Deploy choosing the host (note that absolute paths are not strictly required, relative ones are fine too)
# WSL
sudo nixos-rebuild switch --flake $HOME/.config/nixos#maicol07-pc
sudo nixos-rebuild switch --flake $HOME/.config/nixos#maicol07-galaxy
# Server (non WSL)
sudo nixos-rebuild switch --flake $HOME/.config/nixos#maicol07-server

Project Layout

In order to keep the template as approachable as possible for new NixOS users, this project uses a flat layout without any nesting or modularization.

  • flake.nix is where dependencies are specified
    • nixpkgs is the current release of NixOS
    • nixpkgs-unstable is the current trunk branch of NixOS (ie. all the latest packages)
    • home-manager is used to manage everything related to your home directory (dotfiles etc.)
    • nur is the community-maintained Nix User Repositories for packages that may not be available in the NixOS repository
    • nixos-wsl exposes important WSL-specific configuration options
    • nix-index-database tells you how to install a package when you run a command which requires a binary not in the $PATH
  • common.nix has common options for all hosts (shell, user, nix, docker, etc.)
  • wsl.nix only includes WSL-specific options (Docker Desktop integration, nix-ld, Nvidia in WSL)
  • server.nix is a placeholder for non-WSL server-specific settings
  • home.nix is where home configurations are set
  • home/programs is the directory that contains all the programs that are installed on the system and their configurations
    • home/programs/default.nix is the entry point for all the programs
    • home/programs/programs.nix is where all the programs are defined
    • home/programs/git.nix is where the git configuration is set
    • home/programs/micro.nix is where the micro configuration is set
  • home/shell is the directory that contains all the shell configurations
    • home/shell/default.nix is the entry point for all the shell configurations
    • home/shell/fish.nix is where the fish configuration is set
    • home/starship.toml is where the starship configuration is set
    • home/starship-minimal.toml is a streamlined version of the starship configuration that is used from the fish-async-prompt plugin

Utilities commands

Upgprade dependencies

nix flake update

Compare the package versions difference between one deployment and another

All switches:

nix profile diff-closures --profile /nix/var/nix/profiles/system

Between two specific switches:

nix store diff-closures /nix/var/nix/profiles/system-99-link /run/current-system

Note: The numbers are the generations of the system. You can find them with

nix profile history --profile /nix/var/nix/profiles/system

Note 2: If you only have made one switch then you can use the booted system as base:

nix store diff-closures /run/booted-system /run/current-system

Delete all the old and temporary files from deployments

gc

(from fish alias)