2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
let
|
2023-04-29 16:46:19 +00:00
|
|
|
cfg = config.boot.tmp;
|
2021-09-18 10:52:07 +00:00
|
|
|
in
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
2023-04-29 16:46:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "boot" "cleanTmpDir" ] [ "boot" "tmp" "cleanOnBoot" ])
|
|
|
|
(mkRenamedOptionModule [ "boot" "tmpOnTmpfs" ] [ "boot" "tmp" "useTmpfs" ])
|
|
|
|
(mkRenamedOptionModule [ "boot" "tmpOnTmpfsSize" ] [ "boot" "tmp" "tmpfsSize" ])
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
options = {
|
2023-04-29 16:46:19 +00:00
|
|
|
boot.tmp = {
|
|
|
|
cleanOnBoot = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to delete all files in {file}`/tmp` during boot.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
tmpfsSize = mkOption {
|
|
|
|
type = types.oneOf [ types.str types.types.ints.positive ];
|
|
|
|
default = "50%";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Size of tmpfs in percentage.
|
|
|
|
Percentage is defined by systemd.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
useTmpfs = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to mount a tmpfs on {file}`/tmp` during boot.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
::: {.note}
|
|
|
|
Large Nix builds can fail if the mounted tmpfs is not large enough.
|
|
|
|
In such a case either increase the tmpfsSize or disable this option.
|
|
|
|
:::
|
|
|
|
'';
|
|
|
|
};
|
2021-09-18 10:52:07 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2021-09-18 10:52:07 +00:00
|
|
|
# When changing remember to update /tmp mount in virtualisation/qemu-vm.nix
|
2023-04-29 16:46:19 +00:00
|
|
|
systemd.mounts = mkIf cfg.useTmpfs [
|
2021-01-09 10:05:03 +00:00
|
|
|
{
|
|
|
|
what = "tmpfs";
|
|
|
|
where = "/tmp";
|
2021-01-15 22:18:51 +00:00
|
|
|
type = "tmpfs";
|
2023-04-29 16:46:19 +00:00
|
|
|
mountConfig.Options = concatStringsSep "," [
|
|
|
|
"mode=1777"
|
|
|
|
"strictatime"
|
|
|
|
"rw"
|
|
|
|
"nosuid"
|
|
|
|
"nodev"
|
|
|
|
"size=${toString cfg.tmpfsSize}"
|
|
|
|
];
|
2021-01-09 10:05:03 +00:00
|
|
|
}
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
systemd.tmpfiles.rules = optional cfg.cleanOnBoot "D! /tmp 1777 root root";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2020-08-20 17:08:02 +00:00
|
|
|
}
|