You can now rebuild your system: `sudo nixos-rebuild switch --flake .`.
## Check that your machine is ready for secure-boot environment
After you rebuild your system, check `sudo sbctl verify` output. You should see it report all of your boot entries as
signed.
Note that files ending with `bzImage.efi` do not need to be signed.
### Manually sign an image
In case you'd ever need to do so, it is possible to sign an image manually with `sbctl`. To do so, you can run:
```shell
sbctl sign -s /boot/my_image.efi
```
The `-s` flag means save. This makes sure the files will be automatically re-signed when we update. (List of files to
re-sign will be stored in the secure boot database, in `/etc/secureboot`)
Note that you shouldn't really need to use this.
## Enabling secure boot
Now that NixOS is ready for secure-boot, we will set up firmware. At the end of this section, Secure Boot will be enabled on your system and your firmware will only boot binaries that are signed with your keys.
### Enter Setup mode
To allow us to upload new signing keys into the UEFI firmware, we will need to enter "setup mode". This should be
possible by going to the Secure Boot category in your UEFI settings, and clicking on Delete/Clear certificates, or
there could even be a "Setup Mode" option directly.
This option may not be available without also enabling secure boot. This is fine, while in setup mode, the secure
boot checks will not be performed.
You can now save the settings and reboot.
Once booted, to check that you really are in Setup Mode, run:
```shell
sudo sbctl status
```
### Enroll the new keys
You will now have to enroll your new keys to activate Secure Boot.
```shell
sudo sbctl enroll-keys -m
```
> [!NOTE]
> The `-m` option (also known as `--microsoft`) will make sure to also include the Microsoft
> signing keys. This is required by most motherboards, not using it could brick your device.
This should automatically enable secure boot in user mode for you. You can now reboot the system.
### Make sure it worked
To check that you really are using secure-boot, you can run
```shell
bootctl status
```
It should report `Secure Boot: enabled (user)`.
## Why bother?
As I mentioned, secure boot can be bypassed if someone tries hard enough (pulling the CMOS battery). That then
brings to question whether it's even worth it to set it up, when it doesn't really give you that much. On its own,
I probably wouldn't bother with setting up secure-boot, however secure boot allows me to set up TPM (Trusted Platform
Module) to automatically release the decryption keys for my LUKS encrypted root partition, in a secure way. This means I
won't have to type my disk password every time I boot.
For more information on this, check out the follow-up guide: [TPM_UNLOCKING](./04_TPM_UNLOCKING.md).