blob: 208279ec213369c92108e1f691b941b3925ee9d5 [file] [log] [blame]
Serge Bazanski6abe4fa2020-10-03 00:18:34 +02001# 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 Bazanskib3c67702021-09-10 22:27:24 +00006# For information about building/deploying machines see //ops/README.md.
Serge Bazanski6abe4fa2020-10-03 00:18:34 +02007
8{ hscloud, pkgs, ... }:
9
10let
Serge Bazanskib3c67702021-09-10 22:27:24 +000011 # 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 Bazanski9848e7e2021-09-10 22:30:56 +000022 }) {
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 Bazanskib3c67702021-09-10 22:27:24 +000044
45 # edge01 still lives on an old nixpkgs checkout.
46 #
47 # TODO(b/3): unpin and deploy.
48 nixpkgsBgpwtf = import (pkgs.fetchFromGitHub {
49 owner = "nixos";
50 repo = "nixpkgs-channels";
51 rev = "c59ea8b8a0e7f927e7291c14ea6cd1bd3a16ff38";
52 sha256 = "1ak7jqx94fjhc68xh1lh35kh3w3ndbadprrb762qgvcfb8351x8v";
53 }) {};
54
Piotr Dobrowolskia01905a2021-10-16 18:22:46 +020055 # customs.hackerspace.pl migration temporary checkout
56 nixpkgsCustoms = import (pkgs.fetchFromGitHub {
57 owner = "nixos";
58 repo = "nixpkgs";
59 rev = "d12178b1c4a6ef1232c8c677573ba9db204e66ff";
60 sha256 = "0p7df7yzi35kblxr5ks0rxxp9cfh269g88xpj60sdhdjvfnn6cp7";
61 }) {};
62
Serge Bazanskia16af2d2021-10-16 19:14:05 +000063 # mkMachine builds NixOS modules into a NixOS derivation.
64 # It:
65 # 1) injects passthru.hscloud.provision which deploys that configuration
66 # over SSH to a production machine.
67 # 2) injects 'workspace' as a nixos module argument which points to the root
68 # of the hscloud readTree object. It will contain whatever nixpkgs
69 # checkout this file has been invoked with, ie. will not be 'mixed in'
70 # with the pkgs argument.
Serge Bazanski55a486a2022-06-11 18:27:01 +000071 mkMachine = machines: pkgs: paths: pkgs.nixos ({ config, pkgs, ... }: {
Serge Bazanski6abe4fa2020-10-03 00:18:34 +020072 imports = paths;
Serge Bazanskib3c67702021-09-10 22:27:24 +000073
74 config = let
75 name = config.networking.hostName;
76 domain = if (config.networking ? domain) && config.networking.domain != null then config.networking.domain else "hswaw.net";
77 fqdn = name + "." + domain;
78 toplevel = config.system.build.toplevel;
79
80 runProvision = ''
81 #!/bin/sh
82 set -eu
83 remote=root@${fqdn}
84 echo "Configuration for ${fqdn} is ${toplevel}"
85 nix copy -s --to ssh://$remote ${toplevel}
86
87 running="$(ssh $remote readlink -f /nix/var/nix/profiles/system)"
88 if [ "$running" == "${toplevel}" ]; then
89 echo "${fqdn} already running ${toplevel}."
90 else
91 echo "/etc/systemd/system diff:"
92 ssh $remote diff -ur /var/run/current-system/etc/systemd/system ${toplevel}/etc/systemd/system || true
93 echo ""
94 echo ""
95 echo "dry-activate diff:"
96 ssh $remote ${toplevel}/bin/switch-to-configuration dry-activate
97 read -p "Do you want to switch to this configuration? " -n 1 -r
98 echo
99 if ! [[ $REPLY =~ ^[Yy]$ ]]; then
100 exit 1
101 fi
102
103 echo -ne "\n\nswitch-to-configuration test...\n"
104 ssh $remote ${toplevel}/bin/switch-to-configuration test
105 fi
106
107 echo -ne "\n\n"
108 read -p "Do you want to set this configuration as boot? " -n 1 -r
109 echo
110 if ! [[ $REPLY =~ ^[Yy]$ ]]; then
111 exit 1
112 fi
113
114 echo -ne "\n\nsetting system profile...\n"
115 ssh $remote nix-env -p /nix/var/nix/profiles/system --set ${toplevel}
116
117 echo -ne "\n\nswitch-to-configuration boot...\n"
118 ssh $remote ${toplevel}/bin/switch-to-configuration boot
119 '';
120 in {
121 passthru.hscloud.provision = pkgs.writeScript "provision-${fqdn}" runProvision;
Serge Bazanskia16af2d2021-10-16 19:14:05 +0000122
123 # TODO(q3k): this should be named hscloud, but that seems to not work. Debug and rename.
124 _module.args.workspace = hscloud;
Serge Bazanski55a486a2022-06-11 18:27:01 +0000125 _module.args.machines = machines;
Serge Bazanskib3c67702021-09-10 22:27:24 +0000126 };
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200127 });
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200128
Serge Bazanski55a486a2022-06-11 18:27:01 +0000129 mkClusterMachine = machines: path: mkMachine machines nixpkgsCluster [
130 ../cluster/machines/modules/base.nix
131 ../cluster/machines/modules/kube-controlplane.nix
132 ../cluster/machines/modules/kube-dataplane.nix
133 ../cluster/machines/modules/ceph.nix
134 path
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200135 ];
Piotr Dobrowolskia01905a2021-10-16 18:22:46 +0200136
Serge Bazanski55a486a2022-06-11 18:27:01 +0000137 machines = self: {
138 "bc01n01.hswaw.net" = mkClusterMachine self ../cluster/machines/bc01n01.hswaw.net.nix;
139 "bc01n02.hswaw.net" = mkClusterMachine self ../cluster/machines/bc01n02.hswaw.net.nix;
140 "dcr01s22.hswaw.net" = mkClusterMachine self ../cluster/machines/dcr01s22.hswaw.net.nix;
141 "dcr01s24.hswaw.net" = mkClusterMachine self ../cluster/machines/dcr01s24.hswaw.net.nix;
142
143 "edge01.waw.bgp.wtf" = mkMachine self nixpkgsBgpwtf [
144 ../bgpwtf/machines/edge01.waw.bgp.wtf.nix
145 ../bgpwtf/machines/edge01.waw.bgp.wtf-hardware.nix
146 ];
147
148 "customs.hackerspace.pl" = mkMachine self pkgs [
149 ../hswaw/machines/customs.hackerspace.pl/configuration.nix
150 ];
151 };
152
153in pkgs.lib.fix machines