nixos/tmp: move /tmp options under boot.tmp

This commit is contained in:
Sandro Jäckel 2022-12-04 21:44:47 +01:00
parent 4054db2f35
commit a5d95ac5fc
No known key found for this signature in database
GPG key ID: 3AF5A43A3EECC2E5
4 changed files with 44 additions and 44 deletions

View file

@ -473,7 +473,7 @@ EOF
} }
# Don't emit tmpfs entry for /tmp, because it most likely comes from the # Don't emit tmpfs entry for /tmp, because it most likely comes from the
# boot.tmpOnTmpfs option in configuration.nix (managed declaratively). # boot.tmp.useTmpfs option in configuration.nix (managed declaratively).
next if ($mountPoint eq "/tmp" && $fsType eq "tmpfs"); next if ($mountPoint eq "/tmp" && $fsType eq "tmpfs");
# Emit the filesystem. # Emit the filesystem.

View file

@ -3,62 +3,62 @@
with lib; with lib;
let let
cfg = config.boot; cfg = config.boot.tmp;
in in
{ {
imports = [
###### interface (mkRenamedOptionModule [ "boot" "cleanTmpDir" ] [ "boot" "tmp" "cleanOnBoot" ])
(mkRenamedOptionModule [ "boot" "tmpOnTmpfs" ] [ "boot" "tmp" "useTmpfs" ])
(mkRenamedOptionModule [ "boot" "tmpOnTmpfsSize" ] [ "boot" "tmp" "tmpfsSize" ])
];
options = { options = {
boot.tmp = {
cleanOnBoot = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to delete all files in {file}`/tmp` during boot.
'';
};
boot.cleanTmpDir = mkOption { tmpfsSize = mkOption {
type = types.bool; type = types.oneOf [ types.str types.types.ints.positive ];
default = false; default = "50%";
description = lib.mdDoc '' description = lib.mdDoc ''
Whether to delete all files in {file}`/tmp` during boot. Size of tmpfs in percentage.
''; Percentage is defined by systemd.
'';
};
useTmpfs = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to mount a tmpfs on {file}`/tmp` during boot.
'';
};
}; };
boot.tmpOnTmpfs = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to mount a tmpfs on {file}`/tmp` during boot.
'';
};
boot.tmpOnTmpfsSize = 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.
'';
};
}; };
###### implementation
config = { config = {
# When changing remember to update /tmp mount in virtualisation/qemu-vm.nix # When changing remember to update /tmp mount in virtualisation/qemu-vm.nix
systemd.mounts = mkIf cfg.tmpOnTmpfs [ systemd.mounts = mkIf cfg.useTmpfs [
{ {
what = "tmpfs"; what = "tmpfs";
where = "/tmp"; where = "/tmp";
type = "tmpfs"; type = "tmpfs";
mountConfig.Options = concatStringsSep "," [ "mode=1777" mountConfig.Options = concatStringsSep "," [
"strictatime" "mode=1777"
"rw" "strictatime"
"nosuid" "rw"
"nodev" "nosuid"
"size=${toString cfg.tmpOnTmpfsSize}" ]; "nodev"
"size=${toString cfg.tmpfsSize}"
];
} }
]; ];
systemd.tmpfiles.rules = optional config.boot.cleanTmpDir "D! /tmp 1777 root root"; systemd.tmpfiles.rules = optional cfg.cleanOnBoot "D! /tmp 1777 root root";
}; };
} }

View file

@ -1069,12 +1069,12 @@ in
fsType = "ext4"; fsType = "ext4";
autoFormat = true; autoFormat = true;
}); });
"/tmp" = lib.mkIf config.boot.tmpOnTmpfs { "/tmp" = lib.mkIf config.boot.tmp.useTmpfs {
device = "tmpfs"; device = "tmpfs";
fsType = "tmpfs"; fsType = "tmpfs";
neededForBoot = true; neededForBoot = true;
# Sync with systemd's tmp.mount; # Sync with systemd's tmp.mount;
options = [ "mode=1777" "strictatime" "nosuid" "nodev" "size=${toString config.boot.tmpOnTmpfsSize}" ]; options = [ "mode=1777" "strictatime" "nosuid" "nodev" "size=${toString config.boot.tmp.tmpfsSize}" ];
}; };
"/nix/${if cfg.writableStore then ".ro-store" else "store"}" = lib.mkIf cfg.useNixStoreImage { "/nix/${if cfg.writableStore then ".ro-store" else "store"}" = lib.mkIf cfg.useNixStoreImage {
device = "${lookupDriveDeviceName "nix-store" cfg.qemu.drives}"; device = "${lookupDriveDeviceName "nix-store" cfg.qemu.drives}";

View file

@ -17,7 +17,7 @@ let
http = ":8000"; http = ":8000";
}; };
}; };
boot.cleanTmpDir = true; boot.tmp.cleanOnBoot = true;
# for exchange rates # for exchange rates
security.pki.certificateFiles = [ ./server.crt ]; security.pki.certificateFiles = [ ./server.crt ];
networking.extraHosts = "127.0.0.1 api.exchangerate.host"; networking.extraHosts = "127.0.0.1 api.exchangerate.host";