Commit d8140c2733b2
2026-01-23 11:05:29
1 parent
10ab59a
Changed files (6)
imperative
fedora-csb
lib
systems
fedora-csb
imperative/fedora-csb/bootstrap.sh
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+# Fedora CSB Bootstrap Script
+# Description: Installs Nix and sets up system-manager on Fedora CSB
+
+set -euo pipefail
+
+# Color output for better readability
+readonly RED='\033[0;31m'
+readonly GREEN='\033[0;32m'
+readonly YELLOW='\033[1;33m'
+readonly NC='\033[0m' # No Color
+
+# Configuration
+REPO_URL="${REPO_URL:-https://github.com/vdemeester/home.git}"
+REPO_PATH="${REPO_PATH:-$HOME/src/home}"
+SYSTEM_CONFIG="${SYSTEM_CONFIG:-fedora-csb}"
+
+# Logging functions
+log_info() {
+ echo -e "${GREEN}[INFO]${NC} $*"
+}
+
+log_warn() {
+ echo -e "${YELLOW}[WARN]${NC} $*"
+}
+
+log_error() {
+ echo -e "${RED}[ERROR]${NC} $*" >&2
+}
+
+check_root() {
+ if [[ $EUID -eq 0 ]]; then
+ log_error "This script should NOT be run as root"
+ log_error "Run as your regular user - it will use sudo when needed"
+ exit 1
+ fi
+}
+
+install_dependencies() {
+ log_info "Installing dependencies..."
+ sudo dnf install -y git curl xz
+}
+
+install_nix() {
+ if command -v nix &>/dev/null; then
+ log_info "Nix is already installed"
+ return 0
+ fi
+
+ log_info "Installing Nix..."
+
+ # Use the Determinate Systems installer for better multi-user experience
+ # It handles SELinux and systemd integration well on Fedora
+ curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
+
+ log_info "Nix installed successfully"
+ log_warn "You may need to restart your shell or run: . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
+}
+
+setup_nix_config() {
+ log_info "Configuring Nix..."
+
+ # Ensure Nix is in PATH for this session
+ if [[ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]]; then
+ # shellcheck disable=SC1091
+ . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
+ fi
+
+ # Create XDG config directory for Nix
+ mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/nix"
+
+ # Enable flakes and nix-command
+ cat >"${XDG_CONFIG_HOME:-$HOME/.config}/nix/nix.conf" <<EOF
+experimental-features = nix-command flakes
+use-xdg-base-directories = true
+EOF
+
+ log_info "Nix configured with flakes enabled"
+}
+
+clone_repo() {
+ if [[ -d "$REPO_PATH" ]]; then
+ log_info "Repository already exists at $REPO_PATH"
+ log_info "Pulling latest changes..."
+ git -C "$REPO_PATH" pull --ff-only || log_warn "Could not pull, continuing with existing repo"
+ return 0
+ fi
+
+ log_info "Cloning repository to $REPO_PATH..."
+ mkdir -p "$(dirname "$REPO_PATH")"
+ git clone "$REPO_URL" "$REPO_PATH"
+ log_info "Repository cloned successfully"
+}
+
+build_system_manager() {
+ log_info "Building system-manager configuration..."
+
+ cd "$REPO_PATH"
+
+ # Ensure Nix is available
+ if ! command -v nix &>/dev/null; then
+ if [[ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]]; then
+ # shellcheck disable=SC1091
+ . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
+ else
+ log_error "Nix not found in PATH. Please restart your shell and run this script again."
+ exit 1
+ fi
+ fi
+
+ log_info "Building system configuration: $SYSTEM_CONFIG"
+ nix build ".#systemConfigs.${SYSTEM_CONFIG}" --no-link --print-out-paths
+}
+
+activate_system_manager() {
+ log_info "Activating system-manager..."
+
+ cd "$REPO_PATH"
+
+ # Get the built system path
+ local system_path
+ system_path=$(nix build ".#systemConfigs.${SYSTEM_CONFIG}" --no-link --print-out-paths)
+
+ log_info "Activating configuration from: $system_path"
+
+ # Activate the system configuration
+ sudo "${system_path}/bin/activate"
+
+ log_info "System-manager activated successfully!"
+}
+
+print_next_steps() {
+ log_info ""
+ log_info "Bootstrap complete!"
+ log_info ""
+ log_info "Next steps:"
+ log_info " 1. Restart your shell or run: exec \$SHELL"
+ log_info " 2. Navigate to repo: cd $REPO_PATH"
+ log_info " 3. To rebuild and activate: nix build .#systemConfigs.${SYSTEM_CONFIG} && sudo ./result/bin/activate"
+ log_info ""
+ log_info "Useful commands:"
+ log_info " - Build only: nix build .#systemConfigs.${SYSTEM_CONFIG}"
+ log_info " - Show flake outputs: nix flake show"
+ log_info ""
+}
+
+main() {
+ log_info "Starting Fedora CSB bootstrap..."
+ log_info "Configuration: $SYSTEM_CONFIG"
+ log_info "Repository: $REPO_URL -> $REPO_PATH"
+ log_info ""
+
+ check_root
+ install_dependencies
+ install_nix
+ setup_nix_config
+ clone_repo
+ build_system_manager
+ activate_system_manager
+ print_next_steps
+}
+
+main "$@"
imperative/fedora-csb/create-vm.sh
@@ -0,0 +1,154 @@
+#!/usr/bin/env bash
+
+# Fedora CSB VM Creation Script
+# Description: Creates a libvirt VM from a Fedora CSB ISO
+
+set -euo pipefail
+
+# Color output for better readability
+readonly RED='\033[0;31m'
+readonly GREEN='\033[0;32m'
+readonly YELLOW='\033[1;33m'
+readonly NC='\033[0m' # No Color
+
+# Default configuration
+VM_NAME="${VM_NAME:-fedora-csb}"
+VM_RAM="${VM_RAM:-4096}" # RAM in MB
+VM_CPUS="${VM_CPUS:-2}"
+VM_DISK_SIZE="${VM_DISK_SIZE:-40}" # Disk size in GB
+VM_DISK_PATH="${VM_DISK_PATH:-/var/lib/libvirt/images/${VM_NAME}.qcow2}"
+VM_NETWORK="${VM_NETWORK:-default}"
+
+# Logging functions
+log_info() {
+ echo -e "${GREEN}[INFO]${NC} $*"
+}
+
+log_warn() {
+ echo -e "${YELLOW}[WARN]${NC} $*"
+}
+
+log_error() {
+ echo -e "${RED}[ERROR]${NC} $*" >&2
+}
+
+usage() {
+ cat <<EOF
+Usage: $(basename "$0") <iso-path>
+
+Creates a libvirt VM from a Fedora CSB ISO.
+
+Arguments:
+ iso-path Path to the Fedora CSB ISO file
+
+Environment variables (optional):
+ VM_NAME VM name (default: fedora-csb)
+ VM_RAM RAM in MB (default: 4096)
+ VM_CPUS Number of CPUs (default: 2)
+ VM_DISK_SIZE Disk size in GB (default: 40)
+ VM_DISK_PATH Path to VM disk image (default: /var/lib/libvirt/images/\$VM_NAME.qcow2)
+ VM_NETWORK Libvirt network (default: default)
+
+Example:
+ $(basename "$0") ~/Downloads/fedora-csb.iso
+ VM_RAM=8192 VM_CPUS=4 $(basename "$0") ~/Downloads/fedora-csb.iso
+EOF
+ exit 1
+}
+
+check_dependencies() {
+ local deps=("virt-install" "virsh" "qemu-img")
+ local missing=()
+
+ for dep in "${deps[@]}"; do
+ if ! command -v "$dep" &>/dev/null; then
+ missing+=("$dep")
+ fi
+ done
+
+ if [[ ${#missing[@]} -gt 0 ]]; then
+ log_error "Missing dependencies: ${missing[*]}"
+ log_error "Install with: sudo dnf install libvirt virt-install qemu-kvm"
+ exit 1
+ fi
+}
+
+check_libvirt_running() {
+ if ! systemctl is-active --quiet libvirtd; then
+ log_error "libvirtd is not running"
+ log_error "Start with: sudo systemctl start libvirtd"
+ exit 1
+ fi
+}
+
+check_vm_exists() {
+ if virsh dominfo "$VM_NAME" &>/dev/null; then
+ log_warn "VM '$VM_NAME' already exists"
+ read -rp "Delete and recreate? [y/N] " response
+ if [[ "$response" =~ ^[Yy]$ ]]; then
+ log_info "Destroying existing VM..."
+ virsh destroy "$VM_NAME" 2>/dev/null || true
+ virsh undefine "$VM_NAME" --remove-all-storage 2>/dev/null || true
+ else
+ log_error "Aborting. Use VM_NAME=other-name to create with different name."
+ exit 1
+ fi
+ fi
+}
+
+create_vm() {
+ local iso_path="$1"
+
+ log_info "Creating VM '$VM_NAME'..."
+ log_info " RAM: ${VM_RAM}MB"
+ log_info " CPUs: ${VM_CPUS}"
+ log_info " Disk: ${VM_DISK_SIZE}GB at ${VM_DISK_PATH}"
+ log_info " Network: ${VM_NETWORK}"
+ log_info " ISO: ${iso_path}"
+
+ virt-install \
+ --name "$VM_NAME" \
+ --memory "$VM_RAM" \
+ --vcpus "$VM_CPUS" \
+ --disk "path=${VM_DISK_PATH},size=${VM_DISK_SIZE},format=qcow2" \
+ --cdrom "$iso_path" \
+ --os-variant "fedora-unknown" \
+ --network "network=${VM_NETWORK}" \
+ --graphics spice \
+ --video virtio \
+ --boot uefi \
+ --noautoconsole
+
+ log_info "VM created successfully!"
+ log_info ""
+ log_info "Next steps:"
+ log_info " 1. Connect to VM: virt-manager (or: virsh console $VM_NAME)"
+ log_info " 2. Wait for CSB installation to complete"
+ log_info " 3. After reboot, run bootstrap.sh inside the VM"
+ log_info ""
+ log_info "To get VM IP after install:"
+ log_info " virsh domifaddr $VM_NAME"
+}
+
+main() {
+ if [[ $# -lt 1 ]]; then
+ usage
+ fi
+
+ local iso_path="$1"
+
+ # Validate ISO path
+ if [[ ! -f "$iso_path" ]]; then
+ log_error "ISO file not found: $iso_path"
+ exit 1
+ fi
+
+ log_info "Checking dependencies..."
+ check_dependencies
+ check_libvirt_running
+ check_vm_exists
+
+ create_vm "$iso_path"
+}
+
+main "$@"
imperative/fedora-csb/README.org
@@ -0,0 +1,144 @@
+#+TITLE: Fedora CSB - System Manager Testing
+#+FILETAGS: fedora csb system-manager vm
+
+Testing system-manager on Red Hat Fedora CSB (Corporate Standard Build).
+
+* Overview
+
+This configuration is for testing system-manager on Fedora CSB, Red Hat's managed Fedora distribution.
+
+** System Information
+
+- *OS:* Fedora CSB (Red Hat managed)
+- *Type:* Virtual Machine (test environment)
+- *Architecture:* x86_64
+- *Purpose:* Testing system-manager on non-NixOS
+
+** Components
+
+Managed by system-manager:
+- Core utilities (vim, htop, curl, git, ripgrep, fd, jq)
+- Development tools (helix)
+- Networking tools (wireguard-tools)
+
+* Scripts
+
+** create-vm.sh
+
+Creates a libvirt VM from a Fedora CSB ISO.
+
+#+begin_src bash
+# Basic usage
+./create-vm.sh ~/Downloads/fedora-csb.iso
+
+# With custom settings
+VM_NAME=fedora-csb VM_RAM=8192 VM_CPUS=4 ./create-vm.sh ~/Downloads/fedora-csb.iso
+#+end_src
+
+Environment variables:
+| Variable | Default | Description |
+|---------------+----------------------------------------------+----------------------|
+| VM_NAME | fedora-csb | VM name |
+| VM_RAM | 4096 | RAM in MB |
+| VM_CPUS | 2 | Number of CPUs |
+| VM_DISK_SIZE | 40 | Disk size in GB |
+| VM_DISK_PATH | /var/lib/libvirt/images/$VM_NAME.qcow2 | Path to disk image |
+| VM_NETWORK | default | Libvirt network |
+
+** bootstrap.sh
+
+Run inside the VM after installation to set up Nix and system-manager.
+
+#+begin_src bash
+# Copy to VM and run
+scp bootstrap.sh user@fedora-csb:~
+ssh user@fedora-csb './bootstrap.sh'
+
+# Or with custom repo/config
+REPO_URL=git@github.com:user/home.git SYSTEM_CONFIG=fedora-csb ./bootstrap.sh
+#+end_src
+
+Environment variables:
+| Variable | Default | Description |
+|---------------+--------------------------------------+--------------------------------|
+| REPO_URL | https://github.com/vdemeester/home | Git repository URL |
+| REPO_PATH | $HOME/src/home | Local path for repo |
+| SYSTEM_CONFIG | fedora-csb | System-manager config name |
+
+* Workflow
+
+1. *Download ISO*: Get Fedora CSB ISO from Red Hat
+
+2. *Create VM*:
+ #+begin_src bash
+ ./imperative/fedora-csb/create-vm.sh /path/to/fedora-csb.iso
+ #+end_src
+
+3. *Wait for installation*: CSB installer is automated, wait for it to complete
+
+4. *Get VM IP*:
+ #+begin_src bash
+ virsh domifaddr fedora-csb
+ #+end_src
+
+5. *Bootstrap system-manager*:
+ #+begin_src bash
+ scp imperative/fedora-csb/bootstrap.sh user@<vm-ip>:~
+ ssh user@<vm-ip> './bootstrap.sh'
+ #+end_src
+
+6. *Iterate*: Modify =systems/fedora-csb/system.nix= and rebuild:
+ #+begin_src bash
+ ssh user@<vm-ip> 'cd ~/src/home && git pull && nix build .#systemConfigs.fedora-csb && sudo ./result/bin/activate'
+ #+end_src
+
+* System-Manager Configuration
+
+The system-manager configuration is at =systems/fedora-csb/system.nix=.
+
+To rebuild and activate:
+
+#+begin_src bash
+# Build only
+nix build .#systemConfigs.fedora-csb
+
+# Build and activate
+nix build .#systemConfigs.fedora-csb && sudo ./result/bin/activate
+#+end_src
+
+* Troubleshooting
+
+** Nix not found after bootstrap
+
+Restart your shell or source the Nix profile:
+
+#+begin_src bash
+. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
+#+end_src
+
+** SELinux issues
+
+The Determinate Systems installer handles SELinux, but if you encounter issues:
+
+#+begin_src bash
+# Check SELinux status
+getenforce
+
+# Temporarily set to permissive for testing
+sudo setenforce 0
+#+end_src
+
+** VM networking issues
+
+Check libvirt network is running:
+
+#+begin_src bash
+virsh net-list --all
+virsh net-start default
+#+end_src
+
+* Notes
+
+- CSB ISO is self-automating, no Kickstart needed
+- If CSB doesn't work in VM, fall back to regular Fedora
+- System-manager works alongside Fedora's package manager (dnf)
lib/default.nix
@@ -205,7 +205,6 @@
hostname,
desktop ? null,
pkgsInput ? inputs.nixpkgs,
- homeInput ? inputs.home-manager,
}:
let
globals = import ../globals.nix {
@@ -229,9 +228,8 @@
inputs.system-manager.lib.makeSystemConfig {
inherit extraSpecialArgs;
modules = [
- # self.nixosModules.wireguard-client
- # inputs.agenix.nixosModules.default
- homeInput.nixosModules.home-manager
+ # NOTE: home-manager nixosModules is not compatible with system-manager
+ # Use standalone home-manager instead for user configuration
{
config = {
nixpkgs.hostPlatform = system;
systems/fedora-csb/system.nix
@@ -0,0 +1,26 @@
+{ pkgs, ... }:
+{
+ config = {
+ # Platform
+ nixpkgs.hostPlatform = "x86_64-linux";
+
+ # System packages managed by Nix
+ environment.systemPackages = with pkgs; [
+ # Core utilities
+ vim
+ htop
+ curl
+ git
+ ripgrep
+ fd
+ jq
+
+ # Development tools
+ helix
+
+ # Networking
+ wireguard-tools
+ ];
+
+ };
+}
flake.nix
@@ -154,6 +154,10 @@
hostname = "nagoya";
system = "aarch64-linux";
};
+ fedora-csb = libx.mkSystemManager {
+ hostname = "fedora-csb";
+ system = "x86_64-linux";
+ };
};
images = {