From b01c6222f8ea09baa0ba7de01db64798ad039ef0 Mon Sep 17 00:00:00 2001 From: Kat Inskip Date: Mon, 30 Jan 2023 08:02:10 -0800 Subject: [PATCH] feat: distributed builder work --- common/distributed.nix | 28 ++++++++++++++++++++ common/network.nix | 3 +++ darwin/distributed.nix | 5 ++++ nixos/common/network.nix | 7 ++--- nixos/rosetta.nix | 18 +++++++++++++ systems/renko.nix | 25 +++++------------- systems/sumireko.nix | 56 +--------------------------------------- 7 files changed, 63 insertions(+), 79 deletions(-) create mode 100644 common/distributed.nix create mode 100644 common/network.nix create mode 100644 darwin/distributed.nix create mode 100644 nixos/rosetta.nix diff --git a/common/distributed.nix b/common/distributed.nix new file mode 100644 index 00000000..894e0e15 --- /dev/null +++ b/common/distributed.nix @@ -0,0 +1,28 @@ +{ lib, config, inputs, ... }: let + inherit (lib.attrsets) mapAttrsToList; + inherit (lib.lists) optionals; + buildMachines = mapAttrsToList (name: config_: let + config = config_.config; + in { + hostName = "${config.networking.hostName}.inskip.me"; + sshUser = "deploy"; + systems = [ config.nixpkgs.system ] ++ optionals (config.nix.settings ? extra-platforms) config.nix.settings.extra-platforms; + maxJobs = 100; + speedFactor = 1; # TODO: provide adjustment factor + supportedFeatures = [ "nixos-test" "benchmark" "big-parallel" "kvm" ]; + } ) inputs.self.nixosConfigurations; + daiyousei = { + hostName = "daiyousei.inskip.me"; + sshUser = "root"; + system = "aarch64-linux"; + maxJobs = 100; + speedFactor = 1; + supportedFeatures = ["benchmark" "big-parallel" "kvm"]; + mandatoryFeatures = []; + }; +in { + nix = { + inherit buildMachines; + distributedBuilds = true; + }; +} diff --git a/common/network.nix b/common/network.nix new file mode 100644 index 00000000..6f15b2d1 --- /dev/null +++ b/common/network.nix @@ -0,0 +1,3 @@ +{ machine, ... }: { + networking.hostName = machine; +} diff --git a/darwin/distributed.nix b/darwin/distributed.nix new file mode 100644 index 00000000..36b43168 --- /dev/null +++ b/darwin/distributed.nix @@ -0,0 +1,5 @@ +_: { + nix.envVars = { + "SSH_AUTH_SOCK" = "/Users/kat/.gnupg/S.gpg-agent.ssh"; + }; +} diff --git a/nixos/common/network.nix b/nixos/common/network.nix index 71114927..1a96efd4 100644 --- a/nixos/common/network.nix +++ b/nixos/common/network.nix @@ -1,7 +1,4 @@ -{ machine, ... }: { - networking = { - hostName = machine; - nftables.enable = true; - }; +_: { + networking.nftables.enable = true; services.tailscale.enable = true; } diff --git a/nixos/rosetta.nix b/nixos/rosetta.nix new file mode 100644 index 00000000..b26a3c84 --- /dev/null +++ b/nixos/rosetta.nix @@ -0,0 +1,18 @@ +_: { + boot = { + initrd.availableKernelModules = [ "virtiofs"]; + binfmt.registrations."rosetta" = { + interpreter = "/run/rosetta/rosetta"; + fixBinary = true; + wrapInterpreterInShell = false; + matchCredentials = true; + magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00''; + mask = ''\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff''; + }; + }; + + nix.settings = { + extra-platforms = [ "x86_64-linux" ]; + extra-sandbox-paths = [ "/run/rosetta" "/run/binfmt" ]; + }; +} diff --git a/systems/renko.nix b/systems/renko.nix index 01ab4fe8..b1a948b1 100644 --- a/systems/renko.nix +++ b/systems/renko.nix @@ -1,27 +1,14 @@ _: let - hostConfig = { lib, ... }: let + hostConfig = { lib, tree, ... }: let inherit (lib.modules) mkDefault; in { - imports = [ + imports = with tree; [ + nixos.rosetta ]; boot = { - systemd-boot.enable = true; - initrd = { - availableKernelModules = ["virtio_pci" "xhci_pci" "usb_storage" "usbhid" "virtiofs"]; - }; - nix.settings = { - extra-platforms = [ "x86_64-linux" ]; - extra-sandbox-paths = [ "/run/rosetta" "/run/binfmt" ]; - }; - binfmt.registrations."rosetta" = { - interpreter = "/run/rosetta/rosetta"; - fixBinary = true; - wrapInterpreterInShell = false; - matchCredentials = true; - magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00''; - mask = ''\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff''; - }; + loader.systemd-boot.enable = true; + initrd.availableKernelModules = ["virtio_pci" "xhci_pci" "usb_storage" "usbhid" ]; }; fileSystems = { @@ -51,7 +38,7 @@ _: let system.stateVersion = "22.11"; }; in { - arch = "aarch64-linux"; + arch = "aarch64"; type = "NixOS"; modules = [ hostConfig diff --git a/systems/sumireko.nix b/systems/sumireko.nix index edc486f4..c261f5d4 100644 --- a/systems/sumireko.nix +++ b/systems/sumireko.nix @@ -2,65 +2,11 @@ _: let hostConfig = {tree, pkgs, ...}: { imports = with tree; [ kat.work + darwin.distributed ]; security.pam.enableSudoTouchIdAuth = true; - home-manager.users = let - commonUser = { - programs.ssh = { - enable = true; - matchBlocks = { - "koishi.inskip.me" = { - hostname = "koishi.inskip.me"; - port = 22; - user = "root"; - }; - "daiyousei.inskip.me" = { - hostname = "daiyousei.inskip.me"; - port = 62954; - user = "root"; - }; - "renko-build" = { - hostname = "192.168.64.3"; - port = 62954; - user = "root"; - }; - }; - }; - }; - in { - kat = commonUser; - root = commonUser; - }; - - nix = { - envVars = { - "SSH_AUTH_SOCK" = "/Users/kat/.gnupg/S.gpg-agent.ssh"; - }; - buildMachines = [ - { - hostName = "koishi.inskip.me"; - sshUser = "deploy"; - system = "x86_64-linux"; - maxJobs = 100; - speedFactor = 1; - supportedFeatures = ["benchmark" "big-parallel" "kvm"]; - mandatoryFeatures = []; - } - { - hostName = "daiyousei-build"; - sshUser = "root"; - system = "aarch64-linux"; - maxJobs = 100; - speedFactor = 1; - supportedFeatures = ["benchmark" "big-parallel" "kvm"]; - mandatoryFeatures = []; - } - ]; - distributedBuilds = true; - }; - homebrew = { brewPrefix = "/opt/homebrew/bin"; brews = [