mirror of
https://github.com/oddlama/nixos-extra-modules.git
synced 2025-10-10 22:00:39 +02:00
fix: shared datasets have to be mounted sequentially
This commit is contained in:
parent
35a5d08c3e
commit
dca8158b4f
1 changed files with 47 additions and 21 deletions
|
@ -14,7 +14,9 @@
|
||||||
escapeShellArg
|
escapeShellArg
|
||||||
flatten
|
flatten
|
||||||
flip
|
flip
|
||||||
|
foldl'
|
||||||
groupBy
|
groupBy
|
||||||
|
hasInfix
|
||||||
hasPrefix
|
hasPrefix
|
||||||
listToAttrs
|
listToAttrs
|
||||||
literalExpression
|
literalExpression
|
||||||
|
@ -26,7 +28,9 @@
|
||||||
mkMerge
|
mkMerge
|
||||||
mkOption
|
mkOption
|
||||||
net
|
net
|
||||||
|
optional
|
||||||
types
|
types
|
||||||
|
warnIf
|
||||||
;
|
;
|
||||||
|
|
||||||
# All available backends
|
# All available backends
|
||||||
|
@ -47,18 +51,8 @@
|
||||||
# Add the required datasets to the disko configuration of the machine
|
# Add the required datasets to the disko configuration of the machine
|
||||||
disko.devices.zpool = mkMerge (flip map (attrValues guestCfg.zfs) (zfsCfg: {
|
disko.devices.zpool = mkMerge (flip map (attrValues guestCfg.zfs) (zfsCfg: {
|
||||||
${zfsCfg.pool}.datasets.${zfsCfg.dataset} =
|
${zfsCfg.pool}.datasets.${zfsCfg.dataset} =
|
||||||
if !zfsCfg.shared
|
# We generate the mountpoint fileSystems entries ourselfs to enable shared folders between guests
|
||||||
then disko.zfs.filesystem zfsCfg.hostMountpoint
|
disko.zfs.unmountable;
|
||||||
else disko.zfs.unmountable;
|
|
||||||
}));
|
|
||||||
|
|
||||||
# Add the required fileSystems for shared folders
|
|
||||||
fileSystems = mkMerge (flip map (attrValues guestCfg.zfs) (zfsCfg: {
|
|
||||||
${zfsCfg.hostMountpoint} = {
|
|
||||||
fsType = "zfs";
|
|
||||||
options = ["zfsutil"];
|
|
||||||
device = "${zfsCfg.pool}/${zfsCfg.dataset}";
|
|
||||||
};
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
# Ensure that the zfs dataset exists before it is mounted.
|
# Ensure that the zfs dataset exists before it is mounted.
|
||||||
|
@ -249,13 +243,6 @@ in {
|
||||||
example = "/persist";
|
example = "/persist";
|
||||||
description = "The mountpoint inside the guest.";
|
description = "The mountpoint inside the guest.";
|
||||||
};
|
};
|
||||||
|
|
||||||
shared = mkOption {
|
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
example = true;
|
|
||||||
description = "Whether this mountpoint will be shared between different guests. This will prevent disko from creating a entry to config.filesSystems.";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
@ -282,8 +269,47 @@ in {
|
||||||
"d /guests 0700 root root -"
|
"d /guests 0700 root root -"
|
||||||
];
|
];
|
||||||
|
|
||||||
fileSystems =
|
# To enable shared folders we need to do all fileSystems entries ourselfs
|
||||||
# for guests filter zfs shared, group by mountpoint, fold and add dependencies.
|
fileSystems = let
|
||||||
|
zfsDefs = flatten (flip mapAttrsToList config.guests (
|
||||||
|
_: guestCfg:
|
||||||
|
flip mapAttrsToList guestCfg.zfs (
|
||||||
|
_: zfsCfg: {
|
||||||
|
path = "${zfsCfg.pool}/${zfsCfg.dataset}";
|
||||||
|
inherit (zfsCfg) hostMountpoint;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
));
|
||||||
|
# Due to limitations in zfs mounting we need to explicitly set an order in which
|
||||||
|
# any dataset gets mounted
|
||||||
|
zfsDefsByPath = flip groupBy zfsDefs (x: x.path);
|
||||||
|
in
|
||||||
|
mkMerge (flip mapAttrsToList zfsDefsByPath (_: defs:
|
||||||
|
(foldl' ({
|
||||||
|
prev,
|
||||||
|
res,
|
||||||
|
}: elem: {
|
||||||
|
prev = elem;
|
||||||
|
res =
|
||||||
|
res
|
||||||
|
// {
|
||||||
|
${elem.hostMountpoint} = {
|
||||||
|
fsType = "zfs";
|
||||||
|
options =
|
||||||
|
["zfsutil"]
|
||||||
|
++ optional (prev != null) "x-systemd.requires-mounts-for=${warnIf
|
||||||
|
(hasInfix " " prev.hostMountpoint) "HostMountpoint ${prev.hostMountpoint} cannot contain a space"
|
||||||
|
prev.hostMountpoint}";
|
||||||
|
device = elem.path;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
{
|
||||||
|
prev = null;
|
||||||
|
res = {};
|
||||||
|
}
|
||||||
|
defs)
|
||||||
|
.res));
|
||||||
|
|
||||||
assertions = flatten (flip mapAttrsToList config.guests (
|
assertions = flatten (flip mapAttrsToList config.guests (
|
||||||
guestName: guestCfg:
|
guestName: guestCfg:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue