about summary refs log tree commit diff
path: root/modules/system/boot/default.nix
blob: b037f63a41eb28c78dbe5ba23592ff6d8eb7b7cc (plain) (blame)
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
{ pkgs, config, lib, ... }:
let cfg = config.my.system.boot;
in {
  options.my.system.boot = with lib; {
    tmp = { clean = mkEnableOption "clean `/tmp` on boot."; };
    initrd = {
      network = { enable = mkEnableOption "enable SSH with initrd"; };
    };
  };

  config = {
    boot = {
      loader = {
        # Use the systemd-boot EFI boot loader.
        systemd-boot.enable = true;
        # Prohibits gaining root access by passing init=/bin/sh as a kernel parameter
        systemd-boot.editor = false;
        efi.canTouchEfiVariables = true;
      };

      kernelPackages = pkgs.linuxPackages_latest;
      cleanTmpDir = cfg.tmp.clean;
      tmpOnTmpfs = true;

      initrd = {
        luks.devices."system".allowDiscards = true;
        network = lib.mkIf cfg.initrd.network.enable {
          enable = true;
          postCommands = ''
            echo "cryptsetup-askpass; exit" > /root/.profile
          '';
          ssh = {
            enable = true;
            port = 2222;
            hostKeys =
              [ /etc/ssh/ssh_host_ed25519_key /etc/ssh/ssh_host_rsa_key ];
            authorizedKeys =
              config.users.users.fcuny.openssh.authorizedKeys.keys;
          };
        };
      };
    };
  };
}