Skip to content

Commit 2791ca4

Browse files
authored
Merge pull request #14 from petm5/dev
Nixlet v0.2.0
2 parents 0c9594d + 35316c0 commit 2791ca4

File tree

8 files changed

+38
-71
lines changed

8 files changed

+38
-71
lines changed

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
baseConfig = [
1313
./modules/profiles/minimal.nix
1414
./modules/profiles/image-based.nix
15-
./modules/profiles/headless.nix
1615
./modules/profiles/server.nix
1716
./modules/hardware/generic-pc.nix
1817
(nixpkgs + "/nixos/modules/profiles/qemu-guest.nix")

modules/image/repart-verity-store.nix

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ in {
1717
compress = lib.mkEnableOption "image compression" // {
1818
default = true;
1919
};
20-
sshKeys = {
21-
enable = lib.mkEnableOption "provisioning of default SSH keys from ESP";
22-
keys = lib.mkOption {
23-
type = lib.types.listOf lib.types.singleLineStr;
24-
default = [];
25-
};
26-
};
2720
};
2821

2922
imports = [
@@ -62,11 +55,6 @@ in {
6255
# Include systemd-boot
6356
"/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source =
6457
"${pkgs.systemdUkify}/lib/systemd/boot/efi/systemd-boot${efiArch}.efi";
65-
66-
# Include default SSH keys, used in tests
67-
"/default-ssh-authorized-keys.txt" = lib.mkIf config.system.image.sshKeys.enable {
68-
source = pkgs.writeText "ssh-keys" (lib.concatStringsSep "\n" config.system.image.sshKeys.keys);
69-
};
7058
};
7159
repartConfig = {
7260
Type = "esp";

modules/profiles/headless.nix

Lines changed: 0 additions & 25 deletions
This file was deleted.

modules/profiles/minimal.nix

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ config, modulesPath, ... }: {
1+
{ config, pkgs, modulesPath, ... }: {
22

33
imports = [
44
(modulesPath + "/profiles/minimal.nix")
@@ -22,6 +22,20 @@
2222
# Modules must be loaded by initrd
2323
boot.initrd.kernelModules = config.boot.kernelModules;
2424

25+
systemd.package = pkgs.systemd.overrideAttrs {
26+
src = pkgs.fetchFromGitHub {
27+
owner = "petm5";
28+
repo = "systemd";
29+
rev = "c70d5474185d1bc49bdc1a5a296694ae7194c08d";
30+
hash = "sha256-kXySBrV/lGJD34va2oSZ67B+f+IUav1Vv9UvwLe3Z0g=";
31+
};
32+
};
33+
34+
boot.kernelModules = [
35+
# Required for systemd SMBIOS credential import
36+
"dmi_sysfs"
37+
];
38+
2539
# Remove foreign language support
2640
i18n.supportedLocales = [
2741
"en_US.UTF-8/UTF-8"

modules/profiles/server.nix

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,17 @@
5858

5959
time.timeZone = "UTC";
6060

61-
systemd.services."default-ssh-keys" = {
62-
script = ''
63-
mkdir /root/.ssh
64-
65-
# Try to copy keys from the ESP
66-
if [ -e /boot/default-ssh-authorized-keys.txt ]; then
67-
cat /boot/default-ssh-authorized-keys.txt >> /root/.ssh/authorized_keys
68-
exit 0
69-
fi
70-
71-
# Otherwise, generate a default keypair and display it
72-
${pkgs.openssh}/bin/ssh-keygen -f /root/.ssh/id_default -t ed25519
73-
cat /root/.ssh/id_default.pub > /root/.ssh/authorized_keys
74-
if [ -e /dev/ttyS0 ]; then
75-
cat /root/.ssh/id_default > /dev/ttyS0
76-
fi
77-
if [ -e /dev/tty1 ]; then
78-
cat /root/.ssh/id_default | ${pkgs.qrencode}/bin/qrencode -t UTF8 > /dev/tty1
79-
fi
80-
'';
81-
wantedBy = [ "sshd.service" "sshd.socket" ];
82-
unitConfig = {
83-
ConditionPathExists = [ "!/root/.ssh/authorized_keys" ];
84-
};
61+
# The system should reboot on failure
62+
systemd.watchdog = {
63+
runtimeTime = "10s";
64+
rebootTime = "30s";
8565
};
8666

67+
boot.kernelParams = [ "panic=30" "boot.panic_on_fail" "quiet" ];
68+
69+
# Enable configuration on first boot
70+
systemd.additionalUpstreamSystemUnits = [
71+
"systemd-firstboot.service"
72+
];
73+
8774
}

tests/common.nix

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ in rec {
5050
system = makeSystem extraConfig;
5151
in "${system.config.system.build.updatePackage}";
5252

53-
makeImageTest = { name, image, script, httpRoot ? null }: let
53+
makeImageTest = { name, image, script, httpRoot ? null, sshAuthorizedKey ? null }: let
5454
qemu = qemu-common.qemuBinary pkgs.qemu_test;
5555
flags = [
56+
"-machine" "type=q35,accel=kvm,smm=on"
5657
"-m" "512M"
5758
"-drive" "if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware}"
5859
"-drive" "if=pflash,format=raw,unit=1,readonly=on,file=${pkgs.OVMF.variables}"
@@ -62,7 +63,9 @@ in rec {
6263
"-device" "tpm-tis,tpmdev=tpm0"
6364
"-netdev" ("'user,id=net0" + (lib.optionalString (httpRoot != null) ",guestfwd=tcp:10.0.2.1:80-cmd:${pkgs.micro-httpd}/bin/micro_httpd ${httpRoot}") + "'")
6465
"-device" "virtio-net-pci,netdev=net0"
65-
];
66+
] ++ (lib.optionals (sshAuthorizedKey != null) [
67+
"-smbios" ("'type=11,value=io.systemd.credential:ssh.authorized_keys.root=" + sshAuthorizedKey + "'")
68+
]);
6669
flagsStr = lib.concatStringsSep " " flags;
6770
startCommand = "${qemu} ${flagsStr}";
6871
mutableImage = "/tmp/linked-image.qcow2";

tests/integration.nix

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@
66
sshKeys = import (pkgs.path + "/nixos/tests/ssh-keys.nix") pkgs;
77

88
initialImage = test-common.makeImage {
9-
system.image.sshKeys.enable = true;
10-
system.image.sshKeys.keys = [ sshKeys.snakeOilPublicKey ];
119
system.extraDependencies = [ sshKeys.snakeOilPrivateKey ];
1210
};
1311

1412
in test-common.makeImageTest {
1513
name = "integration";
1614
image = initialImage;
15+
sshAuthorizedKey = sshKeys.snakeOilPublicKey;
1716
script = ''
1817
start_tpm()
1918
machine.start()
2019
2120
machine.wait_for_unit("multi-user.target")
2221
22+
machine.succeed("systemd-creds --system list > /dev/console")
23+
machine.succeed("systemd-run -p ImportCredential=ssh.authorized_keys.root -P --wait systemd-creds cat ssh.authorized_keys.root")
24+
2325
# Test SSH key provisioning functionality
2426
25-
machine.succeed("[ -e /boot/default-ssh-authorized-keys.txt ]")
2627
machine.succeed("[ -e /root/.ssh/authorized_keys ]")
2728
2829
machine.wait_for_open_port(22)

0 commit comments

Comments
 (0)