Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempts to add a disko test. #4

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Collection of system configs for my machines.
- [x] Build `test` VM in GHA
- [x] Set up renovate on repo
- [ ] Clean up `hello.nix`
- [x] Add container to `hello.nix`
- [ ] See if disko works with tests
- [ ] Base install on nas

[nix_vm_gist]: https://gist.github.com/FlakM/0535b8aa7efec56906c5ab5e32580adf
7 changes: 7 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
system = "${system}";
config.allowUnfree = true;
};
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix");
lib = pkgs.lib;
diskoLib = import (disko + "/lib") {inherit lib makeTest eval-config;};
in {
formatter.${system} = alejandra.defaultPackage.${system};
devShell."${system}" = import ./shell.nix {inherit pkgs;};
Expand All @@ -38,6 +42,9 @@

checks.${system} = {
hello = pkgs.testers.runNixOSTest ./tests/hello.nix;
# silver = disko.lib.testLib.makeDiskoTest (import ./tests/silver.nix);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually works with nix flake check --impure.

# silverAlt = diskoLib.testLib.makeDiskoTest (import ./tests/silver.nix);
silverAlt = diskoLib.testLib.makeDiskoTest ((import ./tests/silver.nix) // {inherit pkgs;});
k3s-multi-node = pkgs.testers.runNixOSTest ./tests/k3s-multi-node.nix;
};
};
Expand Down
105 changes: 105 additions & 0 deletions machines/silver/disko.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
disko.devices = {
disk = {
x = {
type = "disk";
device = "/dev/sdx";
content = {
type = "gpt";
partitions = {
ESP = {
size = "64M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = ["umask=0077"];
};
};
zfs = {
size = "100%";
content = {
type = "zfs";
pool = "zroot";
};
};
};
};
};
y = {
type = "disk";
device = "/dev/sdy";
content = {
type = "gpt";
partitions = {
zfs = {
size = "100%";
content = {
type = "zfs";
pool = "zroot";
};
};
};
};
};
};
zpool = {
zroot = {
type = "zpool";
mode = "mirror";
# Workaround: cannot import 'zroot': I/O error in disko tests
options.cachefile = "none";
rootFsOptions = {
compression = "zstd";
"com.sun:auto-snapshot" = "false";
};
mountpoint = "/";
postCreateHook = "zfs list -t snapshot -H -o name | grep -E '^zroot@blank$' || zfs snapshot zroot@blank";

datasets = {
zfs_fs = {
type = "zfs_fs";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
};
zfs_unmounted_fs = {
type = "zfs_fs";
options.mountpoint = "none";
};
zfs_legacy_fs = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/zfs_legacy_fs";
};
zfs_testvolume = {
type = "zfs_volume";
size = "10M";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4onzfs";
};
};
encrypted = {
type = "zfs_fs";
options = {
mountpoint = "none";
encryption = "aes-256-gcm";
keyformat = "passphrase";
keylocation = "file:///tmp/secret.key";
};
# use this to read the key during boot
# postCreateHook = ''
# zfs set keylocation="prompt" "zroot/$name";
# '';
};
"encrypted/test" = {
type = "zfs_fs";
mountpoint = "/zfs_crypted";
};
};
};
};
};
}
34 changes: 34 additions & 0 deletions tests/silver.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
name = "silver";
disko-config = ../machines/silver/disko.nix;
extraInstallerConfig.networking.hostId = "8425e349";
extraSystemConfig = {
networking.hostId = "8425e349";
fileSystems."/zfs_legacy_fs".options = ["nofail"]; # TODO find out why we need this!
};
extraTestScript = ''
machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume");

def assert_property(ds, property, expected_value):
out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip()
assert (
out == expected_value
), f"Expected {property}={expected_value} on {ds}, got: {out}"

assert_property("zroot", "compression", "zstd")
assert_property("zroot/zfs_fs", "compression", "zstd")
assert_property("zroot", "com.sun:auto-snapshot", "false")
assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true")
assert_property("zroot/zfs_testvolume", "volsize", "10M")
assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none")

machine.succeed("zfs get name zroot@blank")

machine.succeed("mountpoint /zfs_fs");
machine.succeed("mountpoint /zfs_legacy_fs");
machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /zfs_crypted");
machine.succeed("zfs get keystatus zroot/encrypted");
machine.succeed("zfs get keystatus zroot/encrypted/test");
'';
}