diff --git a/README.md b/README.md index 7af85bb..ff1c3a9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/flake.nix b/flake.nix index 180907f..dda0c34 100644 --- a/flake.nix +++ b/flake.nix @@ -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;}; @@ -38,6 +42,9 @@ checks.${system} = { hello = pkgs.testers.runNixOSTest ./tests/hello.nix; + # silver = disko.lib.testLib.makeDiskoTest (import ./tests/silver.nix); + # 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; }; }; diff --git a/machines/silver/disko.nix b/machines/silver/disko.nix new file mode 100644 index 0000000..0550726 --- /dev/null +++ b/machines/silver/disko.nix @@ -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"; + }; + }; + }; + }; + }; +} diff --git a/tests/silver.nix b/tests/silver.nix new file mode 100644 index 0000000..8a13a8a --- /dev/null +++ b/tests/silver.nix @@ -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"); + ''; +}