os/modules/core/boot.nix

72 lines
2.1 KiB
Nix
Raw Normal View History

2021-05-30 19:10:28 +00:00
{ config, pkgs, lib, ... }:
2021-10-24 20:03:28 +00:00
with lib;
2021-05-30 19:10:28 +00:00
let
cfg = config.pub-solar.core;
2021-05-30 19:10:28 +00:00
in
{
options.pub-solar.core.iso-options.enable = mkOption {
2021-10-25 23:06:13 +00:00
type = types.bool;
default = false;
description = "Feature flag for iso builds";
};
options.pub-solar.core.disk-encryption-active = mkOption {
2022-08-13 10:32:16 +00:00
type = types.bool;
default = true;
description = "Whether it should be assumed that there is a cryptroot device";
};
options.pub-solar.core.hibernation = {
enable = mkOption {
type = types.bool;
default = false;
description = "Whether the device can hibernate. This creates a swapfile at /swapfile.";
};
2022-08-14 17:59:01 +00:00
resumeDevice = mkOption {
type = types.str;
default = "/swapfile";
description = "The location of the hibernation resume swap file.";
};
resumeOffset = mkOption {
type = types.nullOr types.number;
default = null;
description = "The swap file offset. Can be found by running `filefrag -v $swap_file_location`. See https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file";
};
};
2021-05-30 19:10:28 +00:00
config = {
2022-05-01 15:29:21 +00:00
boot = {
# Enable plymouth for better experience of booting
plymouth.enable = true;
2021-05-30 19:10:28 +00:00
2022-05-01 15:29:21 +00:00
# Mount / luks device in initrd
# Allow fstrim to work on it.
# The ! makes this enabled by default
initrd = mkIf (!cfg.iso-options.enable && cfg.disk-encryption-active) {
2022-05-01 15:29:21 +00:00
luks.devices."cryptroot" = {
allowDiscards = true;
};
2021-05-30 19:10:28 +00:00
};
2022-08-14 17:59:01 +00:00
resumeDevice = mkIf cfg.hibernation.enable cfg.hibernation.resumeDevice;
kernelParams = mkIf cfg.hibernation.enable [
"resume=${cfg.hibernation.resumeDevice}"
] ++ (
if (cfg.hibernation.resumeOffset == null) then builtins.abort "config.pub-solar.hibernation.resumeOffset has to be set if config.pub-solar.hibernation.enable is true."
else [ "resume_offset=${cfg.hibernation.resumeOffset}" ]
);
2022-05-01 15:29:21 +00:00
loader.systemd-boot.enable = true;
# Use latest LTS linux kernel by default
kernelPackages = pkgs.linuxPackages_5_15;
# Support ntfs drives
supportedFilesystems = [ "ntfs" ];
2022-05-01 15:29:21 +00:00
};
2021-05-30 19:10:28 +00:00
};
}