Os-prober with btrfs patch on NixOS

I dualboot NixOS and Arch. Arch is installed on a btrfs partition with subvolumes. Grub with the default os-prober does detect Arch but it gets the path wrong ignoring the subvolume (/boot instead of /@/boot).

After some research I found os-prober-btrfs for Arch which fixes the problem. But I’m a noob and have no idea how to package it for Nix. How do I do it? Or maybe there’s another way of solving this problem?

1 Like

Hi,

The link you gave looks like a fork of os-prober with a compatible CLI, so making an overlay that replaces os-prober by os-prober.overrideAttrs { src = /* the fork * /; } might work.

But before you attempt this, is switching to uefi boot and systemd-boot possible ? then Arch and NixOS won’t fight for boot entries.

2 Likes

Thank you for giving the direction!

I am already using uefi and don’t like systemd so I continued with os-prober-btrfs.

The Arch package turned out to just apply a bunch of patches to the main repository so I ended up making an overlay.

First you need to create a file with the overlay itself (i.e. os-prober-btrfs.nix):

os-prober-btrfs: final: prev: {
  os-prober = prev.os-prober.overrideAttrs (previousAttrs: {
    patches = (previousAttrs.patches or []) ++
    map (x: os-prober-btrfs + x) [
      /os-prober-frugalware.diff
      /os-prober-mdraidfix.patch
      /os-prober-btrfsfix.patch
      /os-prober-bootpart-name-fix.patch
      /os-prober-mounted-partitions-fix.patch
      /os-prober-factor-out-logger.patch
      /os-prober-factored-logger-efi-fix.patch
      /os-prober-umount-fix.patch
      /os-prober-grub2-parsefix.patch
      /os-prober-grepfix.patch
      /os-prober-gentoo-fix.patch
      /os-prober-grub2-mount-workaround.patch
      /fix-blkid-path.patch
      /grub-initrd-generation-fix.diff
      /grub-initrd-generation-fix.hook.diff
    ];
  });
}

Then in flake.nix you add the repository url to inputs and apply the overlay in outputs like so:

{
  inputs = {
    ...
    os-prober-btrfs = {
      url = "git+https://aur.archlinux.org/os-prober-btrfs?ref=HEAD";
      flake = false;
    };
    ...
  };

  outputs = { os-prober-btrfs, nixpkgs, ... }: {
    nixosConfigurations = {
      foo = nixpkgs.lib.nixosSystem {
        ...
        specialArgs = {
          pkgs = import inputs.nixpkgs { 
            system = "x86_64-linux"; 
            overlays = [ 
               (import ../os-prober-btrfs.nix os-prober-btrfs) 
            ];
          };
        };
        ...
      };
    };
  };
};