mirror of
https://github.com/nix-community/disko.git
synced 2026-12-03 06:23:28 +01:00
Merge pull request #921 from nix-community/zfs-fix
zfs: run load-key on mount/unmount
This commit is contained in:
6 files changed
+65
-26
No files matched your search
@@ -97,7 +97,7 @@ let
|
|||||||
diskoScript =
|
diskoScript =
|
||||||
if hasDiskoConfigFlake then
|
if hasDiskoConfigFlake then
|
||||||
diskoEval
|
diskoEval
|
||||||
else if (lib.traceValSeq hasDiskoModuleFlake) then
|
else if hasDiskoModuleFlake then
|
||||||
(builtins.getFlake flake).nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr} or (
|
(builtins.getFlake flake).nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr} or (
|
||||||
pkgs.writeShellScriptBin "disko-compat-error" ''
|
pkgs.writeShellScriptBin "disko-compat-error" ''
|
||||||
echo 'Error: Attribute `nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr}` >&2
|
echo 'Error: Attribute `nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr}` >&2
|
||||||
|
|||||||
+15
-1
@@ -72,7 +72,7 @@
|
|||||||
options.mountpoint = "legacy";
|
options.mountpoint = "legacy";
|
||||||
mountpoint = "/zfs_legacy_fs";
|
mountpoint = "/zfs_legacy_fs";
|
||||||
};
|
};
|
||||||
zfs_testvolume = {
|
zfs_volume = {
|
||||||
type = "zfs_volume";
|
type = "zfs_volume";
|
||||||
size = "10M";
|
size = "10M";
|
||||||
content = {
|
content = {
|
||||||
@@ -81,6 +81,20 @@
|
|||||||
mountpoint = "/ext4onzfs";
|
mountpoint = "/ext4onzfs";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
zfs_encryptedvolume = {
|
||||||
|
type = "zfs_volume";
|
||||||
|
size = "10M";
|
||||||
|
options = {
|
||||||
|
encryption = "aes-256-gcm";
|
||||||
|
keyformat = "passphrase";
|
||||||
|
keylocation = "file:///tmp/secret.key";
|
||||||
|
};
|
||||||
|
content = {
|
||||||
|
type = "filesystem";
|
||||||
|
format = "ext4";
|
||||||
|
mountpoint = "/ext4onzfsencrypted";
|
||||||
|
};
|
||||||
|
};
|
||||||
encrypted = {
|
encrypted = {
|
||||||
type = "zfs_fs";
|
type = "zfs_fs";
|
||||||
options = {
|
options = {
|
||||||
|
|||||||
+10
-2
@@ -101,7 +101,13 @@
|
|||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default =
|
default =
|
||||||
lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
(lib.optionalAttrs (config.options.keylocation or "none" != "none") {
|
||||||
|
dev = ''
|
||||||
|
if [ "$(zfs get keystatus ${config._name} -H -o value)" == "unavailable" ]; then
|
||||||
|
zfs load-key ${config._name}
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
}) // lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
||||||
fs.${config.mountpoint} = ''
|
fs.${config.mountpoint} = ''
|
||||||
if ! findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
if ! findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
||||||
mount ${config._name} "${rootMountPoint}${config.mountpoint}" \
|
mount ${config._name} "${rootMountPoint}${config.mountpoint}" \
|
||||||
@@ -117,7 +123,9 @@
|
|||||||
_unmount = diskoLib.mkUnmountOption {
|
_unmount = diskoLib.mkUnmountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default =
|
default =
|
||||||
lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
(lib.optionalAttrs (config.options.keylocation or "none" != "none") {
|
||||||
|
dev = "zfs unload-key ${config.name}";
|
||||||
|
}) // lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
||||||
fs.${config.mountpoint} = ''
|
fs.${config.mountpoint} = ''
|
||||||
if findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
if findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
||||||
umount "${rootMountPoint}${config.mountpoint}"
|
umount "${rootMountPoint}${config.mountpoint}"
|
||||||
|
|||||||
@@ -66,13 +66,30 @@
|
|||||||
};
|
};
|
||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default =
|
default = {
|
||||||
lib.optionalAttrs (config.content != null) config.content._mount;
|
dev = ''
|
||||||
|
${lib.optionalString (config.options.keylocation or "none" != "none") ''
|
||||||
|
if [ "$(zfs get keystatus ${config.name} -H -o value)" == "unavailable" ]; then
|
||||||
|
zfs load-key ${config.name}
|
||||||
|
fi
|
||||||
|
''}
|
||||||
|
|
||||||
|
${config.content._mount.dev or ""}
|
||||||
|
'';
|
||||||
|
fs = config.content._mount.fs or { };
|
||||||
|
};
|
||||||
};
|
};
|
||||||
_unmount = diskoLib.mkUnmountOption {
|
_unmount = diskoLib.mkUnmountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default =
|
default = {
|
||||||
lib.optionalAttrs (config.content != null) config.content._unmount;
|
dev = ''
|
||||||
|
${lib.optionalString (config.options.keylocation or "none" != "none") "zfs unload-key ${config.name}"}
|
||||||
|
|
||||||
|
${config.content._unmount.dev or ""}
|
||||||
|
'';
|
||||||
|
|
||||||
|
fs = config.content._unmount.fs;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
_config = lib.mkOption {
|
_config = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|||||||
+13
-16
@@ -299,33 +299,30 @@ in
|
|||||||
inherit config options;
|
inherit config options;
|
||||||
default =
|
default =
|
||||||
let
|
let
|
||||||
datasetMounts = diskoLib.deepMergeMap (dataset: dataset._mount) (lib.attrValues config.datasets);
|
datasetFilesystemsMounts = diskoLib.deepMergeMap (dataset: dataset._mount.fs or {}) (lib.attrValues config.datasets);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
dev = ''
|
dev = ''
|
||||||
zpool list "${config.name}" >/dev/null 2>/dev/null ||
|
zpool list "${config.name}" >/dev/null 2>/dev/null ||
|
||||||
zpool import -l -R ${rootMountPoint} "${config.name}"
|
zpool import -l -R ${rootMountPoint} "${config.name}"
|
||||||
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
|
|
||||||
|
${lib.concatMapStrings (x: x._mount.dev or "") (lib.attrValues config.datasets)}
|
||||||
'';
|
'';
|
||||||
fs = datasetMounts.fs or { };
|
fs = datasetFilesystemsMounts;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
_unmount = diskoLib.mkUnmountOption {
|
_unmount = diskoLib.mkUnmountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default =
|
default = {
|
||||||
let
|
dev = ''
|
||||||
datasetUnmounts = diskoLib.deepMergeMap (dataset: dataset._unmount) (lib.attrValues config.datasets);
|
${lib.concatMapStrings (dataset: dataset._unmount.dev or "") (lib.attrValues config.datasets)}
|
||||||
in
|
|
||||||
{
|
|
||||||
dev = ''
|
|
||||||
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetUnmounts)}
|
|
||||||
|
|
||||||
if zpool list "${config.name}" >/dev/null 2>/dev/null; then
|
if zpool list "${config.name}" >/dev/null 2>/dev/null; then
|
||||||
zpool export "${config.name}"
|
zpool export "${config.name}"
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
fs = datasetUnmounts.fs or { };
|
fs = diskoLib.deepMergeMap (dataset: dataset._unmount.fs or {}) (lib.attrValues config.datasets);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
_config = lib.mkOption {
|
_config = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|||||||
+5
-2
@@ -11,7 +11,8 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
|
fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
|
||||||
};
|
};
|
||||||
extraTestScript = ''
|
extraTestScript = ''
|
||||||
machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume");
|
machine.succeed("test -b /dev/zvol/zroot/zfs_volume");
|
||||||
|
machine.succeed("test -b /dev/zvol/zroot/zfs_encryptedvolume");
|
||||||
|
|
||||||
def assert_property(ds, property, expected_value):
|
def assert_property(ds, property, expected_value):
|
||||||
out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip()
|
out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip()
|
||||||
@@ -23,7 +24,8 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
assert_property("zroot/zfs_fs", "compression", "zstd")
|
assert_property("zroot/zfs_fs", "compression", "zstd")
|
||||||
assert_property("zroot", "com.sun:auto-snapshot", "false")
|
assert_property("zroot", "com.sun:auto-snapshot", "false")
|
||||||
assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true")
|
assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true")
|
||||||
assert_property("zroot/zfs_testvolume", "volsize", "10M")
|
assert_property("zroot/zfs_volume", "volsize", "10M")
|
||||||
|
assert_property("zroot/zfs_encryptedvolume", "volsize", "10M")
|
||||||
assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none")
|
assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none")
|
||||||
|
|
||||||
machine.succeed("zfs get name zroot@blank")
|
machine.succeed("zfs get name zroot@blank")
|
||||||
@@ -31,6 +33,7 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
machine.succeed("mountpoint /zfs_fs");
|
machine.succeed("mountpoint /zfs_fs");
|
||||||
machine.succeed("mountpoint /zfs_legacy_fs");
|
machine.succeed("mountpoint /zfs_legacy_fs");
|
||||||
machine.succeed("mountpoint /ext4onzfs");
|
machine.succeed("mountpoint /ext4onzfs");
|
||||||
|
machine.succeed("mountpoint /ext4onzfsencrypted");
|
||||||
machine.succeed("mountpoint /zfs_crypted");
|
machine.succeed("mountpoint /zfs_crypted");
|
||||||
machine.succeed("zfs get keystatus zroot/encrypted");
|
machine.succeed("zfs get keystatus zroot/encrypted");
|
||||||
machine.succeed("zfs get keystatus zroot/encrypted/test");
|
machine.succeed("zfs get keystatus zroot/encrypted/test");
|
||||||
|
|||||||
Reference in new issue
Block a user