feat: refined options for datasets
This commit is contained in:
parent
0de97fa4a2
commit
9df29cc07f
6 changed files with 295 additions and 271 deletions
|
|
@ -171,153 +171,153 @@ in {
|
|||
};
|
||||
|
||||
# Disko configuration based on pool settings
|
||||
disko.devices = {
|
||||
disk = (
|
||||
builtins.listToAttrs (
|
||||
builtins.map
|
||||
(drive:
|
||||
lib.attrsets.nameValuePair (drive.name) {
|
||||
type = "disk";
|
||||
device = "/dev/disk/by-id/${drive.value}";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
ESP = lib.mkIf (builtins.elem drive.value bootDrives) {
|
||||
size = config.storage.zfs.pool.bootPartitionSize;
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = ["umask=0077"];
|
||||
};
|
||||
};
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "rpool";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
})
|
||||
allDrives
|
||||
)
|
||||
);
|
||||
zpool = {
|
||||
rpool = {
|
||||
type = "zpool";
|
||||
mode = {
|
||||
topology = {
|
||||
type = "topology";
|
||||
vdev = (
|
||||
builtins.map (disks: {
|
||||
mode = config.storage.zfs.pool.mode;
|
||||
members =
|
||||
builtins.map (disk: disk.name) disks;
|
||||
})
|
||||
poolVdevs
|
||||
);
|
||||
cache = builtins.map (disk: disk.name) poolCache;
|
||||
};
|
||||
};
|
||||
# disko.devices = {
|
||||
# disk = (
|
||||
# builtins.listToAttrs (
|
||||
# builtins.map
|
||||
# (drive:
|
||||
# lib.attrsets.nameValuePair (drive.name) {
|
||||
# type = "disk";
|
||||
# device = "/dev/disk/by-id/${drive.value}";
|
||||
# content = {
|
||||
# type = "gpt";
|
||||
# partitions = {
|
||||
# ESP = lib.mkIf (builtins.elem drive.value bootDrives) {
|
||||
# size = config.storage.zfs.pool.bootPartitionSize;
|
||||
# type = "EF00";
|
||||
# content = {
|
||||
# type = "filesystem";
|
||||
# format = "vfat";
|
||||
# mountpoint = "/boot";
|
||||
# mountOptions = ["umask=0077"];
|
||||
# };
|
||||
# };
|
||||
# zfs = {
|
||||
# size = "100%";
|
||||
# content = {
|
||||
# type = "zfs";
|
||||
# pool = "rpool";
|
||||
# };
|
||||
# };
|
||||
# };
|
||||
# };
|
||||
# })
|
||||
# allDrives
|
||||
# )
|
||||
# );
|
||||
# zpool = {
|
||||
# rpool = {
|
||||
# type = "zpool";
|
||||
# mode = {
|
||||
# topology = {
|
||||
# type = "topology";
|
||||
# vdev = (
|
||||
# builtins.map (disks: {
|
||||
# mode = config.storage.zfs.pool.mode;
|
||||
# members =
|
||||
# builtins.map (disk: disk.name) disks;
|
||||
# })
|
||||
# poolVdevs
|
||||
# );
|
||||
# cache = builtins.map (disk: disk.name) poolCache;
|
||||
# };
|
||||
# };
|
||||
|
||||
options = {
|
||||
ashift = "12";
|
||||
autotrim = "on";
|
||||
};
|
||||
# options = {
|
||||
# ashift = "12";
|
||||
# autotrim = "on";
|
||||
# };
|
||||
|
||||
rootFsOptions = let
|
||||
rootDataset = config.storage.zfs.rootDataset;
|
||||
# Start with defaults that match the original hardcoded values
|
||||
defaults = {
|
||||
canmount = "off";
|
||||
mountpoint = "none";
|
||||
xattr = "sa";
|
||||
acltype = "posixacl";
|
||||
relatime = "on";
|
||||
compression = "lz4";
|
||||
"com.sun:auto-snapshot" = "false";
|
||||
};
|
||||
# Override defaults with non-null values from rootDataset
|
||||
userOptions = lib.attrsets.filterAttrs (_: v: v != null) {
|
||||
canmount = rootDataset.canmount;
|
||||
mountpoint = rootDataset.mountpoint;
|
||||
xattr = rootDataset.xattr;
|
||||
acltype = rootDataset.acltype;
|
||||
relatime = rootDataset.relatime;
|
||||
compression = rootDataset.compression;
|
||||
encryption = rootDataset.encryption;
|
||||
keyformat = rootDataset.keyformat;
|
||||
keylocation = rootDataset.keylocation;
|
||||
recordsize = rootDataset.recordsize;
|
||||
sync = rootDataset.sync;
|
||||
atime = rootDataset.atime;
|
||||
"com.sun:auto-snapshot" =
|
||||
if rootDataset.autoSnapshot == null
|
||||
then null
|
||||
else
|
||||
(
|
||||
if rootDataset.autoSnapshot
|
||||
then "true"
|
||||
else "false"
|
||||
);
|
||||
};
|
||||
# Only apply pool encryption if user hasn't set encryption options in rootDataset
|
||||
poolEncryptionOptions =
|
||||
lib.attrsets.optionalAttrs (
|
||||
config.storage.zfs.pool.encryption.enable
|
||||
&& rootDataset.encryption == null
|
||||
&& rootDataset.keyformat == null
|
||||
&& rootDataset.keylocation == null
|
||||
) {
|
||||
encryption = "on";
|
||||
keyformat = config.storage.zfs.pool.encryption.keyformat;
|
||||
keylocation = config.storage.zfs.pool.encryption.keylocation;
|
||||
};
|
||||
in
|
||||
defaults // userOptions // rootDataset.options // poolEncryptionOptions;
|
||||
# rootFsOptions = let
|
||||
# rootDataset = config.storage.zfs.rootDataset;
|
||||
# # Start with defaults that match the original hardcoded values
|
||||
# defaults = {
|
||||
# canmount = "off";
|
||||
# mountpoint = "none";
|
||||
# xattr = "sa";
|
||||
# acltype = "posixacl";
|
||||
# relatime = "on";
|
||||
# compression = "lz4";
|
||||
# "com.sun:auto-snapshot" = "false";
|
||||
# };
|
||||
# # Override defaults with non-null values from rootDataset
|
||||
# userOptions = lib.attrsets.filterAttrs (_: v: v != null) {
|
||||
# canmount = rootDataset.canmount;
|
||||
# mountpoint = rootDataset.mountpoint;
|
||||
# xattr = rootDataset.xattr;
|
||||
# acltype = rootDataset.acltype;
|
||||
# relatime = rootDataset.relatime;
|
||||
# compression = rootDataset.compression;
|
||||
# encryption = rootDataset.encryption;
|
||||
# keyformat = rootDataset.keyformat;
|
||||
# keylocation = rootDataset.keylocation;
|
||||
# recordsize = rootDataset.recordsize;
|
||||
# sync = rootDataset.sync;
|
||||
# atime = rootDataset.atime;
|
||||
# "com.sun:auto-snapshot" =
|
||||
# if rootDataset.autoSnapshot == null
|
||||
# then null
|
||||
# else
|
||||
# (
|
||||
# if rootDataset.autoSnapshot
|
||||
# then "true"
|
||||
# else "false"
|
||||
# );
|
||||
# };
|
||||
# # Only apply pool encryption if user hasn't set encryption options in rootDataset
|
||||
# poolEncryptionOptions =
|
||||
# lib.attrsets.optionalAttrs (
|
||||
# config.storage.zfs.pool.encryption.enable
|
||||
# && rootDataset.encryption == null
|
||||
# && rootDataset.keyformat == null
|
||||
# && rootDataset.keylocation == null
|
||||
# ) {
|
||||
# encryption = "on";
|
||||
# keyformat = config.storage.zfs.pool.encryption.keyformat;
|
||||
# keylocation = config.storage.zfs.pool.encryption.keylocation;
|
||||
# };
|
||||
# in
|
||||
# defaults // userOptions // rootDataset.options // poolEncryptionOptions;
|
||||
|
||||
datasets = lib.mkMerge [
|
||||
(
|
||||
lib.attrsets.mapAttrs (name: value: {
|
||||
type = value.type;
|
||||
options = let
|
||||
# For datasets, only include non-null user-specified values
|
||||
userOptions = lib.attrsets.filterAttrs (_: v: v != null) {
|
||||
canmount = value.canmount;
|
||||
xattr = value.xattr;
|
||||
acltype = value.acltype;
|
||||
relatime = value.relatime;
|
||||
compression = value.compression;
|
||||
encryption = value.encryption;
|
||||
keyformat = value.keyformat;
|
||||
keylocation = value.keylocation;
|
||||
recordsize = value.recordsize;
|
||||
sync = value.sync;
|
||||
atime = value.atime;
|
||||
"com.sun:auto-snapshot" =
|
||||
if value.autoSnapshot == null
|
||||
then null
|
||||
else
|
||||
(
|
||||
if value.autoSnapshot
|
||||
then "true"
|
||||
else "false"
|
||||
);
|
||||
};
|
||||
in
|
||||
userOptions // (value.options or {});
|
||||
mountpoint = value.mountpoint;
|
||||
postCreateHook = value.postCreateHook or "";
|
||||
})
|
||||
config.storage.zfs.datasets
|
||||
)
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
# datasets = lib.mkMerge [
|
||||
# (
|
||||
# lib.attrsets.mapAttrs (name: value: {
|
||||
# type = value.type;
|
||||
# options = let
|
||||
# # For datasets, only include non-null user-specified values
|
||||
# userOptions = lib.attrsets.filterAttrs (_: v: v != null) {
|
||||
# canmount = value.canmount;
|
||||
# xattr = value.xattr;
|
||||
# acltype = value.acltype;
|
||||
# relatime = value.relatime;
|
||||
# compression = value.compression;
|
||||
# encryption = value.encryption;
|
||||
# keyformat = value.keyformat;
|
||||
# keylocation = value.keylocation;
|
||||
# recordsize = value.recordsize;
|
||||
# sync = value.sync;
|
||||
# atime = value.atime;
|
||||
# "com.sun:auto-snapshot" =
|
||||
# if value.autoSnapshot == null
|
||||
# then null
|
||||
# else
|
||||
# (
|
||||
# if value.autoSnapshot
|
||||
# then "true"
|
||||
# else "false"
|
||||
# );
|
||||
# };
|
||||
# in
|
||||
# userOptions // (value.options or {});
|
||||
# mountpoint = value.mountpoint;
|
||||
# postCreateHook = value.postCreateHook or "";
|
||||
# })
|
||||
# config.storage.zfs.datasets
|
||||
# )
|
||||
# ];
|
||||
# };
|
||||
# };
|
||||
# };
|
||||
|
||||
# Post-activation scripts for validation
|
||||
system.activationScripts = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue