mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13:28 +01:00
Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4c64aee75 | ||
|
|
54bf06ba8c | ||
|
|
55e874b9c1 | ||
|
|
4698b1ef37 | ||
|
|
2f5df5dcce | ||
|
|
bec6e3cde9 | ||
|
|
e8e8d9a3a9 | ||
|
|
bad376945d | ||
|
|
786965e1b1 | ||
|
|
f1a00e7f55 | ||
|
|
64679cd7f3 | ||
|
|
544a80a69d | ||
|
|
895b2713e1 | ||
|
|
d185770ea2 | ||
|
|
05f4e223b5 | ||
|
|
423b86a7f7 | ||
|
|
115311bc39 | ||
|
|
e8ef4773dd | ||
|
|
96cab883db | ||
|
|
8767dbf5d7 | ||
|
|
b6a1262796 |
No files matched your search
@@ -15,7 +15,7 @@ jobs:
|
|||||||
- name: Install Nix
|
- name: Install Nix
|
||||||
uses: cachix/install-nix-action@V27
|
uses: cachix/install-nix-action@V27
|
||||||
- name: Update flake.lock
|
- name: Update flake.lock
|
||||||
uses: DeterminateSystems/update-flake-lock@v22
|
uses: DeterminateSystems/update-flake-lock@v23
|
||||||
with:
|
with:
|
||||||
pr-labels: |
|
pr-labels: |
|
||||||
merge-queue
|
merge-queue
|
||||||
+1
-1
@@ -240,7 +240,7 @@ main() {
|
|||||||
NIX_STATE_DIR=${mountPoint}/nix/var/nix nix-store --load-db < "${closure_info}/registration"
|
NIX_STATE_DIR=${mountPoint}/nix/var/nix nix-store --load-db < "${closure_info}/registration"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
nixos-install --no-root-password --system "$nixos_system" --root "$mountPoint"
|
nixos-install --no-channel-copy --no-root-password --system "$nixos_system" --root "$mountPoint"
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
device = "/dev/disk/by-path/pci-0000:02:00.0-nvme-1";
|
device = "/dev/disk/by-path/pci-0000:02:00.0-nvme-1";
|
||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
boot = {
|
boot = {
|
||||||
size = "1M";
|
size = "1M";
|
||||||
type = "EF02"; # for grub MBR
|
type = "EF02"; # for grub MBR
|
||||||
priority = 1; # Needs to be first partition
|
|
||||||
};
|
};
|
||||||
ESP = {
|
ESP = {
|
||||||
size = "500M";
|
size = "500M";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/disk/by-diskseq/1";
|
device = "/dev/disk/by-diskseq/1";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/disk/by-diskseq/1";
|
device = "/dev/disk/by-diskseq/1";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
device = "/dev/vdb";
|
device = "/dev/vdb";
|
||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
content = {
|
||||||
@@ -11,7 +11,6 @@
|
|||||||
boot = {
|
boot = {
|
||||||
size = "1M";
|
size = "1M";
|
||||||
type = "EF02"; # for grub MBR
|
type = "EF02"; # for grub MBR
|
||||||
priority = 1; # Needs to be first partition
|
|
||||||
};
|
};
|
||||||
root = {
|
root = {
|
||||||
size = "100%";
|
size = "100%";
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
boot = {
|
boot = {
|
||||||
size = "1M";
|
size = "1M";
|
||||||
type = "EF02"; # for grub MBR
|
type = "EF02"; # for grub MBR
|
||||||
priority = 1; # Needs to be first partition
|
|
||||||
};
|
};
|
||||||
ESP = {
|
ESP = {
|
||||||
name = "ESP";
|
name = "ESP";
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
boot = {
|
boot = {
|
||||||
size = "1M";
|
size = "1M";
|
||||||
type = "EF02"; # for grub MBR
|
type = "EF02"; # for grub MBR
|
||||||
priority = 1; # Needs to be first partition
|
|
||||||
};
|
};
|
||||||
ESP = {
|
ESP = {
|
||||||
size = "512M";
|
size = "512M";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
device = "/dev/sda";
|
device = "/dev/sda";
|
||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
device = "/dev/disk/by-id/some-disk-id";
|
device = "/dev/disk/by-id/some-disk-id";
|
||||||
name = "this-is-some-super-long-name-to-test-what-happens-when-the-name-is-too-long";
|
name = "this-is-some-super-long-name-to-test-what-happens-when-the-name-is-too-long";
|
||||||
type = "disk";
|
type = "disk";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vdb";
|
device = "/dev/vdb";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vdb";
|
device = "/dev/vdb";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vdb";
|
device = "/dev/vdb";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
boot = {
|
boot = {
|
||||||
size = "1M";
|
size = "1M";
|
||||||
type = "EF02"; # for grub MBR
|
type = "EF02"; # for grub MBR
|
||||||
priority = 1; # Needs to be first partition
|
|
||||||
};
|
};
|
||||||
ESP = {
|
ESP = {
|
||||||
size = "500M";
|
size = "500M";
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
{
|
||||||
|
disko.devices = {
|
||||||
|
disk = {
|
||||||
|
main = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdb";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
ESP = {
|
||||||
|
size = "500M";
|
||||||
|
type = "EF00";
|
||||||
|
content = {
|
||||||
|
type = "filesystem";
|
||||||
|
format = "vfat";
|
||||||
|
mountpoint = "/boot";
|
||||||
|
mountOptions = [
|
||||||
|
"defaults"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
primary = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "lvm_pv";
|
||||||
|
vg = "mainpool";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
lvm_vg = {
|
||||||
|
mainpool = {
|
||||||
|
type = "lvm_vg";
|
||||||
|
lvs = {
|
||||||
|
thinpool = {
|
||||||
|
size = "100M";
|
||||||
|
lvm_type = "thin-pool";
|
||||||
|
};
|
||||||
|
root = {
|
||||||
|
size = "10M";
|
||||||
|
lvm_type = "thinlv";
|
||||||
|
pool = "thinpool";
|
||||||
|
content = {
|
||||||
|
type = "filesystem";
|
||||||
|
format = "ext4";
|
||||||
|
mountpoint = "/";
|
||||||
|
mountOptions = [
|
||||||
|
"defaults"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
home = {
|
||||||
|
size = "10M";
|
||||||
|
lvm_type = "thinlv";
|
||||||
|
pool = "thinpool";
|
||||||
|
content = {
|
||||||
|
type = "filesystem";
|
||||||
|
format = "ext4";
|
||||||
|
mountpoint = "/home";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
raw = {
|
||||||
|
size = "10M";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
disk1 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/my-disk";
|
device = "/dev/my-disk";
|
||||||
content = {
|
content = {
|
||||||
@@ -10,7 +10,6 @@
|
|||||||
boot = {
|
boot = {
|
||||||
size = "1M";
|
size = "1M";
|
||||||
type = "EF02"; # for grub MBR
|
type = "EF02"; # for grub MBR
|
||||||
priority = 1; # Needs to be first partition
|
|
||||||
};
|
};
|
||||||
mdadm = {
|
mdadm = {
|
||||||
size = "100%";
|
size = "100%";
|
||||||
@@ -22,7 +21,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
vdc = {
|
disk2 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/my-disk2";
|
device = "/dev/my-disk2";
|
||||||
content = {
|
content = {
|
||||||
@@ -31,7 +30,6 @@
|
|||||||
boot = {
|
boot = {
|
||||||
size = "1M";
|
size = "1M";
|
||||||
type = "EF02"; # for grub MBR
|
type = "EF02"; # for grub MBR
|
||||||
priority = 1; # Needs to be first partition
|
|
||||||
};
|
};
|
||||||
mdadm = {
|
mdadm = {
|
||||||
size = "100%";
|
size = "100%";
|
||||||
|
|||||||
+2
-3
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
disk1 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/my-disk";
|
device = "/dev/my-disk";
|
||||||
content = {
|
content = {
|
||||||
@@ -10,7 +10,6 @@
|
|||||||
boot = {
|
boot = {
|
||||||
size = "1M";
|
size = "1M";
|
||||||
type = "EF02"; # for grub MBR
|
type = "EF02"; # for grub MBR
|
||||||
priority = 1; # Needs to be first partition
|
|
||||||
};
|
};
|
||||||
mdadm = {
|
mdadm = {
|
||||||
size = "100%";
|
size = "100%";
|
||||||
@@ -22,7 +21,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
vdc = {
|
disk2 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/my-disk2";
|
device = "/dev/my-disk2";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
device = "/dev/disk/by-id/some-disk-id";
|
device = "/dev/disk/by-id/some-disk-id";
|
||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
device = "/dev/vdb";
|
device = "/dev/vdb";
|
||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
main = {
|
||||||
device = "/dev/vdb";
|
device = "/dev/vdb";
|
||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
boot = {
|
boot = {
|
||||||
size = "1M";
|
size = "1M";
|
||||||
type = "EF02";
|
type = "EF02";
|
||||||
priority = 1; # Needs to be first partition
|
|
||||||
};
|
};
|
||||||
root = {
|
root = {
|
||||||
size = "100%";
|
size = "100%";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
disk1 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vdb";
|
device = "/dev/vdb";
|
||||||
content = {
|
content = {
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
vdc = {
|
disk2 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vdc";
|
device = "/dev/vdc";
|
||||||
content = {
|
content = {
|
||||||
|
|||||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1719082008,
|
"lastModified": 1721782431,
|
||||||
"narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=",
|
"narHash": "sha256-UNDpwjYxNXQet/g3mgRLsQ9zxrbm9j2JEvP4ijF3AWs=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "9693852a2070b398ee123a329e68f0dab5526681",
|
"rev": "4f02464258baaf54992debfd010a7a3662a25536",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
+22
-3
@@ -67,13 +67,32 @@ let
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
installer = ''
|
installer = ''
|
||||||
|
if [[ -f /sys/module/zfs/parameters/zfs_arc_max ]]; then
|
||||||
|
# We have seen `cp` run out of memory when copying the store paths and using zfs.
|
||||||
|
# Default for ARC is 1/2 of RAM, we choose 1/4 of RAM.
|
||||||
|
# Since we mostly write to the store and don't read from it, we don't need a large ARC.
|
||||||
|
# This hopefully gives zfs enough time to free up memory.
|
||||||
|
QUARTER_RAM=$(($(grep MemTotal /proc/meminfo | awk '{print $2 * 1024}') / 4))
|
||||||
|
echo "$QUARTER_RAM" > /sys/module/zfs/parameters/zfs_arc_max
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Useful for monitoring memory usage
|
||||||
|
#echo $(($(cat /sys/module/zfs/parameters/zfs_arc_max) / 1024 / 1024)) MB
|
||||||
|
#(while true; do
|
||||||
|
# ${pkgs.procps}/bin/free -h
|
||||||
|
# if [[ -f /sys/module/zfs/parameters/zfs_arc_max ]]; then ${pkgs.zfs}/bin/arcstat; fi
|
||||||
|
# ${pkgs.procps}/bin/ps -eo pid,ppid,comm,%mem,%cpu --sort=-%mem | head -n 4
|
||||||
|
# # this can be very verbose
|
||||||
|
# # ${pkgs.linuxPackages_latest.mm-tools}/bin/slabinfo
|
||||||
|
# sleep 1
|
||||||
|
#done) &
|
||||||
|
|
||||||
# populate nix db, so nixos-install doesn't complain
|
# populate nix db, so nixos-install doesn't complain
|
||||||
export NIX_STATE_DIR=${systemToInstall.config.disko.rootMountPoint}/nix/var/nix
|
export NIX_STATE_DIR=${systemToInstall.config.disko.rootMountPoint}/nix/var/nix
|
||||||
nix-store --load-db < "${closureInfo}/registration"
|
nix-store --load-db < "${closureInfo}/registration"
|
||||||
|
|
||||||
# We copy files with cp because `nix copy` seems to have a large memory leak
|
# We copy files with rsync because `nix copy` seems to have a large memory leak
|
||||||
mkdir -p ${systemToInstall.config.disko.rootMountPoint}/nix/store
|
${pkgs.rsync}/bin/rsync -rtpl --files-from=${closureInfo}/store-paths / ${systemToInstall.config.disko.rootMountPoint}
|
||||||
xargs cp --recursive --target ${systemToInstall.config.disko.rootMountPoint}/nix/store < ${closureInfo}/store-paths
|
|
||||||
|
|
||||||
${systemToInstall.config.system.build.nixos-install}/bin/nixos-install --root ${systemToInstall.config.disko.rootMountPoint} --system ${systemToInstall.config.system.build.toplevel} --keep-going --no-channel-copy -v --no-root-password --option binary-caches ""
|
${systemToInstall.config.system.build.nixos-install}/bin/nixos-install --root ${systemToInstall.config.disko.rootMountPoint} --system ${systemToInstall.config.system.build.toplevel} --keep-going --no-channel-copy -v --no-root-password --option binary-caches ""
|
||||||
umount -Rv ${systemToInstall.config.disko.rootMountPoint}
|
umount -Rv ${systemToInstall.config.disko.rootMountPoint}
|
||||||
|
|||||||
+2
-5
@@ -86,7 +86,7 @@ let
|
|||||||
tsp-config = tsp-generator.config testConfigBooted;
|
tsp-config = tsp-generator.config testConfigBooted;
|
||||||
num-disks = builtins.length (lib.attrNames testConfigBooted.disko.devices.disk);
|
num-disks = builtins.length (lib.attrNames testConfigBooted.disko.devices.disk);
|
||||||
|
|
||||||
installed-system = { config, ... }: {
|
installed-system = { ... }: {
|
||||||
imports = [
|
imports = [
|
||||||
(lib.optionalAttrs (testMode == "direct") tsp-config)
|
(lib.optionalAttrs (testMode == "direct") tsp-config)
|
||||||
(lib.optionalAttrs (testMode == "module") {
|
(lib.optionalAttrs (testMode == "module") {
|
||||||
@@ -101,14 +101,11 @@ let
|
|||||||
# config for tests to make them run faster or work at all
|
# config for tests to make them run faster or work at all
|
||||||
documentation.enable = false;
|
documentation.enable = false;
|
||||||
hardware.enableAllFirmware = lib.mkForce false;
|
hardware.enableAllFirmware = lib.mkForce false;
|
||||||
boot.initrd.preDeviceCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
|
boot.initrd.preDeviceCommands = ''
|
||||||
echo -n 'secretsecret' > /tmp/secret.key
|
echo -n 'secretsecret' > /tmp/secret.key
|
||||||
'';
|
'';
|
||||||
boot.initrd.systemd.contents."/tmp/secret.key".text = "secretsecret";
|
|
||||||
boot.consoleLogLevel = lib.mkForce 100;
|
boot.consoleLogLevel = lib.mkForce 100;
|
||||||
boot.loader.systemd-boot.enable = lib.mkDefault efi;
|
boot.loader.systemd-boot.enable = lib.mkDefault efi;
|
||||||
|
|
||||||
boot.initrd.systemd.enable = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
installed-system-eval = eval-config {
|
installed-system-eval = eval-config {
|
||||||
|
|||||||
+13
-1
@@ -45,7 +45,19 @@ in
|
|||||||
};
|
};
|
||||||
priority = lib.mkOption {
|
priority = lib.mkOption {
|
||||||
type = lib.types.int;
|
type = lib.types.int;
|
||||||
default = if (partition.config.size or "" == "100%") then 9001 else 1000;
|
default = if partition.config.size or "" == "100%" then
|
||||||
|
9001
|
||||||
|
else if partition.config.type == "EF02" then
|
||||||
|
# Boot partition should be created first, because some BIOS implementations require it.
|
||||||
|
# Priority defaults to 100 here to support any potential use-case for placing partitions prior to EF02
|
||||||
|
100
|
||||||
|
else
|
||||||
|
1000;
|
||||||
|
defaultText = ''
|
||||||
|
1000: normal partitions
|
||||||
|
9001: partitions with 100% size
|
||||||
|
100: boot partitions (EF02)
|
||||||
|
'';
|
||||||
description = "Priority of the partition, smaller values are created first";
|
description = "Priority of the partition, smaller values are created first";
|
||||||
};
|
};
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
|
|||||||
+20
-5
@@ -1,4 +1,10 @@
|
|||||||
{ config, options, lib, diskoLib, ... }:
|
{ config, options, lib, diskoLib, ... }:
|
||||||
|
let
|
||||||
|
# Load kernel modules to ensure device mapper types are available
|
||||||
|
kernelModules = lib.filter (x: x != "") (map
|
||||||
|
(lv: lib.optionalString (lv.lvm_type != null && lv.lvm_type != "thinlv") "dm-${lv.lvm_type}")
|
||||||
|
(lib.attrValues config.lvs));
|
||||||
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
@@ -21,7 +27,7 @@
|
|||||||
};
|
};
|
||||||
priority = lib.mkOption {
|
priority = lib.mkOption {
|
||||||
type = lib.types.int;
|
type = lib.types.int;
|
||||||
default = if (lib.hasInfix "100%" lv.config.size) then 9001 else 1000;
|
default = (if lv.config.lvm_type == "thin-pool" then 501 else 1000) + (if lib.hasInfix "100%" lv.config.size then 251 else 0);
|
||||||
defaultText = lib.literalExpression ''
|
defaultText = lib.literalExpression ''
|
||||||
if (lib.hasInfix "100%" lv.config.size) then 9001 else 1000
|
if (lib.hasInfix "100%" lv.config.size) then 9001 else 1000
|
||||||
'';
|
'';
|
||||||
@@ -33,7 +39,7 @@
|
|||||||
};
|
};
|
||||||
lvm_type = lib.mkOption {
|
lvm_type = lib.mkOption {
|
||||||
# TODO: add raid10
|
# TODO: add raid10
|
||||||
type = lib.types.nullOr (lib.types.enum [ "mirror" "raid0" "raid1" "raid4" "raid5" "raid6" ]); # TODO add all lib.types
|
type = lib.types.nullOr (lib.types.enum [ "mirror" "raid0" "raid1" "raid4" "raid5" "raid6" "thin-pool" "thinlv" ]); # TODO add all lib.types
|
||||||
default = null; # maybe there is always a default type?
|
default = null; # maybe there is always a default type?
|
||||||
description = "LVM type";
|
description = "LVM type";
|
||||||
};
|
};
|
||||||
@@ -42,6 +48,11 @@
|
|||||||
default = [ ];
|
default = [ ];
|
||||||
description = "Extra arguments";
|
description = "Extra arguments";
|
||||||
};
|
};
|
||||||
|
pool = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = null;
|
||||||
|
description = "Name of pool LV that this LV belongs to";
|
||||||
|
};
|
||||||
content = diskoLib.partitionType { parent = config; device = "/dev/${config.name}/${lv.config.name}"; };
|
content = diskoLib.partitionType { parent = config; device = "/dev/${config.name}/${lv.config.name}"; };
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
@@ -67,6 +78,7 @@
|
|||||||
sortedLvs = lib.sort (a: b: a.priority < b.priority) (lib.attrValues config.lvs);
|
sortedLvs = lib.sort (a: b: a.priority < b.priority) (lib.attrValues config.lvs);
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
|
${lib.concatMapStringsSep "\n" (k: ''modprobe "${k}"'') kernelModules}
|
||||||
readarray -t lvm_devices < <(cat "$disko_devices_dir"/lvm_${config.name})
|
readarray -t lvm_devices < <(cat "$disko_devices_dir"/lvm_${config.name})
|
||||||
if ! vgdisplay "${config.name}" >/dev/null; then
|
if ! vgdisplay "${config.name}" >/dev/null; then
|
||||||
vgcreate ${config.name} \
|
vgcreate ${config.name} \
|
||||||
@@ -76,9 +88,12 @@
|
|||||||
if ! lvdisplay '${config.name}/${lv.name}'; then
|
if ! lvdisplay '${config.name}/${lv.name}'; then
|
||||||
lvcreate \
|
lvcreate \
|
||||||
--yes \
|
--yes \
|
||||||
${if lib.hasInfix "%" lv.size then "-l" else "-L"} ${lv.size} \
|
${if (lv.lvm_type == "thinlv") then "-V"
|
||||||
|
else if lib.hasInfix "%" lv.size then "-l" else "-L"} \
|
||||||
|
${lv.size} \
|
||||||
-n ${lv.name} \
|
-n ${lv.name} \
|
||||||
${lib.optionalString (lv.lvm_type != null) "--type=${lv.lvm_type}"} \
|
${lib.optionalString (lv.lvm_type == "thinlv") "--thinpool=${lv.pool}"} \
|
||||||
|
${lib.optionalString (lv.lvm_type != null && lv.lvm_type != "thinlv") "--type=${lv.lvm_type}"} \
|
||||||
${toString lv.extraArgs} \
|
${toString lv.extraArgs} \
|
||||||
${config.name}
|
${config.name}
|
||||||
fi
|
fi
|
||||||
@@ -110,7 +125,7 @@
|
|||||||
_config = lib.mkOption {
|
_config = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default =
|
default = [ { boot.initrd.kernelModules = kernelModules; } ] ++
|
||||||
map
|
map
|
||||||
(lv: [
|
(lv: [
|
||||||
(lib.optional (lv.content != null) lv.content._config)
|
(lib.optional (lv.content != null) lv.content._config)
|
||||||
|
|||||||
+30
-2
@@ -59,10 +59,38 @@
|
|||||||
# important to prevent accidental shadowing of mount points
|
# important to prevent accidental shadowing of mount points
|
||||||
# since (create order != mount order)
|
# since (create order != mount order)
|
||||||
# -p creates parents automatically
|
# -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
|
if ! zfs get type ${config._name} >/dev/null 2>&1; then
|
||||||
zfs create -up ${config._name} \
|
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
|
fi
|
||||||
'';
|
'';
|
||||||
} // { readOnly = false; };
|
} // { readOnly = false; };
|
||||||
|
|||||||
+3
-1
@@ -62,7 +62,9 @@
|
|||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name})
|
readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name})
|
||||||
if zpool list '${config.name}'; then
|
# Try importing the pool without mounting anything if it exists.
|
||||||
|
# This allows us to set mounpoints.
|
||||||
|
if zpool import -N -f '${config.name}' || zpool list '${config.name}'; then
|
||||||
echo "not creating zpool ${config.name} as a pool with that name already exists" >&2
|
echo "not creating zpool ${config.name} as a pool with that name already exists" >&2
|
||||||
else
|
else
|
||||||
continue=1
|
continue=1
|
||||||
|
|||||||
+13
-8
@@ -98,16 +98,21 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = lib.mkIf (cfg.devices.disk != { }) {
|
config = {
|
||||||
system.build = (cfg.devices._scripts { inherit pkgs; checked = cfg.checkScripts; }) // {
|
system.build = lib.mapAttrs (name: cfg:
|
||||||
|
if cfg.devices.disk == {} then
|
||||||
# we keep these old outputs for compatibility
|
throw ''
|
||||||
disko = builtins.trace "the .disko output is deprecated, please use .diskoScript instead" (cfg.devices._scripts { inherit pkgs; }).diskoScript;
|
Cannot provide ${name} without disks configured.
|
||||||
diskoNoDeps = builtins.trace "the .diskoNoDeps output is deprecated, please use .diskoScriptNoDeps instead" (cfg.devices._scripts { inherit pkgs; }).diskoScriptNoDeps;
|
Current value of disko.devices.disk is empty.
|
||||||
|
Set up a disk configuration according to:
|
||||||
|
https://github.com/nix-community/disko/blob/master/docs/quickstart.md#step-1-choose-a-disk-configuration
|
||||||
|
''
|
||||||
|
else cfg)
|
||||||
|
(cfg.devices._scripts { inherit pkgs; checked = cfg.checkScripts; } // {
|
||||||
diskoImages = diskoLib.makeDiskImages {
|
diskoImages = diskoLib.makeDiskImages {
|
||||||
nixosConfig = args;
|
nixosConfig = args;
|
||||||
};
|
};
|
||||||
|
|
||||||
diskoImagesScript = diskoLib.makeDiskImagesScript {
|
diskoImagesScript = diskoLib.makeDiskImagesScript {
|
||||||
nixosConfig = args;
|
nixosConfig = args;
|
||||||
};
|
};
|
||||||
@@ -121,7 +126,7 @@ in
|
|||||||
extraSystemConfig = cfg.tests.extraConfig;
|
extraSystemConfig = cfg.tests.extraConfig;
|
||||||
extraTestScript = cfg.tests.extraChecks;
|
extraTestScript = cfg.tests.extraChecks;
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
|
|
||||||
|
|
||||||
# we need to specify the keys here, so we don't get an infinite recursion error
|
# we need to specify the keys here, so we don't get an infinite recursion error
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
{ stdenvNoCC, makeWrapper, lib, path, nix, coreutils }:
|
{ stdenvNoCC, makeWrapper, lib, path, nix, coreutils, nixos-install-tools }:
|
||||||
|
|
||||||
stdenvNoCC.mkDerivation (finalAttrs: {
|
stdenvNoCC.mkDerivation (finalAttrs: {
|
||||||
name = "disko";
|
name = "disko";
|
||||||
@@ -14,7 +14,7 @@ stdenvNoCC.mkDerivation (finalAttrs: {
|
|||||||
sed -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" "$i" > "$out/bin/$i"
|
sed -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" "$i" > "$out/bin/$i"
|
||||||
chmod 755 "$out/bin/$i"
|
chmod 755 "$out/bin/$i"
|
||||||
wrapProgram "$out/bin/$i" \
|
wrapProgram "$out/bin/$i" \
|
||||||
--prefix PATH : ${lib.makeBinPath [ nix coreutils ]} \
|
--prefix PATH : ${lib.makeBinPath [ nix coreutils nixos-install-tools ]} \
|
||||||
--prefix NIX_PATH : "nixpkgs=${path}"
|
--prefix NIX_PATH : "nixpkgs=${path}"
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{ pkgs ? import <nixpkgs> { }
|
||||||
|
, diskoLib ? pkgs.callPackage ../lib { }
|
||||||
|
}:
|
||||||
|
diskoLib.testLib.makeDiskoTest {
|
||||||
|
inherit pkgs;
|
||||||
|
name = "lvm-thin";
|
||||||
|
disko-config = ../example/lvm-thin.nix;
|
||||||
|
extraTestScript = ''
|
||||||
|
machine.succeed("mountpoint /home");
|
||||||
|
'';
|
||||||
|
}
|
||||||
Reference in new issue
Block a user