typioca: 2.7.0 -> 2.8.0
[NixPkgs.git] / nixos / modules / system / boot / tmp.nix
blobfd16cd3fba429229f77640ceb3379f3b8b2534f5
1 { config, lib, ... }:
3 with lib;
5 let
6   cfg = config.boot.tmp;
7 in
9   imports = [
10     (mkRenamedOptionModule [ "boot" "cleanTmpDir" ] [ "boot" "tmp" "cleanOnBoot" ])
11     (mkRenamedOptionModule [ "boot" "tmpOnTmpfs" ] [ "boot" "tmp" "useTmpfs" ])
12     (mkRenamedOptionModule [ "boot" "tmpOnTmpfsSize" ] [ "boot" "tmp" "tmpfsSize" ])
13   ];
15   options = {
16     boot.tmp = {
17       cleanOnBoot = mkOption {
18         type = types.bool;
19         default = false;
20         description = lib.mdDoc ''
21           Whether to delete all files in {file}`/tmp` during boot.
22         '';
23       };
25       tmpfsSize = mkOption {
26         type = types.oneOf [ types.str types.types.ints.positive ];
27         default = "50%";
28         description = lib.mdDoc ''
29           Size of tmpfs in percentage.
30           Percentage is defined by systemd.
31         '';
32       };
34       useTmpfs = mkOption {
35         type = types.bool;
36         default = false;
37         description = lib.mdDoc ''
38            Whether to mount a tmpfs on {file}`/tmp` during boot.
40            ::: {.note}
41            Large Nix builds can fail if the mounted tmpfs is not large enough.
42            In such a case either increase the tmpfsSize or disable this option.
43            :::
44         '';
45       };
46     };
47   };
49   config = {
50     # When changing remember to update /tmp mount in virtualisation/qemu-vm.nix
51     systemd.mounts = mkIf cfg.useTmpfs [
52       {
53         what = "tmpfs";
54         where = "/tmp";
55         type = "tmpfs";
56         mountConfig.Options = concatStringsSep "," [
57           "mode=1777"
58           "strictatime"
59           "rw"
60           "nosuid"
61           "nodev"
62           "size=${toString cfg.tmpfsSize}"
63         ];
64       }
65     ];
67     systemd.tmpfiles.rules = optional cfg.cleanOnBoot "D! /tmp 1777 root root";
68   };