# Grub Theme Help

**URL:** https://discourse.nixos.org/t/grub-theme-help/24384
**Category:** Help
**Created:** [January 2, 2023, 10:42pm UTC](https://discourse.nixos.org/t/grub-theme-help/24384 "2023-01-02T22:42:48Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![ZerogGravitas23](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/z/977dab/32.png) [@ZerogGravitas23](https://discourse.nixos.org/u/ZerogGravitas23)
#### Post date: [January 2, 2023, 10:42pm UTC](https://discourse.nixos.org/t/grub-theme-help/24384/1 "2023-01-02T22:42:48Z")

</div>

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)](https://discourse.nixos.org/t/how-to-apply-the-breeze-grub-theme/4341)) 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](https://www.gnome-look.org/p/1482847).

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.

---

<div class="post-metadata">

### Author: ![tejing](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tejing/32/4566_2.png) [@tejing](https://discourse.nixos.org/u/tejing)
#### Post date: [January 3, 2023, 3:44am UTC](https://discourse.nixos.org/t/grub-theme-help/24384/2 "2023-01-03T03:44:18Z")

</div>

> [@ZerogGravitas23](#):
>
> 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.

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.

> [@ZerogGravitas23](#):
>
> 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.

Set `boot.loader.grub.theme` (you can find options like this yourself via [search.nixos.org](http://search.nixos.org) or with `man configuration.nix`).

> [@ZerogGravitas23](#):
>
> Unfortunately, it doesn’t show much in the way of using an external theme that is not packaged in NixOS

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:

```auto
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";
};

```

---

<div class="post-metadata">

### Author: ![ZerogGravitas23](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/z/977dab/32.png) [@ZerogGravitas23](https://discourse.nixos.org/u/ZerogGravitas23)
#### Post date: [January 5, 2023, 9:52pm UTC](https://discourse.nixos.org/t/grub-theme-help/24384/3 "2023-01-05T21:52:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![tejing](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tejing/32/4566_2.png) [@tejing](https://discourse.nixos.org/u/tejing)
#### Post date: [January 5, 2023, 10:06pm UTC](https://discourse.nixos.org/t/grub-theme-help/24384/4 "2023-01-05T22:06:33Z")

</div>

> [@ZerogGravitas23](#):
>
> 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).

Actually, I avoided the `.tar`s because they turned out to not have the `.txt` in them and that seemed important…

> [@ZerogGravitas23](#):
>
> 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?

`customize/nixos` is already picking it.

> [@ZerogGravitas23](#):
>
> 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.

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

---

<div class="post-metadata">

### Author: ![ZerogGravitas23](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/z/977dab/32.png) [@ZerogGravitas23](https://discourse.nixos.org/u/ZerogGravitas23)
#### Post date: [January 7, 2023, 8:19pm UTC](https://discourse.nixos.org/t/grub-theme-help/24384/5 "2023-01-07T20:19:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![tejing](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tejing/32/4566_2.png) [@tejing](https://discourse.nixos.org/u/tejing)
#### Post date: [January 8, 2023, 12:16am UTC](https://discourse.nixos.org/t/grub-theme-help/24384/6 "2023-01-08T00:16:48Z")

</div>

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](https://nixos.org/guides/nix-language.html), which is good for getting you initially oriented.
- [The Nix Manual](https://nixos.org/manual/nix/stable/) is a good reference for the syntax and builtins of the nix language.
- [The Nixpkgs Manual](https://nixos.org/manual/nixpkgs/stable) is a good reference for the various helper functions provided by nixpkgs, such as `stdenv.mkDerivation` which I used here.
- [The NixOS Manual](https://nixos.org/manual/nixos/stable) is a good reference for the nix code that makes NixOS work, such as the module system which processes `configuration.nix`.
- [The Nix Pills](https://nixos.org/guides/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](https://nixos.org/learn.html).

---

<div class="post-metadata">

### Author: ![ZerogGravitas23](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/z/977dab/32.png) [@ZerogGravitas23](https://discourse.nixos.org/u/ZerogGravitas23)
#### Post date: [January 13, 2023, 2:54pm UTC](https://discourse.nixos.org/t/grub-theme-help/24384/7 "2023-01-13T14:54:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![wnxkiv85](https://discourse.nixos.org/user_avatar/discourse.nixos.org/wnxkiv85/32/7387_2.png) [@wnxkiv85](https://discourse.nixos.org/u/wnxkiv85)
#### Post date: [June 30, 2023, 1:26am UTC](https://discourse.nixos.org/t/grub-theme-help/24384/8 "2023-06-30T01:26:48Z")

</div>

Sorry but I think this necrobump worths.

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

```

---

<div class="post-metadata">

### Author: ![tejing](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tejing/32/4566_2.png) [@tejing](https://discourse.nixos.org/u/tejing)
#### Post date: [June 30, 2023, 1:51am UTC](https://discourse.nixos.org/t/grub-theme-help/24384/9 "2023-06-30T01:51:52Z")

</div>

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,

```nix
"${bar}/baz"

```

keeps a link to a copy of all of `bar`, while

```nix
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.

---

<div class="post-metadata">

### Author: ![woodenAllen](https://discourse.nixos.org/user_avatar/discourse.nixos.org/woodenallen/32/28769_2.png) [@woodenAllen](https://discourse.nixos.org/u/woodenAllen)
#### Post date: [September 4, 2024, 6:57pm UTC](https://discourse.nixos.org/t/grub-theme-help/24384/10 "2024-09-04T18:57:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [September 4, 2024, 7:10pm UTC](https://discourse.nixos.org/t/grub-theme-help/24384/11 "2024-09-04T19:10:04Z")

</div>

> [@woodenAllen](#):
>
> there must be building function already somewhere in nixpkgs

Yes, it’s called mkDerivation, and it was used above.

> [@woodenAllen](#):
>
> I think doing this with a flake could be a better option:

You’re not really saving much effort there; if anything it’s even more boilerplate. And flakes are really for nix code, not random files.

If you want tooling to manages hashes for you when using git repos, see `npins` or `nvfetcher`.

---

<div class="post-metadata">

### Author: ![jaymehta-g](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jaymehta-g/32/28545_2.png) [@jaymehta-g](https://discourse.nixos.org/u/jaymehta-g)
#### Post date: [September 28, 2024, 8:49pm UTC](https://discourse.nixos.org/t/grub-theme-help/24384/12 "2024-09-28T20:49:51Z")

</div>

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