Skip to content

Commit

Permalink
nixos/tmp: move /tmp options under boot.tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Mar 19, 2023
1 parent 4054db2 commit a5d95ac
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion nixos/modules/installer/tools/nixos-generate-config.pl
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ sub in {
}

# 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");

# Emit the filesystem.
Expand Down
78 changes: 39 additions & 39 deletions nixos/modules/system/boot/tmp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,62 @@
with lib;

let
cfg = config.boot;
cfg = config.boot.tmp;
in
{

###### interface
imports = [
(mkRenamedOptionModule [ "boot" "cleanTmpDir" ] [ "boot" "tmp" "cleanOnBoot" ])
(mkRenamedOptionModule [ "boot" "tmpOnTmpfs" ] [ "boot" "tmp" "useTmpfs" ])
(mkRenamedOptionModule [ "boot" "tmpOnTmpfsSize" ] [ "boot" "tmp" "tmpfsSize" ])
];

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 {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to delete all files in {file}`/tmp` during boot.
'';
};
tmpfsSize = 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.
'';
};

boot.tmpOnTmpfs = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to mount a tmpfs on {file}`/tmp` during boot.
'';
useTmpfs = 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 = {

# When changing remember to update /tmp mount in virtualisation/qemu-vm.nix
systemd.mounts = mkIf cfg.tmpOnTmpfs [
systemd.mounts = mkIf cfg.useTmpfs [
{
what = "tmpfs";
where = "/tmp";
type = "tmpfs";
mountConfig.Options = concatStringsSep "," [ "mode=1777"
"strictatime"
"rw"
"nosuid"
"nodev"
"size=${toString cfg.tmpOnTmpfsSize}" ];
mountConfig.Options = concatStringsSep "," [
"mode=1777"
"strictatime"
"rw"
"nosuid"
"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";
};

}
4 changes: 2 additions & 2 deletions nixos/modules/virtualisation/qemu-vm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1069,12 +1069,12 @@ in
fsType = "ext4";
autoFormat = true;
});
"/tmp" = lib.mkIf config.boot.tmpOnTmpfs {
"/tmp" = lib.mkIf config.boot.tmp.useTmpfs {
device = "tmpfs";
fsType = "tmpfs";
neededForBoot = true;
# 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 {
device = "${lookupDriveDeviceName "nix-store" cfg.qemu.drives}";
Expand Down
2 changes: 1 addition & 1 deletion nixos/tests/ihatemoney/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let
http = ":8000";
};
};
boot.cleanTmpDir = true;
boot.tmp.cleanOnBoot = true;
# for exchange rates
security.pki.certificateFiles = [ ./server.crt ];
networking.extraHosts = "127.0.0.1 api.exchangerate.host";
Expand Down

0 comments on commit a5d95ac

Please sign in to comment.