Merge pull request #204534 from SuperSandro2000/boot-tmp

This commit is contained in:
Sandro 2023-04-12 21:37:47 +02:00 committed by GitHub
commit 603320b64f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 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,15 +3,18 @@
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 = {
boot.cleanTmpDir = mkOption { cleanOnBoot = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
description = lib.mdDoc '' description = lib.mdDoc ''
@ -19,15 +22,7 @@ in
''; '';
}; };
boot.tmpOnTmpfs = mkOption { tmpfsSize = 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 ]; type = types.oneOf [ types.str types.types.ints.positive ];
default = "50%"; default = "50%";
description = lib.mdDoc '' description = lib.mdDoc ''
@ -36,29 +31,39 @@ in
''; '';
}; };
useTmpfs = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to mount a tmpfs on {file}`/tmp` during boot.
::: {.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.
:::
'';
};
};
}; };
###### 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 "," [
"mode=1777"
"strictatime" "strictatime"
"rw" "rw"
"nosuid" "nosuid"
"nodev" "nodev"
"size=${toString cfg.tmpOnTmpfsSize}" ]; "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";