Overriding default use of ext4 for nixos-rebuild build-vm

Howdy –

I’m trying to test a new Nix module for some btrfs-only software (specifically, beesd – a block-level deduplicator for btrfs, as opposed to the existing file-level deduplicator already in the repo).

When I run nixos-rebuild build-vm, the resulting guest has an ext4 root. This is true even when my nixos-config provided is passed as follows:

{ config, pkgs, ... }: {
  # attempting to override ext4-specific configuration from https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/qemu-vm.nix#L416-L430
  boot.initrd.extraUtilsCommands = ''
    copy_bin_and_libs ${pkgs.btrfs-progs}/bin/mkfs.btrfs
  '';
  boot.initrd.postDeviceCommands = ''
    mkfs.btrfs -L vmdisk ${config.virtualisation.bootDevice}
  '';
  fileSystems."/" = { label = "vmdisk"; fsType = "btrfs"; };
  users.users.root.initialPassword = "root";
  ## commented for public post
  ## to test this, you need the nixpkgs branch at https://github.com/charles-dyfis-net/nixpkgs/commit/33267abde4c60e3feba97205d8b78e8b86c0f75e
  #services.beesd.filesystems."root" = { # FIXME: Would have used the spec as the key, if we knew how to do systemd escaping from nix
  #  spec = "LABEL=vmdisk";
  #  hashTableSizeMB = 256;
  #};
  system.stateVersion = "18.03";
}

Is there a reasonable override mechanism?

(BTW, while I’ll be submitting the module at https://github.com/charles-dyfis-net/nixpkgs/commit/33267abde4c60e3feba97205d8b78e8b86c0f75e for formal review as part of a pull request once it’s better-tested, any feedback on offer while it’s in this earlier stage would be very much appreciated).

1 Like

So, I got this working. There were effectively two missing pieces:

  • The mkfs.btrfs needed to be forced (or preceded by a wipefs) to overwrite results of the prior (hardcoded) mkfs.ext3.
  • boot.initrd.kernelModules needed to be defined.

Thus, the end result looks like the following:

{ config, pkgs, ... }: {
  # attempting to override ext4-specific configuration from https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/qemu-vm.nix#L416-L430
  boot.initrd.extraUtilsCommands = ''
    copy_bin_and_libs ${pkgs.btrfs-progs}/bin/mkfs.btrfs
    copy_bin_and_libs ${pkgs.utillinux}/bin/wipefs
  '';
  boot.initrd.kernelModules = [ "btrfs" ];
  boot.initrd.postDeviceCommands = ''
    wipefs -a ${config.virtualisation.bootDevice}
    mkfs.btrfs -f -L vmdisk ${config.virtualisation.bootDevice}
  '';
  users.users.root.initialPassword = "root";
  services.beesd.filesystems."root" = { # FIXME: Would have used the spec as the key, if we knew how to do systemd escaping from nix
    spec = "LABEL=vmdisk";
    hashTableSizeMB = 256;
  };
  system.stateVersion = "18.03";
}
3 Likes