summaryrefslogtreecommitdiff
path: root/sys/boot/efi.nix
blob: cbcefd97ba3437c9d5dbe738c22767bfa9a4b4b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{ config, lib, ... }:
with lib; let
  cfg = config.local.boot.efi;
in
{
  options.local.boot.efi = {
    enable = mkEnableOption "EFI with FAT32 system partition";

    esp = {
      mountpoint = mkOption {
        type = types.enum [ "/boot" "/boot/efi" ];
        default = "/boot";
      };

      uuid = mkOption {
        type = types.strMatching "[0-9A-F]{4}-[0-9A-F]{4}";
      };
    };

    removable = mkOption {
      type = types.bool;
    };
  };

  config = mkIf cfg.enable {
    boot = {
      initrd.supportedFilesystems = [ "vfat" ];

      loader = {
        efi = {
          efiSysMountPoint = cfg.esp.mountpoint;
          canTouchEfiVariables = !cfg.removable;
        };

        grub.efiInstallAsRemovable = cfg.removable;
      };
    };

    fileSystems.${cfg.esp.mountpoint} = {
      device = "/dev/disk/by-uuid/${cfg.esp.uuid}";
      fsType = "vfat";
      options = [ "noatime" "umask=027" "sync" ];
      neededForBoot = true;
    };
  };
}