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 | 9848e7e | 2021-09-10 22:30:56 +0000 | [diff] [blame] | 22 | }) { |
| 23 | overlays = [ |
| 24 | (self: super: rec { |
| 25 | # Use a newer version of Ceph (16, Pacific, EOL 2023-06-01) than in |
| 26 | # this nixpkgs (15, Octopus, EOL 2022-06-01). |
| 27 | # |
| 28 | # This is to: |
| 29 | # 1. Fix a bug in which ceph-volume lvm create fails due to a rocksdb |
| 30 | # mismatch (https://tracker.ceph.com/issues/49815) |
| 31 | # 2. At the time of deployment not start out with an ancient version |
| 32 | # of Ceph. |
| 33 | # |
| 34 | # Once we unpin nixpkgsCluster past a version that contains this Ceph, |
| 35 | # this can be unoverlayed. |
| 36 | inherit (super.callPackages ./ceph { |
| 37 | boost = super.boost17x.override { enablePython = true; python = super.python3; }; |
| 38 | lua = super.lua5_4; |
| 39 | }) ceph ceph-client; |
| 40 | ceph-lib = ceph.lib; |
| 41 | }) |
| 42 | ]; |
| 43 | }; |
Serge Bazanski | b3c6770 | 2021-09-10 22:27:24 +0000 | [diff] [blame] | 44 | |
Serge Bazanski | a16af2d | 2021-10-16 19:14:05 +0000 | [diff] [blame] | 45 | # mkMachine builds NixOS modules into a NixOS derivation. |
| 46 | # It: |
| 47 | # 1) injects passthru.hscloud.provision which deploys that configuration |
| 48 | # over SSH to a production machine. |
| 49 | # 2) injects 'workspace' as a nixos module argument which points to the root |
| 50 | # of the hscloud readTree object. It will contain whatever nixpkgs |
| 51 | # checkout this file has been invoked with, ie. will not be 'mixed in' |
| 52 | # with the pkgs argument. |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 53 | mkMachine = machines: pkgs: paths: pkgs.nixos ({ config, pkgs, ... }: { |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 54 | imports = paths; |
Serge Bazanski | b3c6770 | 2021-09-10 22:27:24 +0000 | [diff] [blame] | 55 | |
| 56 | config = let |
| 57 | name = config.networking.hostName; |
| 58 | domain = if (config.networking ? domain) && config.networking.domain != null then config.networking.domain else "hswaw.net"; |
| 59 | fqdn = name + "." + domain; |
| 60 | toplevel = config.system.build.toplevel; |
| 61 | |
| 62 | runProvision = '' |
| 63 | #!/bin/sh |
| 64 | set -eu |
| 65 | remote=root@${fqdn} |
| 66 | echo "Configuration for ${fqdn} is ${toplevel}" |
| 67 | nix copy -s --to ssh://$remote ${toplevel} |
| 68 | |
| 69 | running="$(ssh $remote readlink -f /nix/var/nix/profiles/system)" |
| 70 | if [ "$running" == "${toplevel}" ]; then |
| 71 | echo "${fqdn} already running ${toplevel}." |
| 72 | else |
| 73 | echo "/etc/systemd/system diff:" |
| 74 | ssh $remote diff -ur /var/run/current-system/etc/systemd/system ${toplevel}/etc/systemd/system || true |
| 75 | echo "" |
| 76 | echo "" |
| 77 | echo "dry-activate diff:" |
| 78 | ssh $remote ${toplevel}/bin/switch-to-configuration dry-activate |
| 79 | read -p "Do you want to switch to this configuration? " -n 1 -r |
| 80 | echo |
| 81 | if ! [[ $REPLY =~ ^[Yy]$ ]]; then |
| 82 | exit 1 |
| 83 | fi |
| 84 | |
| 85 | echo -ne "\n\nswitch-to-configuration test...\n" |
| 86 | ssh $remote ${toplevel}/bin/switch-to-configuration test |
| 87 | fi |
| 88 | |
| 89 | echo -ne "\n\n" |
| 90 | read -p "Do you want to set this configuration as boot? " -n 1 -r |
| 91 | echo |
| 92 | if ! [[ $REPLY =~ ^[Yy]$ ]]; then |
| 93 | exit 1 |
| 94 | fi |
| 95 | |
| 96 | echo -ne "\n\nsetting system profile...\n" |
| 97 | ssh $remote nix-env -p /nix/var/nix/profiles/system --set ${toplevel} |
| 98 | |
| 99 | echo -ne "\n\nswitch-to-configuration boot...\n" |
| 100 | ssh $remote ${toplevel}/bin/switch-to-configuration boot |
| 101 | ''; |
| 102 | in { |
| 103 | passthru.hscloud.provision = pkgs.writeScript "provision-${fqdn}" runProvision; |
Serge Bazanski | a16af2d | 2021-10-16 19:14:05 +0000 | [diff] [blame] | 104 | |
| 105 | # 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] | 106 | _module.args.workspace = hscloudForPkgs pkgs; |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 107 | _module.args.machines = machines; |
Serge Bazanski | b3c6770 | 2021-09-10 22:27:24 +0000 | [diff] [blame] | 108 | }; |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 109 | }); |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 110 | |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 111 | mkClusterMachine = machines: path: mkMachine machines nixpkgsCluster [ |
| 112 | ../cluster/machines/modules/base.nix |
| 113 | ../cluster/machines/modules/kube-controlplane.nix |
| 114 | ../cluster/machines/modules/kube-dataplane.nix |
| 115 | ../cluster/machines/modules/ceph.nix |
| 116 | path |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 117 | ]; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 118 | |
Serge Bazanski | 5ac5e4b | 2022-07-06 00:31:35 +0200 | [diff] [blame] | 119 | pkgsArm = import pkgs.path { |
| 120 | system = "aarch64-linux"; |
| 121 | }; |
| 122 | |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 123 | machines = self: { |
| 124 | "bc01n01.hswaw.net" = mkClusterMachine self ../cluster/machines/bc01n01.hswaw.net.nix; |
| 125 | "bc01n02.hswaw.net" = mkClusterMachine self ../cluster/machines/bc01n02.hswaw.net.nix; |
| 126 | "dcr01s22.hswaw.net" = mkClusterMachine self ../cluster/machines/dcr01s22.hswaw.net.nix; |
| 127 | "dcr01s24.hswaw.net" = mkClusterMachine self ../cluster/machines/dcr01s24.hswaw.net.nix; |
| 128 | |
Serge Bazanski | 957d911 | 2022-06-12 12:26:02 +0200 | [diff] [blame] | 129 | "edge01.waw.bgp.wtf" = mkMachine self pkgs [ |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 130 | ../bgpwtf/machines/edge01.waw.bgp.wtf.nix |
| 131 | ../bgpwtf/machines/edge01.waw.bgp.wtf-hardware.nix |
| 132 | ]; |
| 133 | |
Serge Bazanski | 5ac5e4b | 2022-07-06 00:31:35 +0200 | [diff] [blame] | 134 | "larrythebuilder.q3k.org" = mkMachine self pkgsArm [ |
| 135 | ../hswaw/machines/larrythebuilder.q3k.org/configuration.nix |
| 136 | ]; |
| 137 | |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 138 | "customs.hackerspace.pl" = mkMachine self pkgs [ |
| 139 | ../hswaw/machines/customs.hackerspace.pl/configuration.nix |
| 140 | ]; |
Serge Bazanski | 5ac5e4b | 2022-07-06 00:31:35 +0200 | [diff] [blame] | 141 | "tv1.waw.hackerspace.pl" = mkMachine self pkgsArm [ |
Serge Bazanski | dcdbd84 | 2022-07-07 02:30:09 +0200 | [diff] [blame] | 142 | ../hswaw/machines/tv/tv1.nix |
| 143 | ]; |
| 144 | "tv2.waw.hackerspace.pl" = mkMachine self pkgsArm [ |
| 145 | ../hswaw/machines/tv/tv2.nix |
Serge Bazanski | 5ac5e4b | 2022-07-06 00:31:35 +0200 | [diff] [blame] | 146 | ]; |
Serge Bazanski | 55a486a | 2022-06-11 18:27:01 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | in pkgs.lib.fix machines |