This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

installer: add cross-compilation support and serial console

+224 -3
+76
flake.nix
··· 168 168 }; 169 169 }; 170 170 clan-cli = clan-core.packages.${system}.clan-cli; 171 + 172 + # Script to build installer ISO with custom vars 173 + build-installer-iso = pkgs.writeShellScriptBin "build-installer-iso" '' 174 + set -euo pipefail 175 + set -x 176 + 177 + # Default values 178 + OUTPUT="installer.iso" 179 + ARCH="x86_64-linux" # Default to x86_64-linux for cross-compilation 180 + VARS_DIR="" 181 + 182 + usage() { 183 + cat <<EOF 184 + Usage: $0 [OPTIONS] 185 + 186 + Build a NixOS installer ISO with custom vars appended. 187 + 188 + OPTIONS: 189 + -o, --output FILE Output ISO file (default: installer.iso) 190 + -a, --arch ARCH Architecture: x86_64-linux or aarch64-linux (default: x86_64-linux) 191 + -v, --vars DIR Directory containing vars to append to ISO 192 + -h, --help Show this help message 193 + 194 + EXAMPLE: 195 + $0 -o my-installer.iso -v ./my-vars -a x86_64-linux 196 + EOF 197 + } 198 + 199 + # Parse arguments 200 + while [[ $# -gt 0 ]]; do 201 + case $1 in 202 + -o|--output) 203 + OUTPUT="$2" 204 + shift 2 205 + ;; 206 + -a|--arch) 207 + ARCH="$2" 208 + shift 2 209 + ;; 210 + -v|--vars) 211 + VARS_DIR="$2" 212 + shift 2 213 + ;; 214 + -h|--help) 215 + usage 216 + exit 0 217 + ;; 218 + *) 219 + echo "Unknown option: $1" 220 + usage 221 + exit 1 222 + ;; 223 + esac 224 + done 225 + 226 + # Build the base ISO 227 + echo "Building base ISO for $ARCH..." 228 + BASE_ISO=$(nix build -L --no-link --print-out-paths ${self}#clanInternals.machines.$ARCH.installer.config.system.build.images.iso-installer) 229 + 230 + if [ -z "$VARS_DIR" ]; then 231 + # No vars specified, just copy the base ISO 232 + echo "No vars directory specified, copying base ISO..." 233 + cp "$BASE_ISO"/iso/*.iso "$OUTPUT" 234 + else 235 + # Append vars using xorriso - preserve boot structure 236 + echo "Appending vars from $VARS_DIR to ISO..." 237 + ${pkgs.xorriso}/bin/xorriso \ 238 + -indev "$BASE_ISO"/iso/*.iso \ 239 + -outdev "$OUTPUT" \ 240 + -boot_image any replay \ 241 + -map "$VARS_DIR" /vars \ 242 + -commit_eject all 243 + fi 244 + 245 + echo "ISO created: $OUTPUT" 246 + ''; 171 247 }; 172 248 devShells.default = pkgs.mkShell { 173 249 packages = [
+69
2configs/installer-tor.nix
··· 1 + { 2 + lib, 3 + pkgs, 4 + modulesPath, 5 + ... 6 + }: 7 + 8 + { 9 + imports = [ 10 + # Import the images.nix module to enable image building 11 + (modulesPath + "/image/images.nix") 12 + 13 + # Include your Tor SSH configuration 14 + ./tor-ssh.nix 15 + ]; 16 + 17 + # Enable SSH in the installer 18 + services.openssh = { 19 + enable = true; 20 + settings = { 21 + PermitRootLogin = "yes"; 22 + PasswordAuthentication = true; 23 + }; 24 + }; 25 + 26 + # Set a default root password for the installer 27 + users.users.root.initialPassword = "nixos"; 28 + 29 + # Ensure Tor starts automatically 30 + systemd.services.tor = { 31 + wantedBy = [ "multi-user.target" ]; 32 + after = [ "network-online.target" ]; 33 + }; 34 + 35 + # Add a script to display the Tor hostname 36 + environment.systemPackages = with pkgs; [ 37 + (writeScriptBin "show-tor-address" '' 38 + #!${pkgs.bash}/bin/bash 39 + echo "Waiting for Tor hidden service to be created..." 40 + while [ ! -f /var/lib/tor/onion/ssh/hostname ]; do 41 + sleep 1 42 + done 43 + echo "" 44 + echo "===============================================" 45 + echo "SSH is available via Tor at:" 46 + echo "" 47 + cat /var/lib/tor/onion/ssh/hostname 48 + echo "" 49 + echo "To connect from another machine:" 50 + echo "torify ssh root@$(cat /var/lib/tor/onion/ssh/hostname)" 51 + echo "===============================================" 52 + echo "" 53 + '') 54 + ]; 55 + 56 + # Add message to installer greeting 57 + services.getty.helpLine = lib.mkAfter '' 58 + 59 + >>> To see the Tor hidden service address for SSH, run: show-tor-address 60 + >>> Default root password is: nixos 61 + ''; 62 + 63 + # Automatically show Tor address on login 64 + programs.bash.loginShellInit = '' 65 + if [ -f /var/lib/tor/onion/ssh/hostname ]; then 66 + show-tor-address 67 + fi 68 + ''; 69 + }
+72 -3
machines/installer/config.nix
··· 1 - { config, lib, pkgs, ... }: 1 + { modulesPath, pkgs, ... }: 2 2 3 3 { 4 4 imports = [ 5 - ../../2configs/installer-tor.nix 5 + # ../../2configs/installer-tor.nix 6 + (modulesPath + "/image/images.nix") 7 + 6 8 ]; 7 9 8 10 # Basic installer configuration 9 11 networking.hostName = "installer"; 10 - } 12 + 13 + # Enable emergency access in initrd for debugging 14 + boot.initrd.systemd.emergencyAccess = true; 15 + 16 + # Enable serial console for VM usage 17 + boot.kernelParams = [ "console=ttyS0,115200n8" "console=tty0" ]; 18 + 19 + # Configure systemd for serial console 20 + systemd.services."serial-getty@ttyS0" = { 21 + enable = true; 22 + wantedBy = [ "getty.target" ]; 23 + serviceConfig.Restart = "always"; 24 + }; 25 + 26 + # Auto-mount ISO and extract vars 27 + systemd.services.extract-vars = { 28 + description = "Extract vars from ISO"; 29 + wantedBy = [ "multi-user.target" ]; 30 + after = [ "local-fs.target" ]; 31 + path = with pkgs; [ util-linux coreutils ]; 32 + serviceConfig = { 33 + Type = "oneshot"; 34 + RemainAfterExit = true; 35 + }; 36 + script = '' 37 + set -euxo pipefail 38 + 39 + # Find the ISO device (usually sr0, but could be others) 40 + ISO_DEVICE="" 41 + for dev in /dev/sr*; do 42 + if [ -b "$dev" ]; then 43 + ISO_DEVICE="$dev" 44 + break 45 + fi 46 + done 47 + 48 + if [ -z "$ISO_DEVICE" ]; then 49 + echo "No ISO device found, checking loop devices..." 50 + for dev in /dev/loop*; do 51 + if [ -b "$dev" ] && lsblk -no FSTYPE "$dev" 2>/dev/null | grep -q iso9660; then 52 + ISO_DEVICE="$dev" 53 + break 54 + fi 55 + done 56 + fi 57 + 58 + if [ -n "$ISO_DEVICE" ]; then 59 + echo "Found ISO device: $ISO_DEVICE" 60 + mkdir -p /mnt/iso 61 + if mount -t iso9660 -o ro "$ISO_DEVICE" /mnt/iso; then 62 + echo "Successfully mounted ISO" 63 + if [ -d /mnt/iso/vars ]; then 64 + echo "Extracting vars to /vars" 65 + cp -r /mnt/iso/vars /vars 66 + chmod -R u+w /vars 67 + echo "Vars extracted successfully" 68 + else 69 + echo "No vars directory found in ISO" 70 + fi 71 + else 72 + echo "Failed to mount ISO device $ISO_DEVICE" 73 + fi 74 + else 75 + echo "No ISO device found" 76 + fi 77 + ''; 78 + }; 79 + }
+7
machines/installer/physical.nix
··· 1 + { ... }: 2 + 3 + { 4 + imports = [ 5 + ./config.nix 6 + ]; 7 + }