Skip to content

nixos-generate-config: does not generate working config for LVM raid setup and LUKS-on-LVM #432258

@Soveu

Description

@Soveu

So, I have this unique partition setup:

$ lsblk
nvme1n1                                            259:0    0 953.9G  0 disk
└─main_storage_v2-main_storage_v2--fast_rimage_0   254:1    0 953.8G  0 lvm
  └─main_storage_v2-main_storage_v2--fast          254:3    0   1.9T  0 lvm   /nix/store
                                                                              /
nvme0n1                                            259:1    0   3.6T  0 disk
├─nvme0n1p1                                        259:2    0     2G  0 part  /boot
├─nvme0n1p3                                        259:3    0 953.9G  0 part
│ └─main_storage_v2-main_storage_v2--fast_rimage_1 254:2    0 953.8G  0 lvm
│   └─main_storage_v2-main_storage_v2--fast        254:3    0   1.9T  0 lvm   /nix/store
│                                                                             /
└─nvme0n1p4                                        259:4    0   2.7T  0 part
  └─main_storage_v2-main_storage_v2--home          254:0    0   2.7T  0 lvm
    └─luks-cafc4a9a-36a4-42cc-973b-986f9f5aaca7    254:4    0   2.7T  0 crypt /home

From partition perspective, this looks like this:

  • /home is on a LUKS partition, which is on main_storage_v2-home LVM volume.
    This LVM volume is placed solely on the larger NVME drive (nvme0n1)
  • /boot is also placed on the larger NVME drive
  • / is placed on main_storage_v2-fast, which is spread on both NVME drives (nvme0n1 and nvme1n1)

nixos-generate-config generated this hardware-configuration.nix for the setup:

# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "thunderbolt" "usbhid" "usb_storage" "sd_mod" ];
  boot.initrd.kernelModules = [ "dm-snapshot" ];
  boot.kernelModules = [ "kvm-amd" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/mapper/main_storage_v2-main_storage_v2--fast";
      fsType = "ext4";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/0A49-7AE5";
      fsType = "vfat";
      options = [ "fmask=0077" "dmask=0077" ];
    };

  fileSystems."/home" =
    { device = "/dev/mapper/luks-cafc4a9a-36a4-42cc-973b-986f9f5aaca7";
      fsType = "ext4";
    };

  boot.initrd.luks.devices."luks-cafc4a9a-36a4-42cc-973b-986f9f5aaca7".device = "/dev/mapper/main_storage_v2-main_storage_v2--home";

There are two issues.

LVM raid kernel modules not included

Besides the fact, that I had to create a custom ISO with dm-raid, the config was generated without it and the needed dependencies. Currently I'm running with this:

boot.initrd.kernelModules = [ "dm-raid" "dm-mod" "md-mod" "raid456" "raid0" ];

It "just" works for me, I might try removing the unnecessary ones in the future. Just dm-raid is not enough:

device-mapper: table: 254:4: raid: Failed to run raid array (-EINVAL)

LUKS-on-LVM

Usually it is done the other way around, so the preLVM = true default is reasonable, however, the script failed to detect that it is not the case and it should generate configuration with preLVM = false, for example

boot.initrd.luks.devices."luks-cafc4a9a-36a4-42cc-973b-986f9f5aaca7" = {
  preLVM = false;
  device = "/dev/mapper/main_storage_v2-main_storage_v2--home";
};

Configuration builds, but does not boot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken6.topic: nixosIssues or PRs affecting NixOS modules, or package usability issues specific to NixOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions