mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-12 08:00:05 +01:00
Merge pull request #234 from nix-community/lvm_sort
This commit is contained in:
commit
10402e3144
8 changed files with 145 additions and 45 deletions
|
|
@ -11,6 +11,7 @@ status = [
|
|||
"check hybrid-tmpfs-on-root [x86_64-linux]",
|
||||
"check luks-lvm [x86_64-linux]",
|
||||
"check lvm-raid [x86_64-linux]",
|
||||
"check lvm-sizes-sort [x86_64-linux]",
|
||||
"check mdadm [x86_64-linux]",
|
||||
"check module [x86_64-linux]",
|
||||
"check multi-device-no-deps [x86_64-linux]",
|
||||
|
|
|
|||
69
example/lvm-sizes-sort.nix
Normal file
69
example/lvm-sizes-sort.nix
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
|
||||
disko.devices = {
|
||||
disk = {
|
||||
one = {
|
||||
type = "disk";
|
||||
device = builtins.elemAt disks 0;
|
||||
content = {
|
||||
type = "table";
|
||||
format = "gpt";
|
||||
partitions = [
|
||||
{
|
||||
name = "boot";
|
||||
start = "0";
|
||||
end = "100M";
|
||||
fs-type = "fat32";
|
||||
bootable = true;
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
};
|
||||
}
|
||||
{
|
||||
name = "primary";
|
||||
start = "100M";
|
||||
end = "100%";
|
||||
content = {
|
||||
type = "lvm_pv";
|
||||
vg = "pool";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
lvm_vg = {
|
||||
pool = {
|
||||
type = "lvm_vg";
|
||||
lvs = {
|
||||
aaa = {
|
||||
size = "1M";
|
||||
};
|
||||
zzz = {
|
||||
size = "1M";
|
||||
};
|
||||
root = {
|
||||
size = "100M";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/";
|
||||
mountOptions = [
|
||||
"defaults"
|
||||
];
|
||||
};
|
||||
};
|
||||
home = {
|
||||
size = "100%FREE";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/home";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
buildLinux (args // {
|
||||
# NOTE: bcachefs-tools should be updated simultaneously to preserve compatibility
|
||||
version = "6.3.0-2023-05-02";
|
||||
|
||||
|
||||
modDirVersion = "6.3.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
|
|
|
|||
10
tests/lvm-sizes-sort.nix
Normal file
10
tests/lvm-sizes-sort.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{ pkgs ? (import <nixpkgs> { })
|
||||
, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
|
||||
}:
|
||||
makeDiskoTest {
|
||||
name = "lvm-sizes-sort";
|
||||
disko-config = ../example/lvm-sizes-sort.nix;
|
||||
extraTestScript = ''
|
||||
machine.succeed("mountpoint /home");
|
||||
'';
|
||||
}
|
||||
|
|
@ -44,36 +44,44 @@
|
|||
readOnly = true;
|
||||
type = diskoLib.jsonType;
|
||||
default =
|
||||
diskoLib.deepMergeMap (lv:
|
||||
lib.optionalAttrs (lv.content != null) (lv.content._meta [ "lvm_vg" config.name ])
|
||||
) (lib.attrValues config.lvs);
|
||||
diskoLib.deepMergeMap
|
||||
(lv:
|
||||
lib.optionalAttrs (lv.content != null) (lv.content._meta [ "lvm_vg" config.name ])
|
||||
)
|
||||
(lib.attrValues config.lvs);
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
inherit config options;
|
||||
default = _: ''
|
||||
readarray -t lvm_devices < <(cat "$disko_devices_dir"/lvm_${config.name})
|
||||
vgcreate ${config.name} \
|
||||
"''${lvm_devices[@]}"
|
||||
${lib.concatMapStrings (lv: ''
|
||||
lvcreate \
|
||||
--yes \
|
||||
${if lib.hasInfix "%" lv.size then "-l" else "-L"} ${lv.size} \
|
||||
-n ${lv.name} \
|
||||
${lib.optionalString (lv.lvm_type != null) "--type=${lv.lvm_type}"} \
|
||||
${toString lv.extraArgs} \
|
||||
${config.name}
|
||||
${lib.optionalString (lv.content != null) (lv.content._create {dev = "/dev/${config.name}/${lv.name}";})}
|
||||
'') (lib.attrValues config.lvs)}
|
||||
'';
|
||||
default = _:
|
||||
let
|
||||
sortedLvs = lib.sort (a: _: !lib.hasInfix "100%" a.size) (lib.attrValues config.lvs);
|
||||
in
|
||||
''
|
||||
readarray -t lvm_devices < <(cat "$disko_devices_dir"/lvm_${config.name})
|
||||
vgcreate ${config.name} \
|
||||
"''${lvm_devices[@]}"
|
||||
${lib.concatMapStrings (lv: ''
|
||||
lvcreate \
|
||||
--yes \
|
||||
${if lib.hasInfix "%" lv.size then "-l" else "-L"} ${lv.size} \
|
||||
-n ${lv.name} \
|
||||
${lib.optionalString (lv.lvm_type != null) "--type=${lv.lvm_type}"} \
|
||||
${toString lv.extraArgs} \
|
||||
${config.name}
|
||||
${lib.optionalString (lv.content != null) (lv.content._create {dev = "/dev/${config.name}/${lv.name}";})}
|
||||
'') sortedLvs}
|
||||
'';
|
||||
};
|
||||
_mount = diskoLib.mkMountOption {
|
||||
inherit config options;
|
||||
default = _:
|
||||
let
|
||||
lvMounts = diskoLib.deepMergeMap (lv:
|
||||
lib.optionalAttrs (lv.content != null) (lv.content._mount { dev = "/dev/${config.name}/${lv.name}"; })
|
||||
) (lib.attrValues config.lvs);
|
||||
lvMounts = diskoLib.deepMergeMap
|
||||
(lv:
|
||||
lib.optionalAttrs (lv.content != null) (lv.content._mount { dev = "/dev/${config.name}/${lv.name}"; })
|
||||
)
|
||||
(lib.attrValues config.lvs);
|
||||
in
|
||||
{
|
||||
dev = ''
|
||||
|
|
@ -87,21 +95,25 @@
|
|||
internal = true;
|
||||
readOnly = true;
|
||||
default =
|
||||
map (lv: [
|
||||
(lib.optional (lv.content != null) (lv.content._config "/dev/${config.name}/${lv.name}"))
|
||||
(lib.optional (lv.lvm_type != null) {
|
||||
boot.initrd.kernelModules = [ "dm-${lv.lvm_type}" ];
|
||||
})
|
||||
]) (lib.attrValues config.lvs);
|
||||
map
|
||||
(lv: [
|
||||
(lib.optional (lv.content != null) (lv.content._config "/dev/${config.name}/${lv.name}"))
|
||||
(lib.optional (lv.lvm_type != null) {
|
||||
boot.initrd.kernelModules = [ "dm-${lv.lvm_type}" ];
|
||||
})
|
||||
])
|
||||
(lib.attrValues config.lvs);
|
||||
description = "NixOS configuration";
|
||||
};
|
||||
_pkgs = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs: lib.flatten (map (lv:
|
||||
lib.optional (lv.content != null) (lv.content._pkgs pkgs)
|
||||
) (lib.attrValues config.lvs));
|
||||
default = pkgs: lib.flatten (map
|
||||
(lv:
|
||||
lib.optional (lv.content != null) (lv.content._pkgs pkgs)
|
||||
)
|
||||
(lib.attrValues config.lvs));
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -65,9 +65,11 @@
|
|||
readOnly = true;
|
||||
type = lib.types.functionTo diskoLib.jsonType;
|
||||
default = dev:
|
||||
lib.foldr lib.recursiveUpdate {} (lib.imap (index: partition:
|
||||
lib.optionalAttrs (partition.content != null) (partition.content._meta dev)
|
||||
) config.partitions);
|
||||
lib.foldr lib.recursiveUpdate { } (lib.imap
|
||||
(index: partition:
|
||||
lib.optionalAttrs (partition.content != null) (partition.content._meta dev)
|
||||
)
|
||||
config.partitions);
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
|
|
@ -99,9 +101,11 @@
|
|||
inherit config options;
|
||||
default = { dev }:
|
||||
let
|
||||
partMounts = lib.foldr lib.recursiveUpdate {} (lib.imap (index: partition:
|
||||
lib.optionalAttrs (partition.content != null) (partition.content._mount { dev = diskoLib.deviceNumbering dev index; })
|
||||
) config.partitions);
|
||||
partMounts = lib.foldr lib.recursiveUpdate { } (lib.imap
|
||||
(index: partition:
|
||||
lib.optionalAttrs (partition.content != null) (partition.content._mount { dev = diskoLib.deviceNumbering dev index; })
|
||||
)
|
||||
config.partitions);
|
||||
in
|
||||
{
|
||||
dev = partMounts.dev or "";
|
||||
|
|
@ -112,9 +116,11 @@
|
|||
internal = true;
|
||||
readOnly = true;
|
||||
default = dev:
|
||||
lib.imap (index: partition:
|
||||
lib.optional (partition.content != null) (partition.content._config (diskoLib.deviceNumbering dev index))
|
||||
) config.partitions;
|
||||
lib.imap
|
||||
(index: partition:
|
||||
lib.optional (partition.content != null) (partition.content._config (diskoLib.deviceNumbering dev index))
|
||||
)
|
||||
config.partitions;
|
||||
description = "NixOS configuration";
|
||||
};
|
||||
_pkgs = lib.mkOption {
|
||||
|
|
@ -122,9 +128,11 @@
|
|||
readOnly = true;
|
||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs:
|
||||
[ pkgs.parted pkgs.systemdMinimal ] ++ lib.flatten (map (partition:
|
||||
lib.optional (partition.content != null) (partition.content._pkgs pkgs)
|
||||
) config.partitions);
|
||||
[ pkgs.parted pkgs.systemdMinimal ] ++ lib.flatten (map
|
||||
(partition:
|
||||
lib.optional (partition.content != null) (partition.content._pkgs pkgs)
|
||||
)
|
||||
config.partitions);
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo diskoLib.jsonType;
|
||||
default = dev: {};
|
||||
default = dev: { };
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@
|
|||
zpool import -l -R ${config.mountRoot} '${config.name}'
|
||||
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
|
||||
'';
|
||||
fs = (datasetMounts.fs or {}) // lib.optionalAttrs (config.mountpoint != null) {
|
||||
fs = (datasetMounts.fs or { }) // lib.optionalAttrs (config.mountpoint != null) {
|
||||
${config.mountpoint} = ''
|
||||
if ! findmnt ${config.name} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
|
||||
mount ${config.name} "${rootMountPoint}${config.mountpoint}" \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue