Grub Theme Help

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.

1 Like

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 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:

boot.loader.grub.theme = pkgs.stdenv.mkDerivation {
  pname = "distro-grub-themes";
  version = "3.1";
  src = pkgs.fetchFromGitHub {
    owner = "AdisonCavani";
    repo = "distro-grub-themes";
    rev = "v3.1";
    hash = "sha256-ZcoGbbOMDDwjLhsvs77C7G7vINQnprdfI37a9ccrmPs=";
  installPhase = "cp -r customize/nixos $out";
1 Like

Thank you tejing for the help!

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.

1 Like

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).

1 Like

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.

1 Like

The nix ecosystem is unfortunately somewhat lacking in good documentation, but there are still some good resources:

  • The NixOS website has a nix language basics guide, which is good for getting you initially oriented.
  • The Nix Manual is a good reference for the syntax and builtins of the nix language.
  • The Nixpkgs Manual is a good reference for the various helper functions provided by nixpkgs, such as stdenv.mkDerivation which I used here.
  • The NixOS Manual is a good reference for the nix code that makes NixOS work, such as the module system which processes configuration.nix.
  • The Nix Pills are a good deep-dive into how nix is working underneath, and how and why some of the helper functions in nixpkgs were created.

There are further guides and other resources listed on the NixOS website.

1 Like

Thank you for all of the resources. These are very good to learn the Nix language and NixOS.

Sorry but I think this necrobump worths.

        boot.loader.grub.theme = "${
            (pkgs.fetchFromGitHub {
              owner = "13atm01";
              repo = "GRUB-Theme";
              rev = "95bcc240162bce388ac2c0bec628b2aaa56e6cb8";
              sha256 = "0xnx82fdyjqw89qmacwmlva9lis3zs8b0l1xi67njpypjy29sdnc";
          }/Touhou\ Project/Touhou-project/";

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,


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.