nixos/readme.md

150 lines
4.3 KiB
Markdown
Raw Normal View History

2026-03-28 15:57:10 +00:00
# FredOS NixOS Configuration
2026-03-28 16:02:40 +00:00
Flake-based NixOS configuration for three machines, built and deployed directly from GitHub. No local config management required after initial setup.
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
## Machines
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
| Hostname | Description |
|---|---|
| FredOS-Gaming | AMD desktop, UEFI/systemd-boot |
| FredOS-Macbook | Intel laptop, UEFI/systemd-boot |
| FredOS-Mediaserver | Intel server, BIOS/GRUB |
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
## Structure
2026-03-28 15:57:10 +00:00
```
flake.nix # Flake inputs and host definitions
2026-03-28 16:02:40 +00:00
common.nix # Shared config for all hosts
2026-03-28 15:57:10 +00:00
hosts/
2026-03-28 16:02:40 +00:00
FredOS-Gaming.nix # Gaming-specific config
FredOS-Macbook.nix # Macbook-specific config
FredOS-Mediaserver.nix # Mediaserver-specific config
2026-03-28 15:57:10 +00:00
hardware/
2026-03-28 16:02:40 +00:00
FredOS-Gaming.nix # Hardware config + bootloader
2026-03-28 15:57:10 +00:00
FredOS-Macbook.nix
FredOS-Mediaserver.nix
apps/ # Per-app config files
2026-03-28 16:02:40 +00:00
settings/ # Shared system settings (GNOME, locale, audio, etc.)
services/ # Service definitions
2026-03-28 15:57:10 +00:00
home-manager/ # Home Manager config
walls/ # Wallpapers
```
2026-03-28 16:02:40 +00:00
## Day-to-day usage
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
Edit files directly on GitHub, then on the machine run:
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
```bash
update
```
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
That's it. The alias is defined in `common.nix` and expands to:
```bash
sudo nixos-rebuild switch --flake github:ediblerope/nixos-config --refresh --no-write-lock-file
```
Nix automatically matches the running machine's hostname to the correct `nixosConfigurations` entry.
Other useful aliases:
```bash
clean # sudo nix-collect-garbage -d
```
2026-03-28 15:57:10 +00:00
---
## Adding a new machine
### 1. Fresh NixOS install
2026-03-28 16:02:40 +00:00
Boot the NixOS installer and complete the standard installation. Note the `system.stateVersion` it generates — you'll need it later.
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
### 2. Enable flakes temporarily
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
Add this to `/etc/nixos/configuration.nix` and rebuild:
2026-03-28 15:57:10 +00:00
```nix
nix.settings.experimental-features = [ "nix-command" "flakes" ];
```
2026-03-28 16:02:40 +00:00
```bash
sudo nixos-rebuild switch
```
2026-03-28 15:57:10 +00:00
### 3. Create the hardware config on GitHub
2026-03-28 16:02:40 +00:00
Copy the contents of `/etc/nixos/hardware-configuration.nix` and create `hosts/hardware/FredOS-NEWHOST.nix` on GitHub. Append the following to it:
2026-03-28 15:57:10 +00:00
```nix
networking.hostName = "FredOS-NEWHOST";
2026-03-28 16:02:40 +00:00
# Match what the installer configured — systemd-boot for UEFI:
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
boot.loader.systemd-boot.configurationLimit = 5;
boot.initrd.systemd.enable = true;
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
# For BIOS/GRUB machines instead:
# boot.loader.grub.enable = true;
# boot.loader.grub.devices = [ "/dev/sda" ]; # verify with: sudo grub-probe --target=disk /
2026-03-28 15:57:10 +00:00
nix.settings.experimental-features = [ "nix-command" "flakes" ];
2026-03-28 16:02:40 +00:00
system.stateVersion = "25.11"; # use the version the installer generated
2026-03-28 15:57:10 +00:00
```
2026-03-28 16:02:40 +00:00
### 4. Register the host in flake.nix
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
In `flake.nix` on GitHub, add to `nixosConfigurations`:
2026-03-28 15:57:10 +00:00
```nix
FredOS-NEWHOST = mkHost "FredOS-NEWHOST";
```
2026-03-28 16:02:40 +00:00
### 5. Add host-specific config
2026-03-28 15:57:10 +00:00
2026-03-28 16:02:40 +00:00
Create `hosts/FredOS-NEWHOST.nix` on GitHub for any machine-specific packages or services:
2026-03-28 15:57:10 +00:00
```nix
{ config, pkgs, lib, ... }:
{
config = lib.mkIf (config.networking.hostName == "FredOS-NEWHOST") {
2026-03-28 16:02:40 +00:00
# host-specific config here
2026-03-28 15:57:10 +00:00
};
}
```
Then add it to the imports list in `common.nix`:
```nix
./hosts/FredOS-NEWHOST.nix
```
### 6. Switch to the flake
2026-03-28 16:02:40 +00:00
Run this once on the new machine with the explicit hostname:
2026-03-28 15:57:10 +00:00
```bash
sudo nixos-rebuild switch --flake github:ediblerope/nixos-config#FredOS-NEWHOST --refresh --no-write-lock-file
```
2026-03-28 16:02:40 +00:00
After this succeeds, the plain `update` alias works from then on.
2026-03-28 15:57:10 +00:00
---
2026-03-28 16:02:40 +00:00
## Flake inputs
| Input | Source |
|---|---|
| nixpkgs | `github:NixOS/nixpkgs/nixos-unstable` |
| home-manager | `github:nix-community/home-manager` |
| omnisearch | `git+https://git.bwaaa.monster/omnisearch` |
| zen-browser | `github:0xc000022070/zen-browser-flake` |
| nix-flatpak | `github:gmodena/nix-flatpak` |
2026-03-28 15:57:10 +00:00
## Notes
2026-03-28 16:02:40 +00:00
- `hosts/hardware/` files are committed to the repo — they contain UUIDs and disk layout but no sensitive credentials
- Host-specific behaviour is gated with `lib.mkIf (config.networking.hostName == "...")` or `lib.elem config.networking.hostName [...]`
- GitHub API rate limit (60 req/hour unauthenticated) can occasionally be hit if running `update` many times in quick succession during active config changes — wait ~15 minutes and retry