fix: remote building to also use localhost

This commit is contained in:
Moritz Böhme 2025-04-14 16:58:56 +02:00
parent 184ef24913
commit 086ff8fa1c
No known key found for this signature in database
GPG key ID: 970C6E89EB0547A9
2 changed files with 16 additions and 19 deletions

View file

@ -23,10 +23,7 @@
# This only works however if you have avahi running on your admin machine else use IP
clan.core.networking.targetHost = "root@moritz-desktop";
our.buildMachines = {
enable = true;
speedFactor = 2;
};
our.buildMachines.enable = true;
my = {
ai.enable = true;

View file

@ -21,33 +21,38 @@
others = filterAttrs (n: _v: n != config.networking.hostName) self.nixosConfigurations;
max = a: b:
if a > b
then a
else b;
mkBuilder = hostName: attrs: let
config' = attrs.config;
cfg' = config'.our.buildMachines;
pkgs' = attrs.pkgs;
in
mkIf cfg'.enable {
hostName = hostName;
sshUser = "remotebuild";
# NOTE: https://github.com/NixOS/nix/issues/3177
hostName =
if hostName == config.networking.hostName
then "local?root=/nix/store"
else hostName;
sshUser =
if hostName == config.networking.hostName
then null
else "remotebuild";
# CPU architecture of the builder, and the operating system it runs.
# If your builder supports multiple architectures
# (e.g. search for "binfmt" for emulation),
systems = [pkgs'.system] ++ config'.boot.binfmt.emulatedSystems;
# Nix custom ssh-variant that avoids lots of "trusted-users" settings pain
protocol = "ssh-ng";
protocol =
if hostName == config.networking.hostName
then null
else "ssh-ng";
# default is 1 but may keep the builder idle in between builds
maxJobs = 3;
speedFactor = max (cfg'.speedFactor - cfg.speedFactor + 1) 1;
speedFactor = 1;
supportedFeatures = cfg'.supportedFeatures;
mandatoryFeatures = [];
};
buildMachines = mapAttrsToList mkBuilder others;
buildMachines = mapAttrsToList mkBuilder self.nixosConfigurations;
remotebuildKeys =
mapAttrsToList (
@ -81,11 +86,6 @@ in {
benchmark | Machine can generate metrics (means the builds usually takes the same amount of time)
'';
};
speedFactor = mkOption {
type = types.int;
default = 1;
description = "How fast is the builder compared to your local machine";
};
};
config = mkIf cfg.enable {
users.users.remotebuild = {