This document describes NixOS system management integration in the NeoVim configuration, including system rebuilding, package management, development environments, and Nix language support.
The configuration provides convenient keybindings for common NixOS operations:
| Key | Command | Description |
|---|---|---|
<leader>nr |
Rebuild system | sudo nixos-rebuild switch --flake . |
<leader>nh |
Apply home-manager | home-manager switch --flake . |
<leader>nu |
Update dependencies | nix flake update |
<leader>ng |
Garbage collection | nix-collect-garbage -d |
<leader>nd |
Development shell | nix develop |
Configuration: lua/neotex/plugins/editor/which-key.lua (NixOS management section)
┌─────────────────────────────────────┐
│ Edit Nix Configuration │
│ • Modify /etc/nixos/configuration.nix│
│ • Update flake.nix │
│ • Edit home-manager config │
└────────────┬────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Rebuild System │
│ <leader>nr │
│ • Evaluates configuration │
│ • Builds new system │
│ • Activates new generation │
└────────────┬────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Verify Changes │
│ • Check services: systemctl status │
│ • Verify packages: which [command] │
│ • Rollback if needed: <leader>nr │
└─────────────────────────────────────┘
Web Resources:
| Key | Action | URL |
|---|---|---|
<leader>np |
Open NixOS packages | https://search.nixos.org/packages |
<leader>nm |
Open MyNixOS | https://mynixos.com |
Command Line Search:
# Search for package
nix search nixpkgs [package-name]
# Show package details
nix-env -qa --description [package-name]
# Check if package exists in current channel
nix-env -qaP | grep [package-name]System-Wide Installation:
- Add package to
/etc/nixos/configuration.nix:environment.systemPackages = with pkgs; [ git neovim ripgrep ];
- Rebuild system:
<leader>nr
User-Level Installation (Home Manager):
- Add to
home.nixor equivalent:home.packages = with pkgs; [ fzf fd ];
- Apply changes:
<leader>nh
Temporary Installation:
# Install for current session
nix-shell -p [package-name]
# Use package immediately
nix run nixpkgs#[package-name]Typical Nix flake organization:
flake.nix # Main flake configuration
├── inputs # Dependencies (nixpkgs, home-manager, etc.)
├── outputs # System configurations
│ ├── nixosConfigurations
│ └── homeConfigurations
└── flake.lock # Lock file with exact versions
Update All Inputs:
" In NeoVim
<leader>nuThis runs nix flake update which:
- Checks all flake inputs for updates
- Updates
flake.lockwith new versions - Does not activate changes (requires rebuild)
Update Specific Input:
nix flake lock --update-input nixpkgsAfter Update:
- Review changes in
flake.lock - Rebuild to apply:
<leader>nr - Rollback if issues:
sudo nixos-rebuild switch --rollback
Enter project-specific development environment:
" In NeoVim
<leader>ndThis runs nix develop, which:
- Reads
flake.nixorshell.nixin current directory - Provides specified packages and environment variables
- Enters shell with development tools available
Python Development:
# shell.nix or flake.nix devShell
{
buildInputs = with pkgs; [
python311
python311Packages.pip
python311Packages.virtualenv
];
}Rust Development:
{
buildInputs = with pkgs; [
rustc
cargo
rust-analyzer
];
}Node.js Development:
{
buildInputs = with pkgs; [
nodejs_20
nodePackages.npm
];
}-
Create
flake.nixin project root:{ description = "Project development environment"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; outputs = { self, nixpkgs }: let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; in { devShells.${system}.default = pkgs.mkShell { buildInputs = with pkgs; [ # Add development dependencies here ]; }; }; }
-
Enter environment:
<leader>nd -
Work on project with available tools
-
Exit:
exitorCtrl-D
Syntax highlighting for Nix files is provided by Tree-sitter:
- Language: Nix expression language
- File Types:
.nixfiles - Features: Syntax highlighting, indentation, folding
Configuration: Automatic through nvim-treesitter with Nix parser
While not currently configured by default, LSP support can be added:
Available LSP Servers:
- nil: Nix language server
- rnix-lsp: Nix language server (older)
To Enable:
- Install LSP server: Add to system packages
- Configure in
lspconfig.lua:lspconfig.nil_ls.setup({})
- Restart NeoVim
" In NeoVim
<leader>ngThis runs nix-collect-garbage -d, which:
- Removes old generations
- Deletes unused store paths
- Frees disk space
Effect: Removes previous system generations, making rollback impossible
Configure automatic garbage collection in /etc/nixos/configuration.nix:
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 30d";
};Check Disk Usage:
# Show Nix store size
du -sh /nix/store
# Show generations
nix-env --list-generations
# Delete specific generation
nix-env --delete-generations [number]Optimize Store:
# Remove duplicate files
nix-store --optimiseIf a rebuild causes issues, rollback to previous generation:
Command Line:
# Rollback to previous generation
sudo nixos-rebuild switch --rollback
# List available generations
nix-env --list-generations --profile /nix/var/nix/profiles/system
# Boot specific generation
sudo nixos-rebuild switch --switch-generation [number]Boot Menu:
- Reboot system
- Select "NixOS - [previous generation]" in GRUB
- System boots with previous configuration
-
Edit Configuration
- Open
/etc/nixos/configuration.nixorflake.nix - Make changes (add packages, modify services, etc.)
- Save file
- Open
-
Test Build (optional)
nixos-rebuild test --flake .
This activates changes without making boot default
-
Apply Changes
<leader>nrRebuilds and makes changes permanent
-
Verify
- Check that services work:
systemctl status [service] - Verify packages available:
which [command] - Test functionality
- Check that services work:
-
Rollback if Needed
sudo nixos-rebuild switch --rollback
For user-specific configuration:
- Edit
home.nixor equivalent - Apply:
<leader>nh - Verify: Check that dotfiles and packages updated
- Rollback:
home-manager generationsand select previous
Plugin Installation:
- Plugins managed through
lazy.nvim, not system packages - LSP servers can be system-wide (via Nix) or Mason-installed
Path Configuration:
- NixOS uses
/nix/store/for packages - System paths configured in
/etc/nixos/configuration.nix - User paths configured through home-manager
Environment Variables:
- Set in NixOS configuration for system-wide effect
- Set in
home.nixfor user-specific settings
This NeoVim configuration can be managed through Nix:
Option 1: System Package:
environment.systemPackages = with pkgs; [
neovim
];Option 2: Home Manager:
programs.neovim = {
enable = true;
# Additional configuration here
};Option 3: Manual Installation (current approach):
- NeoVim installed through Nix
- Configuration in
~/.config/nvim/ - Managed separately from NixOS configuration
| Operation | Keybinding | Command |
|---|---|---|
| System rebuild | <leader>nr |
sudo nixos-rebuild switch --flake . |
| Home-manager | <leader>nh |
home-manager switch --flake . |
| Update flake | <leader>nu |
nix flake update |
| Dev shell | <leader>nd |
nix develop |
| Garbage collect | <leader>ng |
nix-collect-garbage -d |
| Package search | <leader>np |
Opens https://search.nixos.org |
| Purpose | Path |
|---|---|
| System config | /etc/nixos/configuration.nix |
| Flake config | /etc/nixos/flake.nix |
| Home config | ~/.config/home-manager/home.nix |
| Store | /nix/store/ |
| Profiles | /nix/var/nix/profiles/ |
- ARCHITECTURE.md - System architecture overview
- INSTALLATION.md - Initial setup and installation
- Editor Plugins README - Plugin configurations
NixOS integration provides:
- Declarative system configuration: Reproducible system state
- Easy rollback: Previous generations always available
- Development environments: Project-specific tool versions
- Package management: Consistent package versions across system
These workflows integrate NixOS system management directly into the NeoVim editing experience, reducing context switching between editor and terminal.