wip
This commit is contained in:
parent
546c5170d7
commit
433967847a
29 changed files with 1251 additions and 335 deletions
156
README.md
156
README.md
|
|
@ -2,140 +2,46 @@
|
|||
|
||||
This repository contains my dotfiles and a Nix flake that supports multiple hosts (machines) with a shared base and per-host configuration.
|
||||
|
||||
- On NixOS: hosts are built via `nixosConfigurations`.
|
||||
- On non-NixOS (e.g., Ubuntu): hosts are applied via Home Manager using `homeConfigurations`.
|
||||
## Nix Configuration
|
||||
|
||||
## Bootstrap
|
||||
The Nix configuration is located in the `nix/` directory. It uses a shared Home Manager configuration for all hosts, while allowing host-specific NixOS or package settings.
|
||||
|
||||
```shell
|
||||
pip install pipx ansible
|
||||
ansible-playbook --ask-become-pass ansible/main.yml
|
||||
# Then apply dotfiles with dotter
|
||||
dotter
|
||||
```
|
||||
### Structure
|
||||
|
||||
## NixOS: multi-host layout
|
||||
- `nix/flake.nix`: Entry point, defines hosts and helpers.
|
||||
- `nix/home/`: Shared Home Manager configuration (packages, shell, GNOME settings).
|
||||
- `nix/hosts/`: Host-specific NixOS configurations.
|
||||
|
||||
- nix/base/packages.nix — packages installed on all hosts
|
||||
- nix/hosts/<host>/
|
||||
- configuration.nix — host-specific NixOS configuration
|
||||
- hardware-configuration.nix — generated per-machine
|
||||
- packages.nix — extra packages for this host
|
||||
- nix/flake.nix — exposes each host under nixosConfigurations
|
||||
### Adding New Hosts
|
||||
|
||||
Current hosts:
|
||||
- limgrave — my main system
|
||||
- carpates — scaffolded/minimal, ready to extend
|
||||
#### NixOS Hosts
|
||||
1. Create a directory in `nix/hosts/<hostname>/`.
|
||||
2. Add `configuration.nix`, `hardware-configuration.nix`, and `packages.nix` there.
|
||||
3. Add the host to `nixosConfigurations` in `nix/flake.nix`:
|
||||
```nix
|
||||
limgrave = mkNixos "limgrave" [
|
||||
nix-snapd.nixosModules.default
|
||||
autofirma-nix.nixosModules.default
|
||||
];
|
||||
```
|
||||
|
||||
## Naming rule (important)
|
||||
Your machine hostname must match the Nix flake host name. For example:
|
||||
- networking.hostName = "limgrave" in the host configuration
|
||||
- The flake exports nixosConfigurations.limgrave
|
||||
- The system hostname (output of `hostname -s`) is limgrave
|
||||
#### Non-NixOS Hosts (e.g., Ubuntu)
|
||||
1. Add the host to `homeConfigurations` in `nix/flake.nix`:
|
||||
```nix
|
||||
"catalin@ubuntu" = mkHome "ubuntu" "catalin" [ ];
|
||||
```
|
||||
*Note: `mkHome` takes `hostname`, `username`, and additional modules.*
|
||||
|
||||
This allows the upgrade function to pick the right configuration automatically.
|
||||
|
||||
## Build or switch
|
||||
From repo root:
|
||||
### Building and Applying
|
||||
|
||||
#### NixOS
|
||||
Run from the root of the repository:
|
||||
```bash
|
||||
# Limgrave (current system)
|
||||
sudo nixos-rebuild switch --flake ./nix#limgrave
|
||||
|
||||
# carpates (on target machine)
|
||||
sudo nixos-rebuild switch --flake ./nix#carpates
|
||||
# Or during install:
|
||||
# nixos-install --flake <repo-path>/nix#carpates
|
||||
sudo nixos-rebuild switch --flake .#hostname
|
||||
```
|
||||
|
||||
## Upgrades: nix_upgrade
|
||||
A convenience Fish function is provided in fish/conf.d/functions.fish: `nix_upgrade`.
|
||||
It updates flake inputs and rebuilds the system using a host name that matches the machine hostname.
|
||||
|
||||
Usage:
|
||||
```fish
|
||||
# Automatic: uses (hostname -s) → must match a host in nix/flake.nix
|
||||
nix_upgrade
|
||||
|
||||
# Override the host explicitly (useful for recovery or chroots)
|
||||
nix_upgrade limgrave
|
||||
```
|
||||
What it does:
|
||||
1) sudo nix flake update --flake /home/catalin/.dotfiles/nix
|
||||
2) sudo nixos-rebuild switch --flake /home/catalin/.dotfiles/nix#<host> --upgrade
|
||||
|
||||
Safety checks:
|
||||
- Verifies nix/flake.nix exists
|
||||
- Verifies the host is declared in nix/flake.nix
|
||||
- Prints clear error if the hostname doesn’t map to a known host
|
||||
|
||||
Tip: ensure your system hostname matches one of the directories in nix/hosts/ and the entry under nixosConfigurations in nix/flake.nix.
|
||||
|
||||
## Adding a new host
|
||||
1) Create a directory: nix/hosts/<newhost>/
|
||||
2) Add configuration files (start by copying limgrave and trimming, or use the minimal example from carpates)
|
||||
3) Generate hardware config on the new machine:
|
||||
#### Non-NixOS (Home Manager)
|
||||
Run from the root of the repository:
|
||||
```bash
|
||||
sudo nixos-generate-config
|
||||
# Move merge the generated hardware-configuration.nix into nix/hosts/<newhost>/
|
||||
```
|
||||
4) Add the host to nix/flake.nix under nixosConfigurations
|
||||
5) Make sure networking.hostName = "<newhost>" in the host configuration
|
||||
6) Build or install:
|
||||
```bash
|
||||
sudo nixos-rebuild switch --flake ./nix#<newhost>
|
||||
# or during install:
|
||||
nixos-install --flake <repo-path>/nix#<newhost>
|
||||
```
|
||||
|
||||
## Notes
|
||||
- Old single-host files nix/configuration.nix and nix/packages.nix are kept for reference but are not used by the flake. You can remove them once comfortable with the new layout.
|
||||
- limgrave includes nix-snapd and Home Manager; carpates currently includes Home Manager only.
|
||||
|
||||
## Nix on non-NixOS (Ubuntu, etc.)
|
||||
You can also use this flake on non-NixOS systems (e.g., Ubuntu) via Home Manager. For that path, hosts are defined under `homeConfigurations` in `nix/flake.nix` and typically live next to their NixOS counterparts. In this repo, `carpates` is prepared for non-NixOS via Home Manager.
|
||||
|
||||
- Naming rule: your machine's hostname (output of `hostname -s`) should match the `homeConfigurations.<host>` entry. Example: `carpates`.
|
||||
- Packages: non-NixOS hosts usually install user-scoped packages via Home Manager, using the shared base set from `nix/base/packages.nix`.
|
||||
|
||||
### Prerequisites
|
||||
- Install Nix (multi-user is recommended):
|
||||
```bash
|
||||
sh <(curl -L https://nixos.org/nix/install) --daemon
|
||||
```
|
||||
- Enable flakes (if not already). On non-NixOS, set in `/etc/nix/nix.conf` or `$XDG_CONFIG_HOME/nix/nix.conf`:
|
||||
```
|
||||
experimental-features = nix-command flakes
|
||||
```
|
||||
- Install Home Manager (no separate channel needed when using flakes; we can run it via `nix run` or install it on PATH):
|
||||
```bash
|
||||
# Optional, to have `home-manager` on PATH:
|
||||
nix profile install github:nix-community/home-manager
|
||||
```
|
||||
|
||||
### Apply the configuration (non-NixOS)
|
||||
From repo root:
|
||||
```bash
|
||||
# Use the prepared Home Manager host (example: carpates)
|
||||
home-manager switch --flake ./nix#carpates
|
||||
# If `home-manager` is not installed, you can run it via nix:
|
||||
nix run github:nix-community/home-manager -- switch --flake ./nix#carpates
|
||||
```
|
||||
|
||||
### Upgrades (non-NixOS)
|
||||
`nix_upgrade` also works on non-NixOS:
|
||||
```fish
|
||||
# Auto-detects host from (hostname -s) and runs Home Manager switch
|
||||
nix_upgrade
|
||||
|
||||
# Or override explicitly
|
||||
nix_upgrade carpates
|
||||
```
|
||||
What it does on non-NixOS:
|
||||
- `nix flake update --flake /home/catalin/.dotfiles/nix`
|
||||
- `home-manager switch --flake /home/catalin/.dotfiles/nix#<host>` (or `nix run ... -- switch` if HM is not on PATH)
|
||||
|
||||
### NixOS vs. non-NixOS summary
|
||||
- NixOS hosts are declared under `nixosConfigurations` and are applied with `nixos-rebuild`.
|
||||
- non-NixOS hosts are declared under `homeConfigurations` and are applied with `home-manager switch`.
|
||||
- The `nix_upgrade` function detects the OS and selects the correct path automatically based on the hostname.
|
||||
home-manager switch --flake ./nix#user@hostname
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue