I’m relatively new to NixOS and using it on a Dell XPS with good success so far. While trying to customize the OS one item I would like to figure out is how to modify the GRUB theme.
Currently, my system is using GNOME with GRUB2 and what I can find in regard to customizing GRUB is the nixos-grub2-theme pkg but no information or tutorials on how to use it.
I also found this thread (Breeze Grub Thread)) on using a Breeze GRUB theme (looks to have been packaged for 22.05 but not currently in 22.11). Unfortunately, it doesn’t show much in the way of using an external theme that is not packaged in NixOS like: Distro Grub Theme.
I don’t know much about Flakes so I was wondering what options there are to change the GRUB theme and if a Flake would be needed or if the nixos-grub2-theme option is possible with a custom theme like the one above.
Any help on understanding this would be greatly appreciated.
A common misconception these days is that Flakes are somehow integral to everything. They’re just a more modular way of packaging nix code. What can be done with them can always be done without them.
Set boot.loader.grub.theme (you can find options like this yourself via search.nixos.org or with man configuration.nix).
There’s a decent chance something like a grub theme doesn’t even really have a build step and amounts to copying some files around. In that case it should be quite easy to package.
In fact, I went ahead and just did it. Add this to your configuration.nix and it should do the trick:
For getting the files and packaging it to obtain the files from the theme repo, that derivation looks great.
Looking into the github repo for that theme pack it has a whole bunch of different .tar’s depending on the them wanted. The standard/manual setup in Ubuntu or another Linux distro is to choose a theme and update the grub-theme location to the .txt in that theme (which sits somewhere on your main drive).
Since this set of themes has a whole pack of different ones how would we choose the Nixos Theme .txt from it in the boot.loader.grub.theme to set and update grub?
Am I understanding the installPhase correctly in that the entire repo will be available under “customize/nixos” on our system? Trying to figure out how to get from that derivation to setting boot.loader.grub.theme to the “Nixos Theme” in the repo.
Actually, I avoided the .tars because they turned out to not have the .txt in them and that seemed important…
customize/nixos is already picking it.
No, customize/nixos is the source directory of the copy (relative to the github repo root), not the target. The theme will actually be in a directory in the nix store with some big long hash in the name… but it doesn’t actually matter where, since providing the derivation to the boot.loader.grub.theme option takes care of copying it to /boot and hooking it into grub for you. There’s no manual step (that’s kinda the point with NixOS).
Thank you for the response and explanation. That clear things up a lot actually!
I dug into the github source directory and understood the installphase step thanks to your explanation. It makes a lot more sense now.
I was able to use the derivation you made to successfully update grub without any issues and it boots with the expected theme.
Do you have an recommendations on sources of information to learn how to create derivations and understanding how they work? I’d like to be able to use them to package things that may not be already available.
Not bad, but I like my version better. It is a little more code, but it avoids keeping a copy of the entire repo commit in the nix store in perpetuity. Something that can matter a fair amount when the repo is full of media files. My version could, however, be streamlined using pkgs.runCommand.
So, for example,
"${bar}/baz"
keeps a link to a copy of all of bar, while
pkgs.runCommand "barbaz" "cp -r ${bar}/baz $out"
keeps only a copy of the ${bar}/baz directory.
(The "barbaz" bit is just to set the part of the nix store path that comes after the hash. It only matters to human navigability and setting a file extension when the output is a file instead of a directory.)
My version does, however, have a downside in that it may need to re-download the git repo unnecessarily at times (basically whenever stdenv changes), which yours would not. Tradeoffs, tradeoffs.
Also, btw, the parentheses inside the ${...} construct in your version are redundant.
I think doing this with a flake could be a better option: sha256 is handled automatically and there must be building function already somewhere in nixpkgs…(hard guess) that will build the stuff the up for you.
I thought I was using grub ut I was on systemd boot, ignore this
having a weird issue where the option boot.loader.grub.theme doesnt seem to be getting evaluated or used at all. I tried your code snippet and the example on man configuration.nix: boot.loader.grub.theme = "${pkgs.libsForQt5.breeze-grub}/grub/themes/breeze"; and neither seem to do anything when i rebuild-switch
edit: yeah, boot.loader.grub.theme = pkgs.does.not.exist; builds with no problem