Hi!
I’ve wanted to modify the GRUB install script for my installation (automatic signing of files, cosmetic changes in configuration names etc) but I’ve stumbled into an issue I cannot solve.
The installation hook is defined in system.build.installBootLoader
in nixpkgs, precisely at this line:
https://github.com/NixOS/nixpkgs/blob/cdd8031fca5169c2ff952e57e2c81ccd5e9fde03/nixos/modules/system/boot/loader/grub/grub.nix#L704
As you can see the actual perl script is defined in a let, which does not easily make it replaceable. That’s not a huge deal though, I’ve redefined my own in a let block which gathers nixpkgs’s from GitHub and applies a few patches to it.
Once this is done I’d need to replace the perl script inside installBootLoader
.
I’ve already written an overrideAttrs
which can do that inline but the issue is I am now dependent on the old installBootLoader as it is a bit more than a perl wrapper, namely it calls it with an xml generated in a let (urgh again) which contains all the arguments passed to the grub module and I’d rather avoid having to redefine the entire grub.nix if possible.
This seems like the perfect usage for overlays, but I couldn’t figure out for the love of all that exists if it is even possible to overlay something in system
.
The overlay definition would look akin to something like that:
system.build.installBootLoader = super.system.build.installBootLoader.overrideAttrs (oldAttrs: {
# this absolute monstrosity is written within builtins and basically
# splits a string before and after .*pl and puts it back together but
# with a custom perl script
# basically, in a pseudo language that makes sense:
# split = split_text(text, ".*/bin/perl")
# text = split[1][0] + " ${install-grub-pl} " + split[4]
text = (builtins.elemAt (builtins.elemAt (builtins.split
"(^.*/bin/perl)|( .*\\.pl) " oldAttrs.text) 1) 0) + " ${install-grub-pl} "
+ builtins.elemAt (builtins.split "(^.*/bin/perl)|( .*\\.pl) "
oldAttrs.text) 4;
});
I switched to builtins only to avoid making a new package definition while trying to get this working, any cleaner way to do that would be very much appreciated.
Any clue on how I should go around at solving this issue with minimal overriding? I’d much rather avoid having my own nixpkgs fork and/or grub fork for this specific use case.