103: flake.lock: Update r=Mic92 a=Mic92



Co-authored-by: Jörg Thalheim <joerg@thalheim.io>
This commit is contained in:
bors[bot] 2023-05-15 11:43:51 +00:00 committed by GitHub
commit 3758c6481c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 151 additions and 128 deletions

View file

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixos-2211": { "nixos-2211": {
"locked": { "locked": {
"lastModified": 1681932375, "lastModified": 1684141842,
"narHash": "sha256-tSXbYmpnKSSWpzOrs27ie8X3I0yqKA6AuCzCYNtwbCU=", "narHash": "sha256-sbdzOwBDcyzz/Dr1ztdF+tElMyM/cgx+4XxVgz+NLRM=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "3d302c67ab8647327dba84fbdb443cdbf0e82744", "rev": "2eb0795720849ae19c068e39b17362d3ebcd585c",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -18,11 +18,11 @@
}, },
"nixos-unstable": { "nixos-unstable": {
"locked": { "locked": {
"lastModified": 1681914506, "lastModified": 1684106623,
"narHash": "sha256-frb95rhVUKAeRdHKfD2vbO1kv8U+G9JMAoLHLCRPNa4=", "narHash": "sha256-Fxw/lWpx+Cr1sJQ+1msdPBnrRuO0ll1eT48+ym0oqDg=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "cafa2f02fbbcade5c5c257c190061da555d90913", "rev": "8fb30f6066a87a91c21241f1993a26ff57005486",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -40,14 +40,18 @@
checks.x86_64-linux = let checks.x86_64-linux = let
pkgs = nixos-unstable.legacyPackages.x86_64-linux; pkgs = nixos-unstable.legacyPackages.x86_64-linux;
in { in {
kexec-installer-unstable = pkgs.callPackage ./nix/kexec-installer/test.nix {}; kexec-installer-unstable = pkgs.callPackage ./nix/kexec-installer/test.nix {
kexecTarball = self.packages.x86_64-linux.kexec-installer-nixos-unstable-noninteractive;
};
shellcheck = pkgs.runCommand "shellcheck" { shellcheck = pkgs.runCommand "shellcheck" {
nativeBuildInputs = [ pkgs.shellcheck ]; nativeBuildInputs = [ pkgs.shellcheck ];
} '' } ''
shellcheck ${(pkgs.nixos [self.nixosModules.kexec-installer]).config.system.build.kexecRun} shellcheck ${(pkgs.nixos [self.nixosModules.kexec-installer]).config.system.build.kexecRun}
touch $out touch $out
''; '';
kexec-installer-2211 = nixos-2211.legacyPackages.x86_64-linux.callPackage ./nix/kexec-installer/test.nix {}; kexec-installer-2211 = nixos-2211.legacyPackages.x86_64-linux.callPackage ./nix/kexec-installer/test.nix {
kexecTarball = self.packages.x86_64-linux.kexec-installer-nixos-2211-noninteractive;
};
}; };
}; };
} }

View file

@ -53,9 +53,13 @@ done
find . | cpio -o -H newc | gzip -9 >> "$SCRIPT_DIR/initrd" find . | cpio -o -H newc | gzip -9 >> "$SCRIPT_DIR/initrd"
# Dropped --kexec-syscall-auto because it broke on GCP... # Dropped --kexec-syscall-auto because it broke on GCP...
"$SCRIPT_DIR/kexec" --load "$SCRIPT_DIR/bzImage" \ if ! "$SCRIPT_DIR/kexec" --load "$SCRIPT_DIR/bzImage" \
--initrd="$SCRIPT_DIR/initrd" --no-checks \ --initrd="$SCRIPT_DIR/initrd" --no-checks \
--command-line "init=$init $kernelParams" --command-line "init=$init $kernelParams"; then
echo "kexec failed, dumping dmesg"
dmesg | tail -n 100
exit 1
fi
# Disconnect our background kexec from the terminal # Disconnect our background kexec from the terminal
echo "machine will boot into nixos in in 6s..." echo "machine will boot into nixos in in 6s..."

View file

@ -24,6 +24,9 @@ in {
# We are stateless, so just default to latest. # We are stateless, so just default to latest.
system.stateVersion = config.system.nixos.version; system.stateVersion = config.system.nixos.version;
# use latest kernel we can support to get more hardware support
boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;
# This is a variant of the upstream kexecScript that also allows embedding # This is a variant of the upstream kexecScript that also allows embedding
# a ssh key. # a ssh key.
system.build.kexecRun = pkgs.runCommand "kexec-run" {} '' system.build.kexecRun = pkgs.runCommand "kexec-run" {} ''
@ -44,6 +47,10 @@ in {
cp "${config.system.build.kexecRun}" kexec/run cp "${config.system.build.kexecRun}" kexec/run
cp "${pkgs.pkgsStatic.kexec-tools}/bin/kexec" kexec/kexec cp "${pkgs.pkgsStatic.kexec-tools}/bin/kexec" kexec/kexec
cp "${iprouteStatic}/bin/ip" kexec/ip cp "${iprouteStatic}/bin/ip" kexec/ip
${lib.optionalString (pkgs.hostPlatform == pkgs.buildPlatform) ''
kexec/ip -V
kexec/kexec --version
''}
tar -czvf $out/${config.system.kexec-installer.name}-${pkgs.stdenv.hostPlatform.system}.tar.gz kexec tar -czvf $out/${config.system.kexec-installer.name}-${pkgs.stdenv.hostPlatform.system}.tar.gz kexec
''; '';

View file

@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACA8wk9uIqPk7FZFhRs0ZQ4Q/b0Rd//Rpq2i9e3v33+WwgAAAJjeXdO33l3T
twAAAAtzc2gtZWQyNTUxOQAAACA8wk9uIqPk7FZFhRs0ZQ4Q/b0Rd//Rpq2i9e3v33+Wwg
AAAEBiNUp5mUe87gWrXbjd36dqt/6waDLdoYV1woR8in4ehDzCT24io+TsVkWFGzRlDhD9
vRF3/9GmraL17e/ff5bCAAAAE2pvZXJnQHR1cmluZ21hY2hpbmUBAg==
-----END OPENSSH PRIVATE KEY-----

View file

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDzCT24io+TsVkWFGzRlDhD9vRF3/9GmraL17e/ff5bC joerg@turingmachine

View file

@ -1,4 +1,6 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs
, kexecTarball
}:
let let
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix"); makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
@ -6,8 +8,8 @@ let
inherit pkgs; inherit pkgs;
inherit (pkgs) system; inherit (pkgs) system;
}; };
in
in makeTest' { makeTest' {
name = "kexec-installer"; name = "kexec-installer";
meta = with pkgs.lib.maintainers; { meta = with pkgs.lib.maintainers; {
maintainers = [ mic92 ]; maintainers = [ mic92 ];
@ -15,18 +17,20 @@ in makeTest' {
nodes = { nodes = {
node1 = { modulesPath, ... }: { node1 = { modulesPath, ... }: {
virtualisation.vlans = [ 1 ]; virtualisation.vlans = [ ];
environment.noXlibs = false; # avoid recompilation environment.noXlibs = false; # avoid recompilation
imports = [ imports = [
(modulesPath + "/profiles/minimal.nix") (modulesPath + "/profiles/minimal.nix")
]; ];
virtualisation.memorySize = 1024 + 512; system.extraDependencies = [ kexecTarball ];
virtualisation.memorySize = 1 * 1024 + 512;
virtualisation.diskSize = 4 * 1024; virtualisation.diskSize = 4 * 1024;
virtualisation.useBootLoader = true; virtualisation.forwardPorts = [{
virtualisation.useEFIBoot = true; host.port = 2222;
boot.loader.systemd-boot.enable = true; guest.port = 22;
boot.loader.efi.canTouchEfiVariables = true; }];
services.openssh.enable = true; services.openssh.enable = true;
networking = { networking = {
@ -34,6 +38,8 @@ in makeTest' {
useDHCP = false; useDHCP = false;
}; };
users.users.root.openssh.authorizedKeys.keyFiles = [ ./ssh-keys/id_ed25519.pub ];
systemd.network = { systemd.network = {
networks = { networks = {
# systemd-networkd will load the first network unit file # systemd-networkd will load the first network unit file
@ -41,12 +47,12 @@ in makeTest' {
# /etc/systemd/network/{40-eth1,99-main}.network already # /etc/systemd/network/{40-eth1,99-main}.network already
# exists. This network unit must be loaded for the test, # exists. This network unit must be loaded for the test,
# however, hence why this network is named such. # however, hence why this network is named such.
"01-eth1" = {
name = "eth1"; "01-eth0" = {
name = "eth0";
address = [ address = [
# Some static addresses that we want to see in the kexeced image # Some static addresses that we want to see in the kexeced image
"192.168.42.1/24" "192.168.42.1/24" "42::1/64"
"42::1/64"
]; ];
routes = [ routes = [
# Some static routes that we want to see in the kexeced image # Some static routes that we want to see in the kexeced image
@ -55,138 +61,129 @@ in makeTest' {
{ routeConfig = { Destination = "43::0/64"; }; } { routeConfig = { Destination = "43::0/64"; }; }
{ routeConfig = { Destination = "44::1/64"; Gateway = "43::1"; }; } { routeConfig = { Destination = "44::1/64"; Gateway = "43::1"; }; }
]; ];
networkConfig = { networkConfig = { DHCP = "yes"; IPv6AcceptRA = true; };
DHCP = "yes";
IPv6AcceptRA = true;
};
}; };
}; };
}; };
}; };
node2 = { pkgs, modulesPath, ... }: {
environment.systemPackages = [ pkgs.hello ];
imports = [
./module.nix
../noninteractive.nix
];
};
router = { config, pkgs, ... }: {
virtualisation.vlans = [ 1 ];
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
};
systemd.network = {
networks = {
# systemd-networkd will load the first network unit file
# that matches, ordered lexiographically by filename.
# /etc/systemd/network/{40-eth1,99-main}.network already
# exists. This network unit must be loaded for the test,
# however, hence why this network is named such.
"01-eth1" = {
name = "eth1";
address = [
"2001:db8::1/64"
];
ipv6Prefixes = [
{ ipv6PrefixConfig = { Prefix = "2001:db8::/64"; AddressAutoconfiguration = true; OnLink = true; }; }
];
# does not work in 22.11
#ipv6RoutePrefixes = [ { ipv6RoutePrefixConfig = { Route = "::/0"; LifetimeSec = 3600; }; }];
extraConfig = ''
[IPv6RoutePrefix]
Route = ::/0
LifetimeSec = 3600
'';
networkConfig = {
DHCPServer = true;
Address = "10.0.0.1/24";
IPv6SendRA = true;
};
dhcpServerConfig = {
PoolOffset = 100;
PoolSize = 1;
EmitRouter = true;
};
};
};
};
};
}; };
testScript = { nodes, ... }: '' testScript = ''
# Test whether reboot via kexec works. import time
import subprocess
import socket
import http.server
from threading import Thread
from typing import Optional
router.wait_for_unit("network-online.target") start_all()
router.succeed("ip addr >&2")
router.succeed("ip route >&2") class DualStackServer(http.server.HTTPServer):
router.succeed("ip -6 route >&2") def server_bind(self):
router.succeed("networkctl status eth1 >&2") self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
return super().server_bind()
DualStackServer.address_family = socket.AF_INET6
httpd = DualStackServer(("::", 0), http.server.SimpleHTTPRequestHandler)
http.server.HTTPServer.address_family = socket.AF_INET6
port = httpd.server_port
def serve_forever(httpd):
with httpd:
httpd.serve_forever()
thread = Thread(target=serve_forever, args=(httpd, ))
thread.setDaemon(True)
thread.start()
node1.wait_until_succeeds(f"curl -v -I http://10.0.2.2:{port}")
node1.wait_until_succeeds(f"curl -v -I http://[fec0::2]:{port}")
node1.wait_until_succeeds("ping -c1 10.0.0.1")
node1.wait_until_succeeds("ping -c1 2001:db8::1")
node1.succeed("ip addr >&2") node1.succeed("ip addr >&2")
node1.succeed("ip route >&2") node1.succeed("ip route >&2")
node1.succeed("ip -6 route >&2") node1.succeed("ip -6 route >&2")
node1.succeed("networkctl status eth1 >&2") node1.succeed("networkctl status eth0 >&2")
host_ed25519_before = node1.succeed("cat /etc/ssh/ssh_host_ed25519_key.pub") def ssh(cmd: list[str], check: bool = True, stdout: Optional[int] = None) -> subprocess.CompletedProcess:
ssh_cmd = [
"${pkgs.openssh}/bin/ssh",
"-o", "StrictHostKeyChecking=no",
"-o", "ConnectTimeout=1",
"-i", "${./ssh-keys/id_ed25519}",
"-p", "2222",
"root@127.0.0.1",
"--"
] + cmd
print(" ".join(ssh_cmd))
return subprocess.run(ssh_cmd,
text=True,
check=check,
stdout=stdout)
while not ssh(["true"], check=False).returncode == 0:
time.sleep(1)
ssh(["cp", "--version"])
host_ed25519_before = node1.succeed("cat /etc/ssh/ssh_host_ed25519_key.pub").strip()
node1.succeed('ssh-keygen -t ed25519 -f /root/.ssh/id_ed25519 -q -N ""') node1.succeed('ssh-keygen -t ed25519 -f /root/.ssh/id_ed25519 -q -N ""')
root_ed25519_before = node1.succeed('tee /root/.ssh/authorized_keys < /root/.ssh/id_ed25519.pub') root_ed25519_before = node1.succeed('tee /root/.ssh/authorized_keys < /root/.ssh/id_ed25519.pub').strip()
# Kexec node1 to the toplevel of node2 via the kexec-boot script # Kexec node1 to the toplevel of node2 via the kexec-boot script
node1.succeed('touch /run/foo') node1.succeed('touch /run/foo')
node1.fail('hello') node1.fail('parted --version >&2')
node1.succeed('tar -xf ${nodes.node2.system.build.kexecTarball}/nixos-kexec-installer-${pkgs.system}.tar.gz -C /root') node1.succeed('tar -xf ${kexecTarball}/nixos-kexec-installer-noninteractive-${pkgs.system}.tar.gz -C /root')
node1.execute('/root/kexec/run') node1.succeed('/root/kexec/ip -V >&2')
# wait for machine to kexec node1.succeed('/root/kexec/kexec --version >&2')
node1.execute('sleep 9999', check_return=False) node1.succeed('/root/kexec/run >&2')
node1.succeed('! test -e /run/foo')
node1.succeed('hello')
node1.succeed('[ "$(hostname)" = "node2" ]')
node1.wait_for_unit("sshd.service")
host_ed25519_after = node1.succeed("cat /etc/ssh/ssh_host_ed25519_key.pub") # wait for kexec to finish
assert host_ed25519_before == host_ed25519_after, f"{host_ed25519_before} != {host_ed25519_after}" while ssh(["true"], check=False).returncode == 0:
print("Waiting for kexec to finish...")
time.sleep(1)
root_ed25519_after = node1.succeed("cat /root/.ssh/authorized_keys") while ssh(["true"], check=False).returncode != 0:
assert root_ed25519_before == root_ed25519_after, f"{root_ed25519_before} != {root_ed25519_after}" print("Waiting for node2 to come up...")
time.sleep(1)
# See if we can reach the router after kexec print(ssh(["ip", "addr"]))
node1.wait_for_unit("restore-network.service") print(ssh(["ip", "route"]))
node1.wait_until_succeeds("cat /etc/systemd/network/eth1.network >&2") print(ssh(["ip", "-6", "route"]))
node1.wait_until_succeeds("ping -c1 10.0.0.1") print(ssh(["networkctl", "status"]))
node1.wait_until_succeeds("ping -c1 2001:db8::1")
# Check if static addresses have been restored assert ssh(["ls", "-la", "/run/foo"], check=False).returncode != 0, "kexeced node1 still has /run/foo"
node1.wait_until_succeeds("ping -c1 42::1") print(ssh(["parted", "--version"]))
node1.wait_until_succeeds("ping -c1 192.168.42.1") host = ssh(["hostname"], stdout=subprocess.PIPE).stdout.strip()
assert host == "nixos", f"hostname is {host}, not nixos"
out = node1.wait_until_succeeds("ip route get 192.168.43.2") host_ed25519_after = ssh(["cat", "/etc/ssh/ssh_host_ed25519_key.pub"], stdout=subprocess.PIPE).stdout.strip()
assert host_ed25519_before == host_ed25519_after, f"'{host_ed25519_before}' != '{host_ed25519_after}'"
root_ed25519_after = ssh(["cat", "/root/.ssh/authorized_keys"], stdout=subprocess.PIPE).stdout.strip()
assert root_ed25519_before in root_ed25519_after, f"'{root_ed25519_before}' not included in '{root_ed25519_after}'"
print(ssh(["cat", "/etc/systemd/network/eth0.network"]))
ssh(["curl", "-v", "-I", f"http://10.0.2.2:{port}"])
ssh(["curl", "-v", "-I", f"http://[fec0::2]:{port}"])
## Check if static addresses have been restored
ssh(["ping", "-c1", "42::1"])
ssh(["ping", "-c1", "192.168.42.1"])
out = ssh(["ip", "route", "get", "192.168.43.2"], stdout=subprocess.PIPE).stdout
print(out) print(out)
assert "192.168.43.2 dev eth1" in out assert "192.168.43.2 dev" in out, f"route to `192.168.43.2 dev` not found: {out}"
out = node1.wait_until_succeeds("ip route get 192.168.44.2") out = ssh(["ip", "route", "get", "192.168.44.2"], stdout=subprocess.PIPE).stdout
print(out) print(out)
assert "192.168.44.2 via 192.168.43.1" in out assert "192.168.44.2 via 192.168.43.1" in out, f"route to `192.168.44.2 via 192.168.43.1` not found: {out}"
out = node1.wait_until_succeeds("ip route get 43::2") out = ssh(["ip", "route", "get", "43::2"], stdout=subprocess.PIPE).stdout
print(out) print(out)
assert "43::2 from :: dev eth1" in out assert "43::2 from :: dev" in out, f"route `43::2 from dev` not found: {out}"
out = node1.wait_until_succeeds("ip route get 44::2") out = ssh(["ip", "route", "get", "44::2"], stdout=subprocess.PIPE).stdout
print(out) print(out)
assert "44::2 from :: via 43::1" in out assert "44::2 from :: via 43::1" in out, f"route to `44::2 from :: via 43::1` not found: {out}"
node1.succeed("ip addr >&2") node1.crash()
node1.succeed("ip route >&2")
node1.succeed("ip -6 route >&2")
node1.succeed("networkctl status eth1 >&2")
node1.shutdown()
''; '';
} }

View file

@ -18,7 +18,10 @@
programs.nano.syntaxHighlight = lib.mkForce false; programs.nano.syntaxHighlight = lib.mkForce false;
# prevents nano, strace # prevents nano, strace
environment.defaultPackages = lib.mkForce [ pkgs.rsync ]; environment.defaultPackages = lib.mkForce [
pkgs.rsync
pkgs.parted
];
# zfs support is accidentally disabled by excluding base.nix, re-enable it # zfs support is accidentally disabled by excluding base.nix, re-enable it
boot = { boot = {