1{ config, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.boot;
7in
8{
9
10 ###### interface
11
12 options = {
13
14 boot.cleanTmpDir = mkOption {
15 type = types.bool;
16 default = false;
17 description = lib.mdDoc ''
18 Whether to delete all files in {file}`/tmp` during boot.
19 '';
20 };
21
22 boot.tmpOnTmpfs = mkOption {
23 type = types.bool;
24 default = false;
25 description = lib.mdDoc ''
26 Whether to mount a tmpfs on {file}`/tmp` during boot.
27 '';
28 };
29
30 boot.tmpOnTmpfsSize = mkOption {
31 type = types.oneOf [ types.str types.types.ints.positive ];
32 default = "50%";
33 description = lib.mdDoc ''
34 Size of tmpfs in percentage.
35 Percentage is defined by systemd.
36 '';
37 };
38
39 };
40
41 ###### implementation
42
43 config = {
44
45 # When changing remember to update /tmp mount in virtualisation/qemu-vm.nix
46 systemd.mounts = mkIf cfg.tmpOnTmpfs [
47 {
48 what = "tmpfs";
49 where = "/tmp";
50 type = "tmpfs";
51 mountConfig.Options = concatStringsSep "," [ "mode=1777"
52 "strictatime"
53 "rw"
54 "nosuid"
55 "nodev"
56 "size=${toString cfg.tmpOnTmpfsSize}" ];
57 }
58 ];
59
60 systemd.tmpfiles.rules = optional config.boot.cleanTmpDir "D! /tmp 1777 root root";
61
62 };
63
64}