2014-07-25 20:05:57 +02:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2021-09-02 15:20:50 +02:00
|
|
|
let
|
2022-12-04 21:44:47 +01:00
|
|
|
cfg = config.boot.tmp;
|
2021-09-02 15:20:50 +02:00
|
|
|
in
|
2014-07-25 20:05:57 +02:00
|
|
|
{
|
2022-12-04 21:44:47 +01:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "boot" "cleanTmpDir" ] [ "boot" "tmp" "cleanOnBoot" ])
|
|
|
|
(mkRenamedOptionModule [ "boot" "tmpOnTmpfs" ] [ "boot" "tmp" "useTmpfs" ])
|
|
|
|
(mkRenamedOptionModule [ "boot" "tmpOnTmpfsSize" ] [ "boot" "tmp" "tmpfsSize" ])
|
|
|
|
];
|
2014-07-25 20:05:57 +02:00
|
|
|
|
|
|
|
options = {
|
2022-12-04 21:44:47 +01:00
|
|
|
boot.tmp = {
|
|
|
|
cleanOnBoot = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to delete all files in {file}`/tmp` during boot.
|
|
|
|
'';
|
|
|
|
};
|
2014-07-25 20:05:57 +02:00
|
|
|
|
2022-12-04 21:44:47 +01: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.
|
|
|
|
'';
|
|
|
|
};
|
2014-07-25 20:05:57 +02:00
|
|
|
|
2022-12-04 21:44:47 +01:00
|
|
|
useTmpfs = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to mount a tmpfs on {file}`/tmp` during boot.
|
2023-03-20 17:27:06 +01: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.
|
|
|
|
:::
|
2022-12-04 21:44:47 +01:00
|
|
|
'';
|
|
|
|
};
|
2014-07-25 20:05:57 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2021-09-02 15:20:50 +02:00
|
|
|
# When changing remember to update /tmp mount in virtualisation/qemu-vm.nix
|
2022-12-04 21:44:47 +01:00
|
|
|
systemd.mounts = mkIf cfg.useTmpfs [
|
2020-12-23 22:44:20 +01:00
|
|
|
{
|
|
|
|
what = "tmpfs";
|
|
|
|
where = "/tmp";
|
2021-01-09 15:32:17 +01:00
|
|
|
type = "tmpfs";
|
2022-12-04 21:44:47 +01:00
|
|
|
mountConfig.Options = concatStringsSep "," [
|
|
|
|
"mode=1777"
|
|
|
|
"strictatime"
|
|
|
|
"rw"
|
|
|
|
"nosuid"
|
|
|
|
"nodev"
|
|
|
|
"size=${toString cfg.tmpfsSize}"
|
|
|
|
];
|
2020-12-23 22:44:20 +01:00
|
|
|
}
|
|
|
|
];
|
2014-07-25 20:05:57 +02:00
|
|
|
|
2022-12-04 21:44:47 +01:00
|
|
|
systemd.tmpfiles.rules = optional cfg.cleanOnBoot "D! /tmp 1777 root root";
|
2014-07-25 20:05:57 +02:00
|
|
|
};
|
2020-08-08 02:54:16 +02:00
|
|
|
}
|