From 6277e8ed99f7c9a8a487d8babe12125448ff3d50 Mon Sep 17 00:00:00 2001 From: Dave Conroy <23528985+tiredofit@users.noreply.github.com> Date: Wed, 26 Jul 2023 18:02:33 -0700 Subject: [PATCH 1/2] Create luks-btrfs-subvolumes.nix Add example for BTRFS Subvolumes inside a LUKS container --- example/luks-btrfs-subvolumes.nix | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 example/luks-btrfs-subvolumes.nix diff --git a/example/luks-btrfs-subvolumes.nix b/example/luks-btrfs-subvolumes.nix new file mode 100644 index 0000000..9368ed9 --- /dev/null +++ b/example/luks-btrfs-subvolumes.nix @@ -0,0 +1,60 @@ +{ + disko.devices = { + disk = { + vdb = { + type = "disk"; + device = "/dev/vdb"; + content = { + type = "gpt"; + partitions = { + ESP = { + label = "EFI"; + name = "ESP"; + size = "512M"; + type = "EF00" ; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ + "defaults" + ]; + }; + }; + luks = { + size = "100%"; + content = { + type = "luks"; + name = "crypted"; + extraOpenArgs = [ "--allow-discards" ]; + # if you want to use the key for interactive login be sure there is no trailing newline + # for example use `echo -n "password" > /tmp/secret.key` + #keyFile = "/tmp/secret.key"; # Interactive + settings.keyFile = "/tmp/secret.key"; + additionalKeyFiles = ["/tmp/additionalSecret.key"]; + content = { + type = "btrfs"; + extraArgs = [ "-f" ]; + subvolumes = { + "/root" = { + mountpoint = "/"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; + "/home" = { + mountpoint = "/home"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; + "/nix" = { + mountpoint = "/nix"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; +} From d306d84fb00039095f44b7d2b1392f08bece7ee7 Mon Sep 17 00:00:00 2001 From: Dave Conroy <23528985+tiredofit@users.noreply.github.com> Date: Thu, 27 Jul 2023 07:21:07 -0700 Subject: [PATCH 2/2] Add test for examples/luks-btrfs-subvolumes.nix --- tests/luks-btrfs-subvolumes.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/luks-btrfs-subvolumes.nix diff --git a/tests/luks-btrfs-subvolumes.nix b/tests/luks-btrfs-subvolumes.nix new file mode 100644 index 0000000..2898be7 --- /dev/null +++ b/tests/luks-btrfs-subvolumes.nix @@ -0,0 +1,13 @@ +{ pkgs ? (import { }) +, makeDiskoTest ? (pkgs.callPackage ../lib { }).testLib.makeDiskoTest +}: +makeDiskoTest { + inherit pkgs; + name = "luks-btrfs-subvolumes"; + disko-config = ../example/luks-btrfs-subvolumes.nix; + extraTestScript = '' + machine.succeed("cryptsetup isLuks /dev/vda2"); + machine.succeed("btrfs subvolume list / | grep -qs 'path nix$'"); + machine.succeed("btrfs subvolume list / | grep -qs 'path home$'"); + ''; +}