3.7 KiB
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 access to the machine you want to configure
Initial Setup
1. Cloning the Repository
Clone this repository to your local machine:
git clone ssh://nix-apps@localhost:2222/mjallen/nix-config.git
cd nix-config
2. Setting Up a New System
Option 1: Using an Existing Configuration
If you're setting up a new machine that should be identical to an existing configuration:
- Boot from a NixOS installation media
- Mount your target partitions to
/mnt - Clone this repository:
nixos-enter cd /mnt mkdir -p /mnt/etc/nixos git clone ssh://nix-apps@localhost:2222/mjallen/nix-config.git /mnt/etc/nixos - Install NixOS with the desired system profile:
Replace
nixos-install --flake /mnt/etc/nixos#hostnamehostnamewith the target system name (e.g.,matt-nixos,jallen-nas, etc.)
Option 2: Creating a New System Configuration
If you're adding a completely new system:
-
Create a new directory for your system configuration:
mkdir -p systems/$(uname -m)-linux/new-hostname -
Create the basic configuration files:
cat > systems/$(uname -m)-linux/new-hostname/default.nix << EOF { lib, pkgs, ... }: { imports = [ ./hardware-configuration.nix # Add other needed module imports here ]; networking.hostName = "new-hostname"; # Add your system-specific configuration here } EOF -
Generate the hardware configuration:
nixos-generate-config --no-filesystems --dir systems/$(uname -m)-linux/new-hostname/ -
Add your new system to the flake by adding it to the
hostssection inflake.nix -
Build and install the configuration:
sudo nixos-rebuild switch --flake .#new-hostname
Secret Management
Setting Up Sops-Nix
-
Create a GPG key if you don't already have one:
gpg --full-generate-key -
Add your key to
.sops.yaml:# Get your key fingerprint gpg --list-secret-keys --keyid-format=long # Edit the .sops.yaml file to add your key -
Create a new encrypted secret:
sops secrets/newsecret.yaml
Common Tasks
Updating the Repository
git pull
sudo nixos-rebuild switch --flake .#hostname
Adding a New Package
-
For standard packages, add them to your system or home configuration:
environment.systemPackages = with pkgs; [ new-package ]; -
For custom packages, add them to the
packagesdirectory:mkdir -p packages/new-package # Create the necessary Nix files
Adding a New Module
-
Create a new module directory:
mkdir -p modules/nixos/new-module -
Create the module files:
# Create options.nix cat > modules/nixos/new-module/options.nix << EOF { lib, namespace, ... }: with lib; { options.${namespace}.new-module = { enable = mkEnableOption "Enable new module"; # Add other options here }; } EOF # Create default.nix cat > modules/nixos/new-module/default.nix << EOF { config, lib, namespace, ... }: let cfg = config.${namespace}.new-module; in { imports = [ ./options.nix ]; config = lib.mkIf cfg.enable { # Add your configuration here }; } EOF -
Import your module in your system configuration:
imports = [ # ... ../../../modules/nixos/new-module ]; ${namespace}.new-module.enable = true;