2023-01-28 18:19:13 +03:00
|
|
|
{ config, options, lib, diskoLib, ... }:
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = config._module.args.name;
|
|
|
|
description = "Name";
|
|
|
|
};
|
|
|
|
type = lib.mkOption {
|
|
|
|
type = lib.types.enum [ "mdadm" ];
|
|
|
|
default = "mdadm";
|
|
|
|
internal = true;
|
|
|
|
description = "Type";
|
|
|
|
};
|
|
|
|
level = lib.mkOption {
|
|
|
|
type = lib.types.int;
|
|
|
|
default = 1;
|
|
|
|
description = "mdadm level";
|
|
|
|
};
|
|
|
|
metadata = lib.mkOption {
|
|
|
|
type = lib.types.enum [ "1" "1.0" "1.1" "1.2" "default" "ddf" "imsm" ];
|
|
|
|
default = "default";
|
|
|
|
description = "Metadata";
|
|
|
|
};
|
2023-07-01 20:02:01 +03:00
|
|
|
content = diskoLib.deviceType { parent = config; device = "/dev/md/${config.name}"; };
|
2023-01-28 18:19:13 +03:00
|
|
|
_meta = lib.mkOption {
|
|
|
|
internal = true;
|
|
|
|
readOnly = true;
|
|
|
|
type = diskoLib.jsonType;
|
|
|
|
default =
|
2023-02-06 17:24:34 +03:00
|
|
|
lib.optionalAttrs (config.content != null) (config.content._meta [ "mdadm" config.name ]);
|
2023-01-28 18:19:13 +03:00
|
|
|
description = "Metadata";
|
|
|
|
};
|
|
|
|
_create = diskoLib.mkCreateOption {
|
|
|
|
inherit config options;
|
2023-07-01 20:02:01 +03:00
|
|
|
default = ''
|
2024-03-12 06:22:46 +03:00
|
|
|
if ! test -e /dev/md/${config.name}; then
|
|
|
|
readarray -t disk_devices < <(cat "$disko_devices_dir"/raid_${config.name})
|
|
|
|
echo 'y' | mdadm --create /dev/md/${config.name} \
|
|
|
|
--level=${toString config.level} \
|
|
|
|
--raid-devices="$(wc -l "$disko_devices_dir"/raid_${config.name} | cut -f 1 -d " ")" \
|
|
|
|
--metadata=${config.metadata} \
|
|
|
|
--force \
|
|
|
|
--homehost=any \
|
|
|
|
"''${disk_devices[@]}"
|
|
|
|
partprobe /dev/md/${config.name}
|
|
|
|
udevadm trigger --subsystem-match=block
|
|
|
|
udevadm settle
|
|
|
|
# for some reason mdadm devices spawn with an existing partition table, so we need to wipe it
|
|
|
|
sgdisk --zap-all /dev/md/${config.name}
|
|
|
|
fi
|
2023-07-01 20:02:01 +03:00
|
|
|
${lib.optionalString (config.content != null) config.content._create}
|
2023-01-28 18:19:13 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
_mount = diskoLib.mkMountOption {
|
|
|
|
inherit config options;
|
2023-07-01 20:02:01 +03:00
|
|
|
default =
|
|
|
|
lib.optionalAttrs (config.content != null) config.content._mount;
|
2023-01-28 18:19:13 +03:00
|
|
|
# TODO we probably need to assemble the mdadm somehow
|
|
|
|
};
|
|
|
|
_config = lib.mkOption {
|
|
|
|
internal = true;
|
|
|
|
readOnly = true;
|
|
|
|
default =
|
2023-08-11 09:32:16 +03:00
|
|
|
[
|
2023-09-02 19:08:33 +03:00
|
|
|
(if lib.versionAtLeast (lib.versions.majorMinor lib.version) "23.11" then {
|
2023-08-11 09:32:16 +03:00
|
|
|
boot.swraid.enable = true;
|
|
|
|
} else {
|
|
|
|
boot.initrd.services.swraid.enable = true;
|
|
|
|
})
|
|
|
|
] ++
|
2023-07-01 20:02:01 +03:00
|
|
|
lib.optional (config.content != null) config.content._config;
|
2023-01-28 18:19:13 +03:00
|
|
|
description = "NixOS configuration";
|
|
|
|
};
|
|
|
|
_pkgs = lib.mkOption {
|
|
|
|
internal = true;
|
|
|
|
readOnly = true;
|
|
|
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
2023-09-12 12:31:25 +03:00
|
|
|
default = pkgs: [
|
|
|
|
pkgs.parted # for partprobe
|
|
|
|
] ++ (lib.optionals (config.content != null) (config.content._pkgs pkgs));
|
2023-01-28 18:19:13 +03:00
|
|
|
description = "Packages";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|