Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 1 | # Top-level file aggregating all machines managed from hscloud. |
| 2 | # |
| 3 | # This allows to have a common attrset of machines that can be deployed |
| 4 | # in the same way. |
| 5 | # |
Serge Bazanski | b3c6770 | 2021-09-10 22:27:24 +0000 | [diff] [blame] | 6 | # For information about building/deploying machines see //ops/README.md. |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 7 | |
Serge Bazanski | c35ea6a | 2022-07-07 17:47:58 +0200 | [diff] [blame] | 8 | { hscloud, pkgs, hscloudForPkgs, ... }: |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 9 | |
| 10 | let |
Serge Bazanski | b3c6770 | 2021-09-10 22:27:24 +0000 | [diff] [blame] | 11 | # nixpkgs for cluster machines (.hswaw.net). Currently pinned to an old |
| 12 | # nixpkgs because NixOS modules for kubernetes changed enough that it's not |
| 13 | # super easy to use them as is. |
| 14 | # |
| 15 | # TODO(q3k): fix this: use an old nixpkgs for Kube modules while using |
| 16 | # hscloud nixpkgs for everything else. |
| 17 | nixpkgsCluster = import (pkgs.fetchFromGitHub { |
| 18 | owner = "nixos"; |
| 19 | repo = "nixpkgs-channels"; |
| 20 | rev = "44ad80ab1036c5cc83ada4bfa451dac9939f2a10"; |
| 21 | sha256 = "1b61nzvy0d46cspy07szkc0rggacxiqg9v1py27pkqpj7rvawfsk"; |
Serge Bazanski | 3a9562e | 2023-02-28 01:14:26 +0000 | [diff] [blame] | 22 | }) { }; |
Serge Bazanski | b3c6770 | 2021-09-10 22:27:24 +0000 | [diff] [blame] | 23 | |
Serge Bazanski | 8f08423 | 2023-03-10 20:52:06 +0100 | [diff] [blame] | 24 | # TODO(patryk): unpin and upgrade |
| 25 | nixpkgsBgpwtf = import (pkgs.fetchFromGitHub { |
| 26 | owner = "nixos"; |
| 27 | repo = "nixpkgs-channels"; |
| 28 | rev = "e26c0ffdb013cd378fc2528a44689a8bf35d2a6c"; |
| 29 | sha256 = "1b33hw35fqb9rzszdg5jpiyfvhx2cxpv0qrkyr19zkdpdahzdbss"; |
| 30 | }) { }; |
| 31 | |
| 32 | |
Serge Bazanski | a16af2d | 2021-10-16 19:14:05 +0000 | [diff] [blame] | 33 | # mkMachine builds NixOS modules into a NixOS derivation. |
| 34 | # It: |
| 35 | # 1) injects passthru.hscloud.provision which deploys that configuration |
| 36 | # over SSH to a production machine. |
| 37 | # 2) injects 'workspace' as a nixos module argument which points to the root |
| 38 | # of the hscloud readTree object. It will contain whatever nixpkgs |
| 39 | # checkout this file has been invoked with, ie. will not be 'mixed in' |
| 40 | # with the pkgs argument. |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 41 | mkMachine = machines: pkgs: paths: pkgs.nixos ({ config, pkgs, ... }: { |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 42 | imports = paths; |
Serge Bazanski | b3c6770 | 2021-09-10 22:27:24 +0000 | [diff] [blame] | 43 | |
| 44 | config = let |
| 45 | name = config.networking.hostName; |
| 46 | domain = if (config.networking ? domain) && config.networking.domain != null then config.networking.domain else "hswaw.net"; |
| 47 | fqdn = name + "." + domain; |
| 48 | toplevel = config.system.build.toplevel; |
| 49 | |
| 50 | runProvision = '' |
| 51 | #!/bin/sh |
| 52 | set -eu |
| 53 | remote=root@${fqdn} |
| 54 | echo "Configuration for ${fqdn} is ${toplevel}" |
| 55 | nix copy -s --to ssh://$remote ${toplevel} |
| 56 | |
| 57 | running="$(ssh $remote readlink -f /nix/var/nix/profiles/system)" |
| 58 | if [ "$running" == "${toplevel}" ]; then |
| 59 | echo "${fqdn} already running ${toplevel}." |
| 60 | else |
| 61 | echo "/etc/systemd/system diff:" |
| 62 | ssh $remote diff -ur /var/run/current-system/etc/systemd/system ${toplevel}/etc/systemd/system || true |
| 63 | echo "" |
| 64 | echo "" |
| 65 | echo "dry-activate diff:" |
| 66 | ssh $remote ${toplevel}/bin/switch-to-configuration dry-activate |
| 67 | read -p "Do you want to switch to this configuration? " -n 1 -r |
| 68 | echo |
| 69 | if ! [[ $REPLY =~ ^[Yy]$ ]]; then |
| 70 | exit 1 |
| 71 | fi |
| 72 | |
| 73 | echo -ne "\n\nswitch-to-configuration test...\n" |
| 74 | ssh $remote ${toplevel}/bin/switch-to-configuration test |
| 75 | fi |
| 76 | |
| 77 | echo -ne "\n\n" |
| 78 | read -p "Do you want to set this configuration as boot? " -n 1 -r |
| 79 | echo |
| 80 | if ! [[ $REPLY =~ ^[Yy]$ ]]; then |
| 81 | exit 1 |
| 82 | fi |
| 83 | |
| 84 | echo -ne "\n\nsetting system profile...\n" |
| 85 | ssh $remote nix-env -p /nix/var/nix/profiles/system --set ${toplevel} |
| 86 | |
| 87 | echo -ne "\n\nswitch-to-configuration boot...\n" |
| 88 | ssh $remote ${toplevel}/bin/switch-to-configuration boot |
| 89 | ''; |
| 90 | in { |
| 91 | passthru.hscloud.provision = pkgs.writeScript "provision-${fqdn}" runProvision; |
Serge Bazanski | a16af2d | 2021-10-16 19:14:05 +0000 | [diff] [blame] | 92 | |
| 93 | # TODO(q3k): this should be named hscloud, but that seems to not work. Debug and rename. |
Serge Bazanski | c35ea6a | 2022-07-07 17:47:58 +0200 | [diff] [blame] | 94 | _module.args.workspace = hscloudForPkgs pkgs; |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 95 | _module.args.machines = machines; |
Serge Bazanski | b3c6770 | 2021-09-10 22:27:24 +0000 | [diff] [blame] | 96 | }; |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 97 | }); |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 98 | |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 99 | mkClusterMachine = machines: path: mkMachine machines nixpkgsCluster [ |
| 100 | ../cluster/machines/modules/base.nix |
| 101 | ../cluster/machines/modules/kube-controlplane.nix |
| 102 | ../cluster/machines/modules/kube-dataplane.nix |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 103 | path |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 104 | ]; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 105 | |
Serge Bazanski | f6e6abb | 2023-03-31 22:39:45 +0000 | [diff] [blame] | 106 | mkClusterMachineNew = machines: path: mkMachine machines nixpkgsBgpwtf [ |
Serge Bazanski | ef3aab6 | 2022-11-18 14:39:45 +0000 | [diff] [blame] | 107 | ../cluster/machines/modules/base.nix |
| 108 | ../cluster/machines/modules/kube-controlplane.nix |
| 109 | ../cluster/machines/modules/kube-dataplane.nix |
Serge Bazanski | ef3aab6 | 2022-11-18 14:39:45 +0000 | [diff] [blame] | 110 | path |
| 111 | ]; |
| 112 | |
| 113 | |
Serge Bazanski | 5ac5e4b | 2022-07-06 00:31:35 +0200 | [diff] [blame] | 114 | pkgsArm = import pkgs.path { |
| 115 | system = "aarch64-linux"; |
| 116 | }; |
| 117 | |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 118 | machines = self: { |
Serge Bazanski | ef3aab6 | 2022-11-18 14:39:45 +0000 | [diff] [blame] | 119 | "bc01n01.hswaw.net" = mkClusterMachineNew self ../cluster/machines/bc01n01.hswaw.net.nix; |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 120 | "bc01n02.hswaw.net" = mkClusterMachine self ../cluster/machines/bc01n02.hswaw.net.nix; |
Serge Bazanski | 712a5dc | 2023-02-28 01:15:40 +0000 | [diff] [blame] | 121 | "bc01n05.hswaw.net" = mkClusterMachineNew self ../cluster/machines/bc01n05.hswaw.net.nix; |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 122 | "dcr01s22.hswaw.net" = mkClusterMachine self ../cluster/machines/dcr01s22.hswaw.net.nix; |
| 123 | "dcr01s24.hswaw.net" = mkClusterMachine self ../cluster/machines/dcr01s24.hswaw.net.nix; |
Bartosz Stebel | 9a88f28 | 2023-10-08 22:26:20 +0200 | [diff] [blame] | 124 | "dcr03s16.hswaw.net" = mkClusterMachineNew self ../cluster/machines/dcr03s16.hswaw.net.nix; |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 125 | |
Serge Bazanski | 8f08423 | 2023-03-10 20:52:06 +0100 | [diff] [blame] | 126 | "edge01.waw.bgp.wtf" = mkMachine self nixpkgsBgpwtf [ |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 127 | ../bgpwtf/machines/edge01.waw.bgp.wtf.nix |
| 128 | ../bgpwtf/machines/edge01.waw.bgp.wtf-hardware.nix |
| 129 | ]; |
| 130 | |
Serge Bazanski | 5ac5e4b | 2022-07-06 00:31:35 +0200 | [diff] [blame] | 131 | "larrythebuilder.q3k.org" = mkMachine self pkgsArm [ |
| 132 | ../hswaw/machines/larrythebuilder.q3k.org/configuration.nix |
| 133 | ]; |
| 134 | |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 135 | "customs.hackerspace.pl" = mkMachine self pkgs [ |
| 136 | ../hswaw/machines/customs.hackerspace.pl/configuration.nix |
| 137 | ]; |
Serge Bazanski | 5ac5e4b | 2022-07-06 00:31:35 +0200 | [diff] [blame] | 138 | "tv1.waw.hackerspace.pl" = mkMachine self pkgsArm [ |
Serge Bazanski | dcdbd84 | 2022-07-07 02:30:09 +0200 | [diff] [blame] | 139 | ../hswaw/machines/tv/tv1.nix |
| 140 | ]; |
| 141 | "tv2.waw.hackerspace.pl" = mkMachine self pkgsArm [ |
| 142 | ../hswaw/machines/tv/tv2.nix |
Serge Bazanski | 5ac5e4b | 2022-07-06 00:31:35 +0200 | [diff] [blame] | 143 | ]; |
vuko | deeeff8 | 2022-10-02 23:12:29 +0200 | [diff] [blame] | 144 | "sound.waw.hackerspace.pl" = let |
| 145 | # TODO update global pkgs to >= 22.05 and remove this override |
| 146 | # building on current pkgs gives error: |
| 147 | # error: The option `services.home-assistant.extraComponents' does not exist. |
| 148 | pkgs = import (fetchTarball { |
| 149 | # NixOS/nixpkgs/nixos-unstable 2022-09-10 |
| 150 | url = "https://api.github.com/repos/NixOS/nixpkgs/tarball/2da64a81275b68fdad38af669afeda43d401e94b"; |
| 151 | sha256 = "1k71lmzdaa48yqkmsnd22n177qmxxi4gj2qcmdbv0mc6l4f27wd0"; |
| 152 | }) {}; |
| 153 | in mkMachine self pkgs [ |
| 154 | ../hswaw/machines/sound.waw.hackerspace.pl/configuration.nix |
| 155 | ]; |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | in pkgs.lib.fix machines |