This repository contains the Nix / NixOS configuration for all of my systems. See nixos-flake if you want to create your own configuration from scratch.
To use this repository as base configuration for your new machine running:
Tip
For a general tutorial, see https://nixos.asia/en/nixos-install-flake
- Install NixOS
- Hetzner dedicated from Linux Rescue system: https://github.com/numtide/nixos-anywhere (see blog post; example PR: srid#35 where I had to configure networking manually)
- Copy from existing configuration (eg: ax41.nix)
- Make networking configuration changes.
- Run nixos-anywhere from a Linux system, targetting
root@<ip> - Wait for reboot;
ssh srid@<ip>; profit!
- Digital Ocean
- Legacy/manual approach: nixos-infect
- Modern/automate approach: Custom image + colerama; cf. Zulip and example
- X1 Carbon: https://srid.ca/x1c7-install
- Windows (via WSL): https://github.com/nix-community/NixOS-WSL
- Hetzner dedicated from Linux Rescue system: https://github.com/numtide/nixos-anywhere (see blog post; example PR: srid#35 where I had to configure networking manually)
- Clone this repo anywhere
- Edit
flake.nixto use your system hostname as a key of thenixosConfigurationsset - Edit
users/config.nixto contain your users - Run
nix run. That's it. Re-open your terminal.
- Install Nix
- Clone this repo anywhere
- Edit
flake.nixto use your system hostname as a key of thedarwinConfigurationsset - Edit
users/config.nixto contain your users - Run
nix run.1 That's it. Re-open your terminal.
Start from flake.nix (see Flakes). flake-parts is used as the module system.
home: home-manager config (shared between Linux and macOS)nixos: nixos modules for Linuxnix-darwin: nix-darwin modules for macOSusers: user informationsystems: top-level configuration.nix('ish) for various systems
- To update NixOS (and other inputs) run
nix flake update- You may also update a subset of inputs, e.g.
nix flake lock --update-input nixpkgs --update-input darwin --update-input home-manager # Or, `nix run .#update`
- You may also update a subset of inputs, e.g.
- To free up disk space,
sudo nix-env -p /nix/var/nix/profiles/system --delete-generations +2 sudo nixos-rebuild boot
- To autoformat the project tree using nixfmt(rfc-style) run
nix fmt. - To build all flake outputs (locally or in CI), run
nix --accept-flake-config run github:juspay/omnix ci build - For secrets management, I use ragenix.
If you wish to discuss about this config, join the Zulip.
Using nixos-infect (Successful on Ubuntu 24.04 LTS x64)
To install Manually,
curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-23.05 bash -xOr Automatically using Cloud-Init User-Data,
#!/bin/sh
curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-23.05 bashAfter nix is instantiated, change and update nix channels.
nix-channel --add https://channels.nixos.org/nixos-24.05 nixos
nix-channel --add https://channels.nixos.org/nixos-unstable nixos-unstable
nix-channel --updateAnd then bootstrap with manual script ./manual_scripts/init-configuration.nix.
nixos-rebuild switchAfter bootstrapping, install further with flake configs with created user.
mkdir -p ~/repos/nixos/config && cd $_
git clone https://github.com/testfailed/nixos-config-srid
cd nixos-config-srid
nixos-rebuild switchBuild into the nix store.
nix-build ./examples/what-is-my-ip.nix
# Visualize the dependency graph.
nix-store --query --graph $(nix-build ./examples/what-is-my-ip.nix) | \
dot -Tsvg -o what-is-my-ip-deps.svgBuild and include in a shell environment.
nix-shell ./examples/what-is-my-ip-shell.nixBuild into a docker image and run it.
docker load < $(nix-build ./examples/what-is-my-ip-docker.nix)
# => Loaded image: what-is-my-ip-docker:c9g6x30invdq1bjfah3w1aw5w52vkdfn
docker run -it --rm what-is-my-ip-docker:c9g6x30invdq1bjfah3w1aw5w52vkdfnFootnotes
-
You might have to
rm -rf /etc/nix/nix.conf, so our flake.nix can do its thing. ↩