Archived
Compare commits
8
Commits
48a879e2a0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cae8a2fcd | ||
|
|
8d6ad63094 | ||
|
|
dd2d3b5914 | ||
|
|
0c70c63371 | ||
|
|
5a7bdea454 | ||
|
|
9db659d54e | ||
|
|
02ea1929e5 | ||
|
|
a90e736743 |
No files matched your search
+5
-1
@@ -1 +1,5 @@
|
||||
result
|
||||
result
|
||||
|
||||
# Locally-generated SSH host keys staged for transfer to a new machine
|
||||
# during install (see scripts/prepare-host-key.sh) — never commit these.
|
||||
host-keys/
|
||||
@@ -4,10 +4,10 @@ This repository builds a custom NixOS installer environment that can automatical
|
||||
install any host exposed by a separate NixOS flake.
|
||||
|
||||
The installer provides a small NixOS netboot/install environment with SSH access,
|
||||
Git support, and an interactive installation script. When the `nixos` user logs
|
||||
in, it runs `/etc/auto-install.sh`, discovers available hosts from the target
|
||||
flake, allows the operator to choose a system profile, applies the matching
|
||||
Disko storage configuration, installs NixOS, and reboots.
|
||||
Git support, and an interactive installation script. Logging in as any user
|
||||
(root or `nixos`) runs `/etc/auto-install.sh`, discovers available hosts from
|
||||
the target flake, allows the operator to choose a system profile, applies the
|
||||
matching Disko storage configuration, installs NixOS, and reboots.
|
||||
|
||||
The installer is designed for a mixed environment where different machines may
|
||||
have different storage layouts, including Proxmox VMs, Linode instances, and
|
||||
@@ -18,17 +18,35 @@ defined by each host's NixOS configuration using Disko.
|
||||
|
||||
* `flake.nix`
|
||||
|
||||
* Defines the installer build outputs.
|
||||
* Builds an `install-iso` image using `nixos-generators`.
|
||||
* Defines the installer build outputs directly via `nixosSystem` (no
|
||||
external `nixos-generators` dependency).
|
||||
* `nixosConfigurations.installer` — ISO/netboot installer image.
|
||||
* `nixosConfigurations.proxmox-lxc` — Proxmox LXC-based installer image.
|
||||
* Builds netboot kernel, initrd, and iPXE scripts.
|
||||
|
||||
* `common.nix`
|
||||
|
||||
* Shared by every installer target (imported by both `installer.nix`
|
||||
and `proxmox-lxc.nix`).
|
||||
* Enables SSH access, configures Git credentials for the target flake
|
||||
repository, creates the `nixos` and `root` users.
|
||||
* Provides the generated `/etc/auto-install.sh` installation script and
|
||||
the `programs.bash.loginShellInit` hook that runs it on login.
|
||||
|
||||
* `installer.nix`
|
||||
|
||||
* Defines the installer environment.
|
||||
* Enables SSH access.
|
||||
* Configures Git access to the target flake repository.
|
||||
* Creates the `nixos` and `root` users.
|
||||
* Provides the generated `/etc/auto-install.sh` installation script.
|
||||
* ISO/netboot-specific: imports the stock `installation-cd-minimal.nix`
|
||||
module plus `common.nix`.
|
||||
|
||||
* `proxmox-lxc.nix`
|
||||
|
||||
* Proxmox LXC-specific: disables bootloader options (containers don't
|
||||
need one) plus `common.nix`.
|
||||
|
||||
* `scripts/prepare-host-key.sh`
|
||||
|
||||
* Admin-workstation pre-flight tool — see "Creating a New Machine"
|
||||
below.
|
||||
|
||||
The installed system configuration lives in a separate NixOS flake. Each target
|
||||
host is exposed through:
|
||||
@@ -53,41 +71,26 @@ The target machine requires:
|
||||
* A disk defined by its Disko configuration.
|
||||
* SSH access or local console access.
|
||||
|
||||
## Build The Installer ISO
|
||||
## Build Targets
|
||||
|
||||
From the repository root:
|
||||
Four packages, built directly from `nixosConfigurations.*` via
|
||||
`system.build.*` (no `nixos-generators` dependency):
|
||||
|
||||
```sh
|
||||
nix build
|
||||
nix build .#iso # installer ISO/netboot image (nixosConfigurations.installer)
|
||||
nix build .#lxc # Proxmox LXC installer tarball (nixosConfigurations.proxmox-lxc)
|
||||
nix build .#pxe # netboot-ipxe + netboot-initrd + netboot-kernel, bundled
|
||||
nix build .#all # all three of the above, bundled
|
||||
```
|
||||
|
||||
The generated installer ISO will be available through the `result` symlink.
|
||||
|
||||
The ISO is generated using:
|
||||
|
||||
```nix
|
||||
nixos-generators.nixosGenerate {
|
||||
format = "install-iso";
|
||||
}
|
||||
```
|
||||
|
||||
## Build Netboot Components
|
||||
|
||||
The flake also exposes netboot components:
|
||||
|
||||
```sh
|
||||
nix build .#netboot-ipxe
|
||||
nix build .#netboot-initrd
|
||||
nix build .#netboot-kernel
|
||||
```
|
||||
|
||||
These can be used to PXE boot the installer environment.
|
||||
Each one is available through the `result` symlink afterward (`result/iso/`,
|
||||
`result/tarball/`, or the bundle's subdirectories for `pxe`/`all`).
|
||||
|
||||
## Use The Installer
|
||||
|
||||
1. Boot the generated ISO or netboot environment on the target machine.
|
||||
|
||||
2. Log in as the `nixos` user.
|
||||
2. Log in as `root` or `nixos` (over SSH or local console).
|
||||
|
||||
3. The login shell launches:
|
||||
|
||||
@@ -199,7 +202,12 @@ The generated `/etc/auto-install.sh` performs the following steps:
|
||||
|
||||
6. Prepare `/mnt` using the Disko-generated mount configuration.
|
||||
|
||||
7. Install NixOS:
|
||||
7. Check for a pre-seeded SSH host key at `/root/host-keys/<host>_ssh_host_ed25519_key`
|
||||
and install it to `/mnt/etc/ssh/` if present (see "Creating a New
|
||||
Machine" below) — prompts for confirmation before continuing without
|
||||
one.
|
||||
|
||||
8. Install NixOS:
|
||||
|
||||
```sh
|
||||
nixos-install \
|
||||
@@ -207,9 +215,103 @@ The generated `/etc/auto-install.sh` performs the following steps:
|
||||
--no-root-password
|
||||
```
|
||||
|
||||
8. Remove temporary installation files.
|
||||
9. Remove temporary installation files.
|
||||
|
||||
9. Reboot.
|
||||
10. Reboot.
|
||||
|
||||
## Creating a New Machine
|
||||
|
||||
Full walkthrough for installing a new host, including the sops-nix
|
||||
pre-seeding step. Do this instead of jumping straight to "Use The
|
||||
Installer" whenever the target host consumes any secret managed by the
|
||||
`nixos` flake's sops-nix setup (as of this writing, that's every host —
|
||||
`modules/common/configuration.nix` puts the root/nixos password hash and
|
||||
the GitHub token behind sops-nix for all of them).
|
||||
|
||||
### Why the extra step exists
|
||||
|
||||
The `nixos` flake manages secrets with sops-nix, using an age key derived
|
||||
from each host's own `/etc/ssh/ssh_host_ed25519_key`. That key is normally
|
||||
generated by a systemd service (`sshd-keygen`) the first time a host boots
|
||||
— but sops-nix decrypts secrets during system *activation*, which runs
|
||||
**before** systemd starts pursuing the target `sshd-keygen` is gated
|
||||
behind. On a genuinely fresh install, that means secrets — including the
|
||||
login password — fail to decrypt on the very first boot unless the host
|
||||
key already exists beforehand. Pre-seeding it is what fixes that.
|
||||
|
||||
Machines that don't consume any sops-nix secret don't strictly need this,
|
||||
but since the shared password hash currently applies to every host, treat
|
||||
it as required unless you've specifically confirmed otherwise.
|
||||
|
||||
### Steps
|
||||
|
||||
**1. On your admin workstation** (the machine with `~/.config/sops/age/keys.txt`
|
||||
from the `nixos` repo's sops-nix setup), decide the new machine's flake
|
||||
target name (`<platform>-<buildtype>`, e.g. `proxmox-server`) and
|
||||
generate + register its host key:
|
||||
|
||||
```sh
|
||||
./scripts/prepare-host-key.sh <hostname> [path-to-nixos-repo]
|
||||
```
|
||||
|
||||
This generates `host-keys/<hostname>_ssh_host_ed25519_key(.pub)`
|
||||
locally and prints:
|
||||
|
||||
- the line to add under `keys:` in `nixos/.sops.yaml`
|
||||
- which `creation_rules` key_groups to add it to (`secrets/common.yaml`
|
||||
always; a per-host `secrets/<hostname>.yaml` too if this build type
|
||||
has its own secrets, same pattern as `nix-cache`/`server`)
|
||||
|
||||
**2. Edit `nixos/.sops.yaml`** by hand with the printed snippet, then
|
||||
re-encrypt every secrets file you added the new host to:
|
||||
|
||||
```sh
|
||||
nix-shell -p sops --run 'sops updatekeys nixos/secrets/common.yaml'
|
||||
```
|
||||
|
||||
**3. Commit and push the `nixos` repo.** The flake build the installer
|
||||
uses has to see the new recipient before you install, or decryption
|
||||
will fail on first boot regardless of step 4 below.
|
||||
|
||||
**4. Build and boot the installer image** on the target machine (ISO,
|
||||
netboot, or Proxmox LXC — see "Build Targets" above).
|
||||
|
||||
**5. Copy the generated private key onto the live installer environment**
|
||||
once it's reachable over SSH:
|
||||
|
||||
```sh
|
||||
scp host-keys/<hostname>_ssh_host_ed25519_key{,.pub} root@<target-ip>:/root/host-keys/
|
||||
```
|
||||
|
||||
**6. Log in** (as `root` or `nixos`) to trigger `/etc/auto-install.sh`
|
||||
automatically, or run it manually if it doesn't (see Troubleshooting).
|
||||
Select `<hostname>`'s flake target from the menu and confirm. The
|
||||
script will:
|
||||
|
||||
- run Disko to format and mount `/mnt`
|
||||
- find the key you copied in at `/root/host-keys/<hostname>_ssh_host_ed25519_key`
|
||||
and install it to `/mnt/etc/ssh/` — if it's missing, the script
|
||||
warns and asks for confirmation before continuing without it (fine
|
||||
for a host with no sops-nix secrets; for any other host, continuing
|
||||
anyway means the machine will boot with no working login password)
|
||||
- run `nixos-install` and reboot
|
||||
|
||||
**7. Verify after reboot.** SSH into the new machine and confirm secrets
|
||||
actually decrypted:
|
||||
|
||||
```sh
|
||||
ls /run/secrets/
|
||||
```
|
||||
|
||||
If that's empty or login fails, the most likely cause is the host's
|
||||
age key not being in `.sops.yaml` (or not re-encrypted into the
|
||||
secrets file it needs) at the time `nixos-install` ran — re-check
|
||||
steps 1–3, fix `nixos/.sops.yaml`/`secrets/*.yaml`, push, then
|
||||
re-run `nixos-install --flake <flake>#<hostname> --no-root-password`
|
||||
from a rescue/live environment against the existing `/mnt` (or just
|
||||
redo the install).
|
||||
|
||||
`host-keys/` is gitignored — never commit private key material.
|
||||
|
||||
## Configuration Notes
|
||||
|
||||
@@ -241,11 +343,11 @@ The installer currently assumes:
|
||||
|
||||
* The target host is responsible for defining its own storage layout.
|
||||
|
||||
Change these values in `installer.nix` if your environment differs.
|
||||
Change these values in `common.nix` if your environment differs.
|
||||
|
||||
## Security Notes
|
||||
|
||||
`installer.nix` currently contains:
|
||||
`common.nix` currently contains:
|
||||
|
||||
* Git credentials
|
||||
* Password hashes
|
||||
@@ -325,8 +427,18 @@ Verify:
|
||||
|
||||
### Installer does not start automatically
|
||||
|
||||
Run manually:
|
||||
It's triggered by `programs.bash.loginShellInit` (rendered into
|
||||
`/etc/profile`), which only fires for genuine login shells. If you're not
|
||||
seeing it — e.g. you attached to an existing shell rather than logging in
|
||||
fresh — run it manually:
|
||||
|
||||
```sh
|
||||
sudo /etc/auto-install.sh
|
||||
```
|
||||
|
||||
### Login succeeds but the machine has no working password after install
|
||||
|
||||
The new host's sops-nix secrets didn't decrypt on first boot — almost
|
||||
always because its age key wasn't registered in `nixos/.sops.yaml` and
|
||||
re-encrypted into the secrets file(s) it needs before `nixos-install` ran.
|
||||
See "Creating a New Machine" above, specifically step 7.
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
{ pkgs, lib, ... }:
|
||||
|
||||
{
|
||||
networking.useDHCP = lib.mkDefault true;
|
||||
|
||||
time.timeZone = "Australia/Brisbane";
|
||||
|
||||
# Without this, the installer only ever sees cache.nixos.org, which
|
||||
# doesn't carry sops-install-secrets (it's built straight from the
|
||||
# sops-nix flake's own Go source, not part of nixpkgs) — every install
|
||||
# would otherwise compile it from scratch, which is what ran an 8GB LXC
|
||||
# container's disk out of space. Push a built copy to nix-cache once
|
||||
# (from a machine with real disk headroom) and every future install,
|
||||
# of any type, fetches instead of rebuilding.
|
||||
nix.settings = {
|
||||
substituters = [
|
||||
"http://nix-cache"
|
||||
"https://cache.nixos.org/"
|
||||
];
|
||||
trusted-public-keys = [
|
||||
"cache.local-1:usoWYanY3Kpq2+kDIS2nhWoLZiRxanmdysdzqCFBHW4="
|
||||
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
|
||||
];
|
||||
};
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
git
|
||||
curl
|
||||
jq
|
||||
parted
|
||||
e2fsprogs
|
||||
btrfs-progs
|
||||
util-linux
|
||||
disko
|
||||
];
|
||||
|
||||
programs.git = {
|
||||
enable = true;
|
||||
|
||||
config = {
|
||||
credential.helper = "store --file=/etc/git-credentials";
|
||||
};
|
||||
};
|
||||
|
||||
environment.etc."git-credentials".text =
|
||||
"https://beatzaplenty:294be99829703536e02fdeed893137f1d8d96b76@gitea.lan.ddnsgeek.com";
|
||||
|
||||
# Run the installer on first login. Previously this copied an /etc file
|
||||
# into the nixos user's ~/.bash_profile via an activation script that
|
||||
# got dropped in a refactor (and only ever worked for that one user
|
||||
# anyway) — loginShellInit is NixOS's native hook for this, applies to
|
||||
# any user's login shell (root included), and needs no home-directory
|
||||
# file-copying/chown.
|
||||
programs.bash.loginShellInit = ''
|
||||
if [ -n "$PS1" ] && [ ! -e "$HOME/.auto_install_ran" ]; then
|
||||
sudo /etc/auto-install.sh
|
||||
touch "$HOME/.auto_install_ran"
|
||||
fi
|
||||
'';
|
||||
|
||||
|
||||
services.openssh.enable = true;
|
||||
|
||||
services.openssh.settings = {
|
||||
PermitRootLogin = "yes";
|
||||
PasswordAuthentication = true;
|
||||
};
|
||||
|
||||
|
||||
users.users.root = {
|
||||
hashedPassword =
|
||||
"$6$Kwv9KAyvcurAViQF$H4.u3feqGE7lVoNgkFXhE3n2Pmo//9JYDTCz8ifrVHBxPjwa1xMby7tEZ8Bpt5MXs9Rkx6/YbZWxs5CpH0s/70";
|
||||
};
|
||||
|
||||
|
||||
users.users.nixos = {
|
||||
isNormalUser = true;
|
||||
|
||||
extraGroups = [
|
||||
"wheel"
|
||||
];
|
||||
|
||||
shell = pkgs.bashInteractive;
|
||||
|
||||
hashedPassword =
|
||||
"$6$Kwv9KAyvcurAViQF$H4.u3feqGE7lVoNgkFXhE3n2Pmo//9JYDTCz8ifrVHBxPjwa1xMby7tEZ8Bpt5MXs9Rkx6/YbZWxs5CpH0s/70";
|
||||
|
||||
openssh.authorizedKeys.keys = [
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCq/Q5LvIXlZwO2kdeAN5nLGZ59nZB7JHYMEszHxmNtGMzv1lM31jiPNsr0z2EKVZhE7OOfa2IF9rhWYD7JUA9G0yzdZ4WTXFNGVVOJoOVH6vAF3XCxoVilOEwTc7h2Wiy+rzd0B28/3spffzQQWJhY6GRQVa8j+6xAGF60Fcvl1vLosYT9Bn2ZbK4TCWOwAn2jqXIieGpZdn/UNZbGOeKRiCvhktDfMAzuQzN/9jMu/oF4pkPn2X1UrsQdNlvp0Ci8md612MozIpncQJyAF1ADhunr3sMx0isUXiqD29R5DS4TftpekqLNLak+zcxFa8N7DcRNp3DcKfJvyTkwQrR4r+b7lFLYOLHLagSso9CzeW/paAS2q9I5SBm/2DtE1diLLg2jZikYcstsu/G5RgvbzbKqjiaMwTdXC3AMvDxQrs7U5pDRZFzoofG3cpODbTm+uy3m0kP70z0M1K45UbDG0p+itnTu9x40JbQEgefbx38AItNvAIx1A8HO4I1VX28= wayne@stream"
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
system.stateVersion = "26.05";
|
||||
|
||||
# Write auto-install script to /root
|
||||
environment.etc."auto-install.sh".text = ''
|
||||
#!/run/current-system/sw/bin/bash
|
||||
set -eux
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
export FLAKE_BASE_URL="git+https://gitea.lan.ddnsgeek.com/beatzaplenty/nixos.git"
|
||||
|
||||
echo "Fetching available NixOS hosts from flake..."
|
||||
mapfile -t options < <(
|
||||
nix eval --json --no-use-registries --no-accept-flake-config --extra-experimental-features "flakes nix-command" \
|
||||
"''${FLAKE_BASE_URL}#nixosConfigurations" \
|
||||
--apply builtins.attrNames \
|
||||
| jq -r '.[]'
|
||||
)
|
||||
|
||||
if [[ ''${#options[@]} -eq 0 ]]; then
|
||||
echo "ERROR: No NixOS hosts found in ''${FLAKE_BASE_URL}#nixosConfigurations" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Choose the flake profile to install:"
|
||||
select choice in "''${options[@]}"; do
|
||||
if [[ -n "$choice" ]]; then
|
||||
echo "You selected: $choice"
|
||||
break
|
||||
else
|
||||
echo "Invalid selection. Try again."
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Starting install with flake: ''${FLAKE_BASE_URL}#''${choice}"
|
||||
|
||||
# Optional: confirm before proceeding
|
||||
read -rp "Proceed with installation? (y/N): " confirm
|
||||
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
||||
echo "Aborted."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if nix eval --refresh --json --extra-experimental-features "flakes nix-command" "''${FLAKE_BASE_URL}#nixosConfigurations.''${choice}.config.disko.devices.disk.main.device" >/dev/null 2>&1; then
|
||||
disko --mode destroy,format,mount \
|
||||
--flake "''${FLAKE_BASE_URL}#''${choice}" --yes
|
||||
else
|
||||
# No raw disk to partition — true for every LXC container, which has
|
||||
# no block device visible from inside it, only its already-mounted
|
||||
# root filesystem. nixos-install defaults to installing into /mnt; if
|
||||
# nothing points /mnt at the real root, the new system gets built and
|
||||
# written to a disconnected empty directory, never actually becomes
|
||||
# bootable, and the container silently keeps running this installer
|
||||
# environment forever. Bind-mount / onto /mnt so the install actually
|
||||
# lands on the filesystem this container boots from.
|
||||
echo "Selected host has no Disko configuration — installing in place via bind mount."
|
||||
mount --bind / /mnt
|
||||
fi
|
||||
|
||||
# sops-nix derives this host's decryption key from its own SSH host key
|
||||
# at *activation* time, which runs before systemd would otherwise
|
||||
# generate one on first boot. Without pre-seeding it here, secrets
|
||||
# (including the login password) fail to decrypt on first boot.
|
||||
# Generate the key + register it with `nixos`'s sops-nix setup ahead of
|
||||
# time (see nix-auto-installer/scripts/prepare-host-key.sh), then scp it
|
||||
# to /root/host-keys/ on this machine before continuing.
|
||||
mkdir -p /root/host-keys
|
||||
if [[ -f "/root/host-keys/''${choice}_ssh_host_ed25519_key" ]]; then
|
||||
echo "Found pre-seeded SSH host key for ''${choice}, installing to target..."
|
||||
install -D -m 0600 "/root/host-keys/''${choice}_ssh_host_ed25519_key" /mnt/etc/ssh/ssh_host_ed25519_key
|
||||
install -D -m 0644 "/root/host-keys/''${choice}_ssh_host_ed25519_key.pub" /mnt/etc/ssh/ssh_host_ed25519_key.pub
|
||||
else
|
||||
echo "WARNING: no pre-seeded host key found at /root/host-keys/''${choice}_ssh_host_ed25519_key"
|
||||
echo "sops-nix secrets (including the login password) will NOT decrypt on first boot."
|
||||
echo "Run scripts/prepare-host-key.sh for host ''${choice} on your admin workstation first,"
|
||||
echo "then scp the result here, if this host needs sops-nix secrets."
|
||||
read -rp "Continue without a pre-seeded key anyway? (y/N): " skip_key
|
||||
if [[ ! "$skip_key" =~ ^[Yy]$ ]]; then
|
||||
echo "Aborted."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p /mnt/install-tmp
|
||||
export TMPDIR=/mnt/install-tmp
|
||||
|
||||
nixos-install \
|
||||
--flake "''${FLAKE_BASE_URL}#''${choice}" \
|
||||
--no-root-password
|
||||
|
||||
|
||||
rm -rf /mnt/install-tmp
|
||||
sleep 10
|
||||
reboot
|
||||
'';
|
||||
|
||||
environment.etc."auto-install.sh".mode = "0755";
|
||||
}
|
||||
Generated
+3
-40
@@ -127,21 +127,6 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixlib": {
|
||||
"locked": {
|
||||
"lastModified": 1736643958,
|
||||
"narHash": "sha256-tmpqTSWVRJVhpvfSN9KXBvKEXplrwKnSZNAoNPf/S/s=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "1418bc28a52126761c02dd3d89b2d8ca0f521181",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixos-conf-editor": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
@@ -162,27 +147,6 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixos-generators": {
|
||||
"inputs": {
|
||||
"nixlib": "nixlib",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1769813415,
|
||||
"narHash": "sha256-nnVmNNKBi1YiBNPhKclNYDORoHkuKipoz7EtVnXO50A=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixos-generators",
|
||||
"rev": "8946737ff703382fda7623b9fab071d037e897d5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nixos-generators",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1771008912,
|
||||
@@ -201,11 +165,11 @@
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1784011430,
|
||||
"narHash": "sha256-lDebytrYdd47IBLwvNOD+6AGeoqZ78CIKlp70hzW280=",
|
||||
"lastModified": 1784280462,
|
||||
"narHash": "sha256-DtoqIqM7VkR6NxAkcLpMwmi02USwWb3JdmNGLyhthc0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "8eeec934ae0dbeca3d7868c059568a65c08b2fc3",
|
||||
"rev": "293d6abedf0478e681a4dfcfcb35b30fc796a32f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -221,7 +185,6 @@
|
||||
"flake-utils": "flake-utils",
|
||||
"home-manager": "home-manager",
|
||||
"nixos-conf-editor": "nixos-conf-editor",
|
||||
"nixos-generators": "nixos-generators",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,68 +1,111 @@
|
||||
# flake.nix
|
||||
{
|
||||
description = "Auto-install NixOS ISO";
|
||||
|
||||
inputs = {
|
||||
# nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
|
||||
|
||||
nixos-conf-editor.url = "github:snowfallorg/nixos-conf-editor";
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
nixos-generators = {
|
||||
url = "github:nix-community/nixos-generators";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
# home-manager.url = "github:nix-community/home-manager";
|
||||
# home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
||||
|
||||
home-manager = {
|
||||
url = "github:nix-community/home-manager/release-26.05";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
disko = {
|
||||
url = "github:nix-community/disko";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, nixos-generators, home-manager, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
iso = nixos-generators.nixosGenerate {
|
||||
inherit system;
|
||||
format = "install-iso";
|
||||
modules = [
|
||||
./installer.nix
|
||||
outputs = { self, nixpkgs, flake-utils, home-manager, ... }:
|
||||
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
netbootSystem = nixpkgs.lib.nixosSystem {
|
||||
inherit system;
|
||||
|
||||
modules = [
|
||||
./installer.nix
|
||||
|
||||
({ modulesPath, ... }: {
|
||||
imports = [
|
||||
(modulesPath + "/installer/netboot/netboot-minimal.nix")
|
||||
];
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
in
|
||||
{
|
||||
|
||||
#
|
||||
# Complete NixOS systems
|
||||
#
|
||||
# These can be used with:
|
||||
#
|
||||
# nixos-rebuild switch --flake .#name
|
||||
#
|
||||
|
||||
nixosConfigurations = {
|
||||
|
||||
installer =
|
||||
nixpkgs.lib.nixosSystem {
|
||||
inherit system;
|
||||
|
||||
modules = [
|
||||
./installer.nix
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
proxmox-lxc =
|
||||
nixpkgs.lib.nixosSystem {
|
||||
inherit system;
|
||||
|
||||
modules = [
|
||||
./proxmox-lxc.nix
|
||||
];
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#
|
||||
# Buildable artifacts
|
||||
#
|
||||
# These are built with:
|
||||
#
|
||||
# nix build .#name
|
||||
#
|
||||
|
||||
packages.${system} = rec {
|
||||
|
||||
iso =
|
||||
self.nixosConfigurations.installer.config.system.build.isoImage;
|
||||
|
||||
lxc =
|
||||
self.nixosConfigurations.proxmox-lxc.config.system.build.tarball;
|
||||
|
||||
pxe =
|
||||
pkgs.linkFarm "pxe" [
|
||||
{ name = "netboot.ipxe"; path = netbootSystem.config.system.build.netbootIpxeScript; }
|
||||
{ name = "initrd"; path = netbootSystem.config.system.build.netbootRamdisk; }
|
||||
{ name = "kernel"; path = netbootSystem.config.system.build.kernel; }
|
||||
];
|
||||
};
|
||||
|
||||
netbootSystem = nixpkgs.lib.nixosSystem {
|
||||
inherit system;
|
||||
all =
|
||||
pkgs.linkFarm "all" [
|
||||
{ name = "iso"; path = iso; }
|
||||
{ name = "lxc"; path = lxc; }
|
||||
{ name = "pxe"; path = pxe; }
|
||||
];
|
||||
};
|
||||
|
||||
modules = [
|
||||
./installer.nix
|
||||
|
||||
({ modulesPath, ... }: {
|
||||
imports = [
|
||||
(modulesPath + "/installer/netboot/netboot-minimal.nix")
|
||||
];
|
||||
})
|
||||
];
|
||||
};
|
||||
in {
|
||||
packages.default = iso;
|
||||
|
||||
# packages.netboot = netbootSystem.config.system.build.netboot;
|
||||
|
||||
#packages.netboot-debug =
|
||||
# pkgs.writeText "attrs.json"
|
||||
# (builtins.toJSON
|
||||
# (builtins.attrNames netbootSystem.config.system.build));
|
||||
|
||||
packages.netboot-ipxe = netbootSystem.config.system.build.netbootIpxeScript;
|
||||
packages.netboot-initrd = netbootSystem.config.system.build.netbootRamdisk;
|
||||
packages.netboot-kernel = netbootSystem.config.system.build.kernel;
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
+11
-183
@@ -1,187 +1,15 @@
|
||||
{ lib, pkgs, modulesPath, config, ... }:
|
||||
{ modulesPath, ... }:
|
||||
|
||||
{
|
||||
# imports = [
|
||||
# "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
|
||||
# ];
|
||||
imports = [
|
||||
"${modulesPath}/installer/netboot/netboot-minimal.nix"
|
||||
];
|
||||
|
||||
networking.useDHCP = lib.mkDefault true;
|
||||
time.timeZone = "Australia/Brisbane";
|
||||
|
||||
services.openssh.enable = true;
|
||||
services.openssh.settings.PermitRootLogin = "yes";
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
git curl jq parted e2fsprogs btrfs-progs util-linux disko
|
||||
imports = [
|
||||
"${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
|
||||
./common.nix
|
||||
];
|
||||
|
||||
# environment.etc."flake-url".text = "git+https://gitea.lan.ddnsgeek.com/beatzaplenty/nixos.git?ref=main#nixos";
|
||||
|
||||
# Enable LISH
|
||||
boot.kernelParams = [ "console=ttyS0,19200n8" ];
|
||||
boot.loader.grub.extraConfig = ''
|
||||
serial --speed=19200 --unit=0 --word=8 --parity=no --stop=1;
|
||||
terminal_input serial;
|
||||
terminal_output serial;
|
||||
'';
|
||||
|
||||
environment.etc."git-credentials".text =
|
||||
"https://beatzaplenty:2b7e178eeee4af437fc721295d59e9e19366fd02@gitea.lan.ddnsgeek.com";
|
||||
#programs.git.enable = true;
|
||||
#programs.git.extraConfig."credential.helper" = "store --file=/etc/git-credentials";
|
||||
programs.git = {
|
||||
enable = true;
|
||||
package = pkgs.git;
|
||||
config = {
|
||||
credential.helper = "store --file=/etc/git-credentials";
|
||||
};
|
||||
};
|
||||
|
||||
# Write auto-install script to /root
|
||||
environment.etc."auto-install.sh".text = ''
|
||||
#!/run/current-system/sw/bin/bash
|
||||
set -eux
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
export FLAKE_BASE_URL="git+https://gitea.lan.ddnsgeek.com/beatzaplenty/nixos.git"
|
||||
|
||||
echo "Fetching available NixOS hosts from flake..."
|
||||
mapfile -t options < <(
|
||||
nix eval --json --no-use-registries --no-accept-flake-config --extra-experimental-features "flakes nix-command" \
|
||||
"''${FLAKE_BASE_URL}#nixosConfigurations" \
|
||||
--apply builtins.attrNames \
|
||||
| jq -r '.[]'
|
||||
)
|
||||
|
||||
if [[ ''${#options[@]} -eq 0 ]]; then
|
||||
echo "ERROR: No NixOS hosts found in ''${FLAKE_BASE_URL}#nixosConfigurations" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Choose the flake profile to install:"
|
||||
select choice in "''${options[@]}"; do
|
||||
if [[ -n "$choice" ]]; then
|
||||
echo "You selected: $choice"
|
||||
break
|
||||
else
|
||||
echo "Invalid selection. Try again."
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Starting install with flake: ''${FLAKE_BASE_URL}#''${choice}"
|
||||
|
||||
# Optional: confirm before proceeding
|
||||
read -rp "Proceed with installation? (y/N): " confirm
|
||||
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
||||
echo "Aborted."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# parted -s /dev/sda -- mklabel msdos
|
||||
# parted -s /dev/sda -- mkpart primary 1MB -8GB
|
||||
# parted -s /dev/sda -- set 1 boot on
|
||||
# parted -s /dev/sda -- mkpart primary linux-swap -8GB 100%
|
||||
# mkfs.ext4 -L nixos /dev/sda1
|
||||
# mkswap -L swap /dev/sda2
|
||||
# swapon /dev/sda2
|
||||
# sleep 10
|
||||
# mount /dev/disk/by-label/nixos /mnt
|
||||
# mkdir -p /mnt/install-tmp
|
||||
# export TMPDIR=/mnt/install-tmp
|
||||
# nixos-install --flake "''${FLAKE_BASE_URL}#''${choice}" --no-root-password --no-write-lock-file
|
||||
|
||||
if nix eval --refresh --json --extra-experimental-features "flakes nix-command" "''${FLAKE_BASE_URL}#nixosConfigurations.''${choice}.config.disko.devices.disk.main.device" >/dev/null 2>&1; then
|
||||
lsblk
|
||||
disko --mode destroy,format,mount \
|
||||
--flake "''${FLAKE_BASE_URL}#''${choice}"
|
||||
else
|
||||
echo "Selected host has no Disko configuration."
|
||||
mount /dev/sda /mnt
|
||||
fi
|
||||
|
||||
mkdir -p /mnt/install-tmp
|
||||
export TMPDIR=/mnt/install-tmp
|
||||
|
||||
nixos-install \
|
||||
--flake "''${FLAKE_BASE_URL}#''${choice}" \
|
||||
--no-root-password
|
||||
|
||||
|
||||
rm -rf /mnt/install-tmp
|
||||
sleep 10
|
||||
reboot
|
||||
'';
|
||||
# environment.etc."auto-install.sh".mode = "0755";
|
||||
|
||||
# Trigger the script from nixos user's shell
|
||||
# environment.etc."nixos/.bashrc".text = ''
|
||||
# # Run installer only once
|
||||
# if [ -n "$PS1" ] && [ ! -e ~/.auto_install_ran ]; then
|
||||
# sudo /etc/auto-install.sh
|
||||
# touch ~/.auto_install_ran
|
||||
# fi
|
||||
# '';
|
||||
# environment.etc."nixos/.bashrc".mode = "0755";
|
||||
#Set root password
|
||||
users.users.root = {
|
||||
hashedPassword = "$6$Kwv9KAyvcurAViQF$H4.u3feqGE7lVoNgkFXhE3n2Pmo//9JYDTCz8ifrVHBxPjwa1xMby7tEZ8Bpt5MXs9Rkx6/YbZWxs5CpH0s/70";
|
||||
};
|
||||
|
||||
# Define a user account. Don't forget to set a password with ‘passwd’.
|
||||
users.users.nixos = {
|
||||
isNormalUser = true;
|
||||
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
|
||||
packages = with pkgs; [
|
||||
tree
|
||||
];
|
||||
hashedPassword = "$6$Kwv9KAyvcurAViQF$H4.u3feqGE7lVoNgkFXhE3n2Pmo//9JYDTCz8ifrVHBxPjwa1xMby7tEZ8Bpt5MXs9Rkx6/YbZWxs5CpH0s/70";
|
||||
openssh.authorizedKeys.keys = [
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCq/Q5LvIXlZwO2kdeAN5nLGZ59nZB7JHYMEszHxmNtGMzv1lM31jiPNsr0z2EKVZhE7OOfa2IF9rhWYD7JUA9G0yzdZ4WTXFNGVVOJoOVH6vAF3XCxoVilOEwTc7h2Wiy+rzd0B28/3spffzQQWJhY6GRQVa8j+6xAGF60Fcvl1vLosYT9Bn2ZbK4TCWOwAn2jqXIieGpZdn/UNZbGOeKRiCvhktDfMAzuQzN/9jMu/oF4pkPn2X1UrsQdNlvp0Ci8md612MozIpncQJyAF1ADhunr3sMx0isUXiqD29R5DS4TftpekqLNLak+zcxFa8N7DcRNp3DcKfJvyTkwQrR4r+b7lFLYOLHLagSso9CzeW/paAS2q9I5SBm/2DtE1diLLg2jZikYcstsu/G5RgvbzbKqjiaMwTdXC3AMvDxQrs7U5pDRZFzoofG3cpODbTm+uy3m0kP70z0M1K45UbDG0p+itnTu9x40JbQEgefbx38AItNvAIx1A8HO4I1VX28= wayne@stream"
|
||||
];
|
||||
home = "/home/nixos";
|
||||
createHome = true;
|
||||
shell = pkgs.bashInteractive;
|
||||
|
||||
};
|
||||
# environment.etc."auto-install.sh".source = ./auto-install.sh;
|
||||
environment.etc."auto-install.sh".mode = "0755";
|
||||
|
||||
# environment.etc."home/nixos/.bashrc".text = ''
|
||||
# if [ -n "$PS1" ] && [ ! -e ~/.auto_install_ran ]; then
|
||||
# sudo /etc/auto-install.sh
|
||||
# touch ~/.auto_install_ran
|
||||
# fi
|
||||
# '';
|
||||
# environment.etc."home/nixos/.bashrc".mode = "0644";
|
||||
|
||||
# Write .bashrc into the user's home directory
|
||||
# environment.etc."bashrc-nixos".source = pkgs.writeText "bashrc-nixos" ''
|
||||
# if [ -n "$PS1" ] && [ ! -e ~/.auto_install_ran ]; then
|
||||
# sudo /etc/auto-install.sh
|
||||
# touch ~/.auto_install_ran
|
||||
# fi
|
||||
# '';
|
||||
|
||||
system.activationScripts.installBashProfile = {
|
||||
text = ''
|
||||
mkdir -p /home/nixos
|
||||
cp -f ${config.environment.etc."bash_profile-nixos".source} /home/nixos/.bash_profile
|
||||
chown nixos:nixos /home/nixos/.bash_profile
|
||||
chmod 644 /home/nixos/.bash_profile
|
||||
'';
|
||||
};
|
||||
|
||||
|
||||
environment.etc."bash_profile-nixos".source = pkgs.writeText "bash_profile-nixos" ''
|
||||
if [ -n "$PS1" ] && [ ! -e ~/.auto_install_ran ]; then
|
||||
sudo /etc/auto-install.sh
|
||||
touch ~/.auto_install_ran
|
||||
fi
|
||||
'';
|
||||
|
||||
}
|
||||
# Only for ISO/Linode serial environments if required
|
||||
# NOT for LXC
|
||||
#
|
||||
# boot.kernelParams = [
|
||||
# "console=ttyS0,19200n8"
|
||||
# ];
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
{ lib, pkgs, modulesPath, config, ... }:
|
||||
|
||||
{
|
||||
# imports = [
|
||||
# "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
|
||||
# ];
|
||||
imports = [
|
||||
"${modulesPath}/installer/netboot/netboot-minimal.nix"
|
||||
];
|
||||
|
||||
networking.useDHCP = lib.mkDefault true;
|
||||
time.timeZone = "Australia/Brisbane";
|
||||
|
||||
services.openssh.enable = true;
|
||||
services.openssh.settings.PermitRootLogin = "yes";
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
git curl jq parted e2fsprogs btrfs-progs util-linux disko
|
||||
];
|
||||
|
||||
# environment.etc."flake-url".text = "git+https://gitea.lan.ddnsgeek.com/beatzaplenty/nixos.git?ref=main#nixos";
|
||||
|
||||
# Enable LISH
|
||||
boot.kernelParams = [ "console=ttyS0,19200n8" ];
|
||||
boot.loader.grub.extraConfig = ''
|
||||
serial --speed=19200 --unit=0 --word=8 --parity=no --stop=1;
|
||||
terminal_input serial;
|
||||
terminal_output serial;
|
||||
'';
|
||||
|
||||
environment.etc."git-credentials".text =
|
||||
"https://beatzaplenty:2b7e178eeee4af437fc721295d59e9e19366fd02@gitea.lan.ddnsgeek.com";
|
||||
#programs.git.enable = true;
|
||||
#programs.git.extraConfig."credential.helper" = "store --file=/etc/git-credentials";
|
||||
programs.git = {
|
||||
enable = true;
|
||||
package = pkgs.git;
|
||||
config = {
|
||||
credential.helper = "store --file=/etc/git-credentials";
|
||||
};
|
||||
};
|
||||
|
||||
# Write auto-install script to /root
|
||||
environment.etc."auto-install.sh".text = ''
|
||||
#!/run/current-system/sw/bin/bash
|
||||
set -eux
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
export FLAKE_BASE_URL="git+https://gitea.lan.ddnsgeek.com/beatzaplenty/nixos.git"
|
||||
|
||||
echo "Fetching available NixOS hosts from flake..."
|
||||
mapfile -t options < <(
|
||||
nix eval --json --no-use-registries --no-accept-flake-config --extra-experimental-features "flakes nix-command" \
|
||||
"''${FLAKE_BASE_URL}#nixosConfigurations" \
|
||||
--apply builtins.attrNames \
|
||||
| jq -r '.[]'
|
||||
)
|
||||
|
||||
if [[ ''${#options[@]} -eq 0 ]]; then
|
||||
echo "ERROR: No NixOS hosts found in ''${FLAKE_BASE_URL}#nixosConfigurations" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Choose the flake profile to install:"
|
||||
select choice in "''${options[@]}"; do
|
||||
if [[ -n "$choice" ]]; then
|
||||
echo "You selected: $choice"
|
||||
break
|
||||
else
|
||||
echo "Invalid selection. Try again."
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Starting install with flake: ''${FLAKE_BASE_URL}#''${choice}"
|
||||
|
||||
# Optional: confirm before proceeding
|
||||
read -rp "Proceed with installation? (y/N): " confirm
|
||||
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
||||
echo "Aborted."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if nix eval --refresh --json --extra-experimental-features "flakes nix-command" "''${FLAKE_BASE_URL}#nixosConfigurations.''${choice}.config.disko.devices.disk.main.device" >/dev/null 2>&1; then
|
||||
disko --mode destroy,format,mount \
|
||||
--flake "''${FLAKE_BASE_URL}#''${choice}" --yes`
|
||||
else
|
||||
echo "Selected host has no Disko configuration."
|
||||
fi
|
||||
|
||||
mkdir -p /mnt/install-tmp
|
||||
export TMPDIR=/mnt/install-tmp
|
||||
|
||||
nixos-install \
|
||||
--flake "''${FLAKE_BASE_URL}#''${choice}" \
|
||||
--no-root-password
|
||||
|
||||
|
||||
rm -rf /mnt/install-tmp
|
||||
sleep 10
|
||||
reboot
|
||||
'';
|
||||
# environment.etc."auto-install.sh".mode = "0755";
|
||||
|
||||
# Trigger the script from nixos user's shell
|
||||
# environment.etc."nixos/.bashrc".text = ''
|
||||
# # Run installer only once
|
||||
# if [ -n "$PS1" ] && [ ! -e ~/.auto_install_ran ]; then
|
||||
# sudo /etc/auto-install.sh
|
||||
# touch ~/.auto_install_ran
|
||||
# fi
|
||||
# '';
|
||||
# environment.etc."nixos/.bashrc".mode = "0755";
|
||||
#Set root password
|
||||
users.users.root = {
|
||||
hashedPassword = "$6$Kwv9KAyvcurAViQF$H4.u3feqGE7lVoNgkFXhE3n2Pmo//9JYDTCz8ifrVHBxPjwa1xMby7tEZ8Bpt5MXs9Rkx6/YbZWxs5CpH0s/70";
|
||||
};
|
||||
|
||||
# Define a user account. Don't forget to set a password with ‘passwd’.
|
||||
users.users.nixos = {
|
||||
isNormalUser = true;
|
||||
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
|
||||
packages = with pkgs; [
|
||||
tree
|
||||
];
|
||||
hashedPassword = "$6$Kwv9KAyvcurAViQF$H4.u3feqGE7lVoNgkFXhE3n2Pmo//9JYDTCz8ifrVHBxPjwa1xMby7tEZ8Bpt5MXs9Rkx6/YbZWxs5CpH0s/70";
|
||||
openssh.authorizedKeys.keys = [
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCq/Q5LvIXlZwO2kdeAN5nLGZ59nZB7JHYMEszHxmNtGMzv1lM31jiPNsr0z2EKVZhE7OOfa2IF9rhWYD7JUA9G0yzdZ4WTXFNGVVOJoOVH6vAF3XCxoVilOEwTc7h2Wiy+rzd0B28/3spffzQQWJhY6GRQVa8j+6xAGF60Fcvl1vLosYT9Bn2ZbK4TCWOwAn2jqXIieGpZdn/UNZbGOeKRiCvhktDfMAzuQzN/9jMu/oF4pkPn2X1UrsQdNlvp0Ci8md612MozIpncQJyAF1ADhunr3sMx0isUXiqD29R5DS4TftpekqLNLak+zcxFa8N7DcRNp3DcKfJvyTkwQrR4r+b7lFLYOLHLagSso9CzeW/paAS2q9I5SBm/2DtE1diLLg2jZikYcstsu/G5RgvbzbKqjiaMwTdXC3AMvDxQrs7U5pDRZFzoofG3cpODbTm+uy3m0kP70z0M1K45UbDG0p+itnTu9x40JbQEgefbx38AItNvAIx1A8HO4I1VX28= wayne@stream"
|
||||
];
|
||||
home = "/home/nixos";
|
||||
createHome = true;
|
||||
shell = pkgs.bashInteractive;
|
||||
|
||||
};
|
||||
# environment.etc."auto-install.sh".source = ./auto-install.sh;
|
||||
environment.etc."auto-install.sh".mode = "0755";
|
||||
|
||||
# environment.etc."home/nixos/.bashrc".text = ''
|
||||
# if [ -n "$PS1" ] && [ ! -e ~/.auto_install_ran ]; then
|
||||
# sudo /etc/auto-install.sh
|
||||
# touch ~/.auto_install_ran
|
||||
# fi
|
||||
# '';
|
||||
# environment.etc."home/nixos/.bashrc".mode = "0644";
|
||||
|
||||
# Write .bashrc into the user's home directory
|
||||
# environment.etc."bashrc-nixos".source = pkgs.writeText "bashrc-nixos" ''
|
||||
# if [ -n "$PS1" ] && [ ! -e ~/.auto_install_ran ]; then
|
||||
# sudo /etc/auto-install.sh
|
||||
# touch ~/.auto_install_ran
|
||||
# fi
|
||||
# '';
|
||||
|
||||
system.activationScripts.installBashProfile = {
|
||||
text = ''
|
||||
mkdir -p /home/nixos
|
||||
cp -f ${config.environment.etc."bash_profile-nixos".source} /home/nixos/.bash_profile
|
||||
chown nixos:nixos /home/nixos/.bash_profile
|
||||
chmod 644 /home/nixos/.bash_profile
|
||||
'';
|
||||
};
|
||||
|
||||
|
||||
environment.etc."bash_profile-nixos".source = pkgs.writeText "bash_profile-nixos" ''
|
||||
if [ -n "$PS1" ] && [ ! -e ~/.auto_install_ran ]; then
|
||||
sudo /etc/auto-install.sh
|
||||
touch ~/.auto_install_ran
|
||||
fi
|
||||
'';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{ modulesPath, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
./common.nix
|
||||
(modulesPath + "/virtualisation/proxmox-lxc.nix")
|
||||
];
|
||||
|
||||
|
||||
# LXC has no bootloader
|
||||
boot.loader.grub.enable = false;
|
||||
boot.loader.systemd-boot.enable = false;
|
||||
|
||||
|
||||
# Ensure Proxmox console works
|
||||
# services.getty.enable = true;
|
||||
|
||||
|
||||
# environment.etc."auto-install.sh" = {
|
||||
# source = ./auto-install.sh;
|
||||
# mode = "0755";
|
||||
# };
|
||||
|
||||
# networking.useDHCP = true;
|
||||
}
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generates a new machine's SSH host key ahead of installing it, so
|
||||
# sops-nix (in the `nixos` flake) has something to derive an age key
|
||||
# from before the target ever boots.
|
||||
#
|
||||
# Why this is needed: sops-nix derives each host's decryption key from
|
||||
# its own /etc/ssh/ssh_host_ed25519_key at *activation* time, but that
|
||||
# activation runs before systemd would otherwise generate this key on
|
||||
# first boot (sshd-keygen is a normal systemd service gated behind
|
||||
# multi-user.target; activation scripts run earlier than that). Without
|
||||
# pre-seeding, secrets — including the root/nixos login password — fail
|
||||
# to decrypt on the machine's very first boot.
|
||||
#
|
||||
# This script only touches your admin workstation and the `nixos` repo's
|
||||
# .sops.yaml (it never contacts the target machine). Run it, follow the
|
||||
# printed next steps, then use the resulting key with the auto-install.sh
|
||||
# prompt (see common.nix) when you actually install the new machine.
|
||||
set -euo pipefail
|
||||
|
||||
hostname="${1:?usage: scripts/prepare-host-key.sh <hostname> [path-to-nixos-repo]}"
|
||||
nixos_repo="${2:-../nixos}"
|
||||
sops_yaml="${nixos_repo}/.sops.yaml"
|
||||
|
||||
if [[ ! -f "$sops_yaml" ]]; then
|
||||
echo "ERROR: $sops_yaml not found. Pass the nixos repo path as the 2nd argument." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
keydir="$(cd "$(dirname "$0")/.." && pwd)/host-keys"
|
||||
mkdir -p "$keydir"
|
||||
keyfile="${keydir}/${hostname}_ssh_host_ed25519_key"
|
||||
|
||||
if [[ -f "$keyfile" ]]; then
|
||||
echo "ERROR: $keyfile already exists. Remove it first if you want to regenerate." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
nix-shell -p openssh --run "ssh-keygen -t ed25519 -N '' -C '${hostname}' -f '${keyfile}'" >/dev/null
|
||||
|
||||
age_pub="$(nix-shell -p ssh-to-age --run "ssh-to-age -i '${keyfile}.pub'")"
|
||||
|
||||
cat <<EOF
|
||||
|
||||
Generated: ${keyfile}(.pub)
|
||||
|
||||
=== 1. Add this line under keys: in ${sops_yaml} ===
|
||||
- &${hostname} ${age_pub}
|
||||
|
||||
=== 2. Add *${hostname} to whichever creation_rules key_groups this host needs ===
|
||||
(e.g. secrets/common.yaml always; add a per-host secrets/${hostname}.yaml
|
||||
block too if this host will get its own secrets, same pattern as
|
||||
nix-cache/server.)
|
||||
|
||||
=== 3. Re-encrypt every secrets file you just added it to ===
|
||||
nix-shell -p sops --run 'sops updatekeys ${nixos_repo}/secrets/common.yaml'
|
||||
|
||||
=== 4. Commit + push the nixos repo so the flake build picks up the new recipient ===
|
||||
|
||||
=== 5. When you boot the installer on the new machine, scp the key in ===
|
||||
scp ${keyfile}{,.pub} root@<target-ip>:/root/host-keys/
|
||||
|
||||
Then continue with /etc/auto-install.sh as normal — it will find the
|
||||
pre-seeded key and install it before running nixos-install.
|
||||
EOF
|
||||
Reference in new issue
Block a user