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 = ''
18 Whether to delete all files in <filename>/tmp</filename> during boot.
19 '';
20 };
21
22 boot.tmpOnTmpfs = mkOption {
23 type = types.bool;
24 default = false;
25 description = ''
26 Whether to mount a tmpfs on <filename>/tmp</filename> during boot.
27 '';
28 };
29
30 boot.tmpOnTmpfsSize = mkOption {
31 type = types.oneOf [ types.str types.types.ints.positive ];
32 default = "50%";
33 description = ''
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 = [ "mode=1777" "strictatime" "rw" "nosuid" "nodev" "size=${toString cfg.tmpOnTmpfsSize}" ];
52 }
53 ];
54
55 systemd.tmpfiles.rules = optional config.boot.cleanTmpDir "D! /tmp 1777 root root";
56
57 };
58
59}