mirror of
https://github.com/xiej2520/nix_config.git
synced 2026-08-17 21:29:50 -05:00
configs, probably doesn't have secrets committed
- Nix 58%
- Lua 31.9%
- Vim Script 5.1%
- Shell 4.7%
- Python 0.3%
| dev | ||
| home-manager | ||
| hosts | ||
| modules | ||
| overlays | ||
| pkgs | ||
| scripts | ||
| flake.lock | ||
| flake.nix | ||
| gc_log.md | ||
| README.md | ||
| switch.sh | ||
NixOS Config
Usage
jjorgit addany new filesnh
nh os switch .
nh home switch .
Setup
# 1. Install nix, enable flakes
export NIX_CONFIG="experimental-features = nix-command flakes"
# 2. Generate host config `/etc/nixos/{configuration.nix, hardware-configuration.nix}`
sudo nixos-generate-config
cp ~/etc/nixos/hardware-configuration ./hosts/<HOST>/hardware-configuration
# 3. Switch to config
nix-shell -p home-manager
HOST=<HOSTNAME> USER=<USERNAME> ./switch.sh
Organization
.#xiej@WORKING-DESKTOP.#xiej@WORKING-LAPTOP
Notes
nix commands
nix flake check
nix flake update
# generate /etc/nixos/{configuration.nix, hardware-configuration.nix}
sudo nixos-generate-config
# apply system configuration
# {switch, boot, test}
sudo nixos-rebuild switch --flake .#{hostname}
# apply home configuration
home-manager switch --flake .#username@hostname
# old configurations
home-manager generations
# switch to old generation
/nix/store/{hash}-home-manager-generation/activate
# launch shell with output of flake
nix-shell -p {package}
nix shell nixpkgs#{package}
# create shell with buildInputs and env variables
nix develop nixpkgs#{package}
# create shell with output of .#devShells.<system>.default or packages.<system>.default
nix develop
# use flake > .envrc => loads devShells.default
# run program
nix run nixpkgs#{package}
# collect garbage
sudo nix-collect-garbage --delete-older-than 30d
# optimize nix store
sudo nix-store --optimise
# /boot/kernels full of old generations: collect garbage then nh os switch .
nh commands
nh os switch . -H <HOSTNAME>
nh home switch .
nh os switch --update .
nh home switch --update .
nh search <pkg>
nh clean
error booting grub /etf/Microsoft/... not found
- make sure fast boot disabled, windows isn't in hibernate
Custom Components
Packages
Add a derivation inside pkgs under pkgs/{package name}/default.nix, and call it with
pkgs.callPackage in pkgs/default.nix.
Overlays
See overlays/default.nix. Use overlays to patch across the entire nixpkgs, e.g. set compile options
for a library, but requires compiling everything depending on it.
Overrides
Prefer overrides when possible for making a change to a single package.
Modules
Custom modules with options/configurations go under modules/nixos or modules/home-manager.
Add to modules/nixos/default.nix or modules/home-manager/default.nix.
WSL
-
Enable WSL
wsl --install --no-distribution -
Download
nixos-wsl.tar.gz. -
Import
wsl --import NixOS --version 2 $env:USERPROFILE\NixOS\ nixos-wsl.tar.gz -
Run
wsl -d NixOS
distrobox
distrobox create -n ubuntu -i ubuntu:latest -H ~/ubuntu
distrobox create -n ubuntu -i ubuntu:latest -H ~/ubuntu --additional-packages "systemd libpam-systemd pipewire-audio-client-libraries"
distrobox enter ubuntu
nvim subtree
Submodules don't work with flakes, using subtree for nvim-config.
git subtree pull --prefix home-manager/nvim-config https://github.com/xiej2520/nvim_config main --squash
git subtree push --prefix home-manager/nvim-config https://github.com/xiej2520/nvim_config main
git push https://github.com/xiej2520/nvim_config `git subtree split --prefix=home-manager/nvim_config main`:forcepush --force