4.0 KiB
Executable File
Getting Started
This guide will help you get started with this NixOS configuration repository.
Prerequisites
- Basic knowledge of NixOS and the Nix language
- Git installed on your system
- Physical or SSH access to the target machine
Cloning the Repository
git clone ssh://nix-apps@localhost:2222/mjallen/nix-config.git
cd nix-config
Installing on a New Machine
Option 1: Using an existing system configuration
If the machine matches an existing configuration (e.g. reinstalling jallen-nas):
- Boot from a NixOS installation ISO
- Partition and mount disks (or use
disko):nix run github:nix-community/disko -- --mode disko /path/to/disko-config.nix - Clone this repo into the target:
mkdir -p /mnt/etc/nixos git clone <repo-url> /mnt/etc/nixos - Install:
nixos-install --flake /mnt/etc/nixos#hostname
Option 2: Adding a new system configuration
-
Create the system directory under the appropriate architecture:
mkdir -p systems/x86_64-linux/new-hostname -
Write the configuration — at minimum a
default.nix:{ namespace, ... }: { mjallen = { sops.enable = true; network.hostName = "new-hostname"; user.name = "admin"; }; } -
Generate hardware configuration (on the target machine):
nixos-generate-config --no-filesystems --dir systems/x86_64-linux/new-hostname/ -
Add SOPS secrets for the new host — see Secrets Management.
-
Build and switch:
sudo nixos-rebuild switch --flake .#new-hostname
Day-to-Day Usage
Applying configuration changes
# On the local machine
sudo nixos-rebuild switch --flake .#$(hostname)
# On a remote machine
nixos-rebuild switch --flake .#hostname --target-host user@host --use-remote-sudo
Updating flake inputs
# Update all inputs
nix flake update
# Update a single input
nix flake lock --update-input nixpkgs
# Apply after updating
sudo nixos-rebuild switch --flake .#$(hostname)
Garbage collection
# Remove old generations and unreferenced store paths
sudo nix-collect-garbage -d
# Keep the last N generations
sudo nix-collect-garbage --delete-older-than 30d
Enabling a Module
Most functionality is exposed through the mjallen namespace. To enable a module, set it in the system's default.nix (or a relevant sub-file):
mjallen = {
desktop.gnome.enable = true;
hardware.amd.enable = true;
gaming.enable = true;
services.jellyfin = {
enable = true;
port = 8096;
reverseProxy.enable = true;
};
};
See Custom Modules for the full list of available modules and options.
Adding a New Service Module
-
Create the module directory:
mkdir -p modules/nixos/services/my-service -
Write
default.nixusing themkModulehelper:{ config, lib, namespace, pkgs, ... }: let name = "my-service"; nebulaConfig = lib.${namespace}.mkModule { inherit config name; description = "my service description"; options = { }; moduleConfig = { services.my-service = { enable = true; port = config.${namespace}.services.${name}.port; }; }; }; in { imports = [ nebulaConfig ]; } -
Enable it in a system configuration:
mjallen.services.my-service = { enable = true; port = 1234; };
Adding a New Package
-
Create a directory under
packages/:mkdir packages/my-package -
Write a
default.nixthat returns a derivation. The package will be available aspkgs.mjallen.my-packagein all configurations.
Secrets
See the Secrets Management section of the root README for:
- How age keys are derived from SSH host keys
- Adding a new machine as a SOPS recipient
- Adding/editing secrets
- Generating Nebula VPN certificates