diff --git a/flake.nix b/flake.nix index ce4af6b..e7d033d 100644 --- a/flake.nix +++ b/flake.nix @@ -81,9 +81,9 @@ inputs.nixpkgs.follows = "nixpkgs"; }; vintagestory-nix = { - url = "git+https://codeberg.org/PierreBorine/vintagestory-nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; + url = "git+https://codeberg.org/PierreBorine/vintagestory-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; # The owner's Neovim configuration (modules/cli/neovim.nix): plain files, # not a flake. The repository is private and Nix has no credentials for # HTTPS, so it is fetched over SSH with the key of the user who runs nix diff --git a/modules/cli/git.nix b/modules/cli/git.nix index 6e59763..25250ae 100644 --- a/modules/cli/git.nix +++ b/modules/cli/git.nix @@ -32,16 +32,16 @@ in }; jujutsu = { - enable = true; - settings = { - user = { - name = owner.fullName; - inherit (owner) email; - }; - ui = { - diff.format = "color-words"; - }; + enable = true; + settings = { + user = { + name = owner.fullName; + inherit (owner) email; }; + ui = { + diff.format = "color-words"; + }; + }; }; # Syntax-highlighted diffs as the git pager. diff --git a/modules/desktop/apps.nix b/modules/desktop/apps.nix index 9624c41..050263b 100644 --- a/modules/desktop/apps.nix +++ b/modules/desktop/apps.nix @@ -7,7 +7,7 @@ flake.modules.homeManager.apps = { pkgs, ... }: let - vintagestory = pkgs.vintagestoryPackages.v1-22-7.overrideAttrs (old: { + vintagestory = pkgs.vintagestoryPackages.v1-22-7.overrideAttrs (old: { # Put the actual executable in the game directory. postInstall = (old.postInstall or "") + '' install -Dm755 ${./PlayVintageStory} \ @@ -38,7 +38,8 @@ 'Exec=vintagestory' \ "Exec=$out/bin/PlayVintageStory" ''; - }); in + }); + in { programs = { firefox = { diff --git a/modules/dev/_gitea-vm-runner-assets/macos/bootstrap.sh b/modules/dev/_gitea-vm-runner-assets/macos/bootstrap.sh index 0587db8..7ad9d07 100755 --- a/modules/dev/_gitea-vm-runner-assets/macos/bootstrap.sh +++ b/modules/dev/_gitea-vm-runner-assets/macos/bootstrap.sh @@ -37,8 +37,8 @@ brew update brew install gcc cmake ninja rustup-init vulkan-headers vulkan-loader vulkan-tools molten-vk node git git-lfs rustup-init -y --default-toolchain stable --no-modify-path export PATH="$HOME/.cargo/bin:$(brew --prefix)/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" -"$HOME/.cargo/bin/rustup" toolchain install stable -"$HOME/.cargo/bin/rustup" default stable +"$HOME/.cargo/bin/rustup" toolchain install nightly +"$HOME/.cargo/bin/rustup" default nightly GXX="$(brew --prefix gcc)/bin/g++-16" if [[ ! -x "$GXX" ]]; then diff --git a/modules/dev/_gitea-vm-runner-assets/windows/install.ps1 b/modules/dev/_gitea-vm-runner-assets/windows/install.ps1 index 29ef696..885c3cc 100644 --- a/modules/dev/_gitea-vm-runner-assets/windows/install.ps1 +++ b/modules/dev/_gitea-vm-runner-assets/windows/install.ps1 @@ -11,13 +11,29 @@ function Invoke-Installer([string]$File, [string]$Arguments, [int[]]$SuccessCode } function Download([string]$Url, [string]$Path) { - Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $Path + # Always log the exact request: a thrown Invoke-WebRequest otherwise hides + # which vendor URL returned the HTTP error in the OEM transcript. + Write-Host "Downloading [$Url] to [$Path]" + try { + Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $Path -TimeoutSec 600 -MaximumRedirection 10 + if (-not (Test-Path $Path) -or (Get-Item -LiteralPath $Path).Length -le 0) { + throw 'The server returned no file data.' + } + } catch { + $status = 'unknown' + if ($_.Exception.Response) { + try { $status = [string]$_.Exception.Response.StatusCode } catch { } + } + Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue + throw "Download failed from [$Url] (HTTP $status): $($_.Exception.Message)" + } } try { New-Item -ItemType Directory -Force -Path 'C:\ci-tools', 'C:\ci-tools\downloads', 'C:\ci-tools\cargo', 'C:\ci-tools\rustup', 'C:\ci\gitea-runner' | Out-Null # Node is needed by JavaScript-based Gitea Actions. Pin to the current Node 24 LTS line. + Write-Host 'Resolving the latest Node.js 24 LTS release from https://nodejs.org/dist/index.json.' $nodeRelease = Invoke-RestMethod -Uri 'https://nodejs.org/dist/index.json' | Where-Object { $_.version -match '^v24\.' -and $_.lts } | Select-Object -First 1 @@ -26,9 +42,18 @@ try { Download "https://nodejs.org/dist/$($nodeRelease.version)/node-$($nodeRelease.version)-x64.msi" $nodeMsi Invoke-Installer "$env:SystemRoot\System32\msiexec.exe" "/i `"$nodeMsi`" /qn /norestart" @(0, 3010) - # Git's official installer; jobs execute as SYSTEM in this isolated guest. - $gitInstaller = 'C:\ci-tools\downloads\Git-64-bit.exe' - Download 'https://github.com/git-for-windows/git/releases/latest/download/Git-64-bit.exe' $gitInstaller + # The release asset's filename includes its version; GitHub does not + # provide a generic Git-64-bit.exe alias. Resolve the asset from the API. + Write-Host 'Resolving the latest Git for Windows x64 installer from GitHub Releases.' + $gitRelease = Invoke-RestMethod -UseBasicParsing ` + -Uri 'https://api.github.com/repos/git-for-windows/git/releases/latest' ` + -Headers @{ 'User-Agent' = 'gitea-vm-runner-provisioner'; 'Accept' = 'application/vnd.github+json' } + $gitAsset = $gitRelease.assets | + Where-Object { $_.name -match '^Git-[0-9.]+-64-bit\.exe$' } | + Select-Object -First 1 + if (-not $gitAsset) { throw 'GitHub latest release did not contain a versioned x64 Git installer.' } + $gitInstaller = "C:\ci-tools\downloads\$($gitAsset.name)" + Download $gitAsset.browser_download_url $gitInstaller Invoke-Installer $gitInstaller '/VERYSILENT /NORESTART /SP- /DIR="C:\Program Files\Git"' @(0, 3010) # MSVC compatibility lane plus the MSYS2 UCRT64 GCC lane for C++26 reflection/contracts. @@ -61,7 +86,7 @@ try { $env:RUSTUP_HOME = 'C:\ci-tools\rustup' $rustup = 'C:\ci-tools\downloads\rustup-init.exe' Download 'https://win.rustup.rs/x86_64' $rustup - Invoke-Installer $rustup '-y --default-toolchain stable --no-modify-path' @(0) + Invoke-Installer $rustup '-y --default-toolchain nightly --no-modify-path' @(0) # Ensure the native toolchain paths are available to jobs launched by Task Scheduler. $machinePath = [Environment]::GetEnvironmentVariable('Path', 'Machine') diff --git a/modules/dev/docker.nix b/modules/dev/docker.nix index ac35d5d..55349e0 100644 --- a/modules/dev/docker.nix +++ b/modules/dev/docker.nix @@ -13,7 +13,7 @@ in enable = true; setSocketVariable = true; daemon.settings = { - experimental = true; + experimental = true; }; }; diff --git a/modules/dev/gitea-runner.nix b/modules/dev/gitea-runner.nix index c4a1095..fa80e8a 100644 --- a/modules/dev/gitea-runner.nix +++ b/modules/dev/gitea-runner.nix @@ -37,14 +37,14 @@ in ]; hostPackages = with pkgs; [ - bashInteractive - coreutils - curl - gitMinimal - nix - nodejs_26 - wget - ]; + bashInteractive + coreutils + curl + gitMinimal + nix + nodejs_26 + wget + ]; settings = { runner = { capacity = 5; diff --git a/modules/dev/gitea-vm-runners.nix b/modules/dev/gitea-vm-runners.nix index 17504be..fbebb5c 100644 --- a/modules/dev/gitea-vm-runners.nix +++ b/modules/dev/gitea-vm-runners.nix @@ -8,10 +8,25 @@ let hasApiSecret = builtins.pathExists apiSecret; in { - flake.modules.nixos.gitea-vm-runners = { config, lib, pkgs, ... }: + flake.modules.nixos.gitea-vm-runners = + { + config, + lib, + pkgs, + ... + }: let assets = ./_gitea-vm-runner-assets; + # The Docker Hub v3.12/latest image predates the Reims vGPU QEMU fix. + # Build a pinned upstream source revision lazily on first macOS VM start. + # Bump this revision to select a new source tree and image tag together. + macosRev = "16a5b470cdd601bae8b05b02d748d7edfb36c12e"; + macosSource = builtins.fetchGit { + url = "https://github.com/dockur/macos.git"; + rev = macosRev; + }; + macosImage = "local/dockur-macos:${builtins.substring 0 7 macosRev}"; windowsOem = pkgs.runCommand "gitea-vm-windows-oem" { } '' mkdir -p "$out" cp ${assets}/windows/install.bat "$out/install.bat" @@ -33,44 +48,55 @@ in set -euo pipefail state=/var/lib/gitea-vm-runners/windows oem=/run/gitea-vm-runners/windows-oem + share=/run/gitea-vm-runners/windows-share ${pkgs.coreutils}/bin/mkdir -p "$state" /run/gitea-vm-runners - ${pkgs.coreutils}/bin/rm -rf "$oem" + ${pkgs.coreutils}/bin/rm -rf "$oem" "$share" ${pkgs.coreutils}/bin/mkdir -m 0700 -p "$oem" + ${pkgs.coreutils}/bin/mkdir -m 0755 -p "$share" ${pkgs.coreutils}/bin/cp -R ${windowsOem}/. "$oem/" + ${pkgs.coreutils}/bin/cp ${windowsOem}/install.ps1 ${windowsOem}/cxx26-feature-probe.cpp "$share/" ${registrationCopy} ${pkgs.docker}/bin/docker rm -f gitea-vm-windows >/dev/null 2>&1 || true exec ${pkgs.docker}/bin/docker run --rm --init \ --name gitea-vm-windows \ --device=/dev/kvm --device=/dev/net/tun --cap-add=NET_ADMIN \ -e VERSION=11 -e RAM_SIZE=16G -e CPU_CORES=8 -e DISK_SIZE=160G \ + -e SAMBA_READONLY=Y \ -p 127.0.0.1:18006:8006 \ -p 127.0.0.1:13389:3389/tcp \ -v /var/lib/gitea-vm-runners/windows:/storage \ -v "$oem:/oem:ro" \ + -v "$share:/shared" \ dockurr/windows:latest ''; windowsStop = pkgs.writeShellScript "gitea-vm-windows-stop" '' set +e ${pkgs.docker}/bin/docker stop --time 120 gitea-vm-windows >/dev/null 2>&1 - ${pkgs.coreutils}/bin/rm -rf /run/gitea-vm-runners/windows-oem + ${pkgs.coreutils}/bin/rm -rf /run/gitea-vm-runners/windows-oem /run/gitea-vm-runners/windows-share exit 0 ''; macosStart = pkgs.writeShellScript "gitea-vm-macos-start" '' set -euo pipefail + # Build once into Docker's persistent image store. Guest RAM is not + # allocated during idle; this image build happens only on the first start. + if ! ${pkgs.docker}/bin/docker image inspect ${macosImage} >/dev/null 2>&1; then + echo "Building pinned dockur/macos source ${macosRev} (one-time first start)..." >&2 + ${pkgs.docker}/bin/docker build --pull --tag ${macosImage} ${macosSource} + fi ${pkgs.coreutils}/bin/mkdir -p /var/lib/gitea-vm-runners/macos ${pkgs.docker}/bin/docker rm -f gitea-vm-macos >/dev/null 2>&1 || true exec ${pkgs.docker}/bin/docker run --rm --init \ --name gitea-vm-macos \ --device=/dev/kvm --device=/dev/net/tun --device=/dev/dri --cap-add=NET_ADMIN \ - -e VERSION=15 -e RAM_SIZE=16G -e CPU_CORES=8 -e DISK_SIZE=128G -e GPU=Y \ + -e VERSION=15 -e RAM_SIZE=8G -e CPU_CORES=8 -e DISK_SIZE=128G -e GPU=Y \ -p 127.0.0.1:18007:8006 \ -p 127.0.0.1:15900:5900/tcp \ -p 127.0.0.1:15900:5900/udp \ -v /var/lib/gitea-vm-runners/macos:/storage \ -v ${macosShare}:/shared:ro \ - dockurr/macos:latest + ${macosImage} ''; macosStop = pkgs.writeShellScript "gitea-vm-macos-stop" '' @@ -81,7 +107,10 @@ in in { # AMD KVM support. The host's existing docker aspect provides docker.service. - boot.kernelModules = lib.mkAfter [ "kvm-amd" "tun" ]; + boot.kernelModules = lib.mkAfter [ + "kvm-amd" + "tun" + ]; age.secrets = lib.optionalAttrs hasApiSecret { gitea-vm-runner-api-token = { @@ -135,7 +164,11 @@ in description = "Wake Gitea Windows/macOS runners for queued workflow jobs"; wantedBy = [ "multi-user.target" ]; wants = [ "network-online.target" ]; - after = [ "network-online.target" "docker.service" "agenix.service" ]; + after = [ + "network-online.target" + "docker.service" + "agenix.service" + ]; requires = [ "docker.service" ]; serviceConfig = { Type = "simple"; @@ -148,4 +181,4 @@ in }; }; - } +} diff --git a/modules/hardware/amd.nix b/modules/hardware/amd.nix index d63b838..ad2ce1c 100644 --- a/modules/hardware/amd.nix +++ b/modules/hardware/amd.nix @@ -23,7 +23,10 @@ cpu.amd.updateMicrocode = lib.mkDefault true; }; - boot.kernelModules = [ "kvm-amd" "tun" ]; + boot.kernelModules = [ + "kvm-amd" + "tun" + ]; # LACT: GPU monitoring, fan curves and overclocking. services.lact.enable = true; diff --git a/modules/hosts/desktop/host.nix b/modules/hosts/desktop/host.nix index c3d42a2..710fc8c 100644 --- a/modules/hosts/desktop/host.nix +++ b/modules/hosts/desktop/host.nix @@ -29,6 +29,7 @@ in proxy-suite docker gitea-runner + gitea-vm-runners nix-ld ];