mirror of
https://github.com/nix-community/disko
synced 2024-11-10 06:14:14 +00:00
Merge pull request #689 from nix-community/incremental-zfs
zfs: when dataset already exist, only update dataset options
This commit is contained in:
commit
e8ef4773dd
1 changed files with 30 additions and 2 deletions
|
@ -59,10 +59,38 @@
|
|||
# important to prevent accidental shadowing of mount points
|
||||
# since (create order != mount order)
|
||||
# -p creates parents automatically
|
||||
default = ''
|
||||
default = let
|
||||
createOptions = (lib.optionalAttrs (config.mountpoint != null) { mountpoint = config.mountpoint; }) // config.options;
|
||||
# All options defined as PROP_ONETIME or PROP_ONETIME_DEFAULT in https://github.com/openzfs/zfs/blob/master/module/zcommon/zfs_prop.c
|
||||
onetimeProperties = [
|
||||
"encryption"
|
||||
"casesensitivity"
|
||||
"utf8only"
|
||||
"normalization"
|
||||
"volblocksize"
|
||||
"pbkdf2iters"
|
||||
"pbkdf2salt"
|
||||
"keyformat"
|
||||
];
|
||||
updateOptions = builtins.removeAttrs config.options onetimeProperties;
|
||||
mountpoint = config.options.mountpoint or config.mountpoint;
|
||||
in ''
|
||||
if ! zfs get type ${config._name} >/dev/null 2>&1; then
|
||||
zfs create -up ${config._name} \
|
||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)}
|
||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") (createOptions))}
|
||||
${lib.optionalString (updateOptions != {}) ''
|
||||
else
|
||||
zfs set ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${v}") updateOptions)} ${config._name}
|
||||
${lib.optionalString (mountpoint != null) ''
|
||||
# zfs will try unmount the dataset to change the mountpoint
|
||||
# but this might fail if the dataset is in use
|
||||
if ! zfs set mountpoint=${mountpoint} ${config._name}; then
|
||||
echo "Failed to set mountpoint to '${mountpoint}' for ${config._name}." >&2
|
||||
echo "You may need to run when the pool is not mounted i.e. in a recovery system:" >&2
|
||||
echo " zfs set mountpoint=${mountpoint} ${config._name}" >&2
|
||||
fi
|
||||
''}
|
||||
''}
|
||||
fi
|
||||
'';
|
||||
} // { readOnly = false; };
|
||||
|
|
Loading…
Reference in a new issue