From f0ea4c95f61b39503c7e4d25c167a0b8f44cc293 Mon Sep 17 00:00:00 2001 From: MK Date: Mon, 13 Feb 2023 20:17:21 +0100 Subject: [PATCH] Update 'configuration.nix' --- configuration.nix | 65 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/configuration.nix b/configuration.nix index 130ccad..febda9c 100644 --- a/configuration.nix +++ b/configuration.nix @@ -2,7 +2,7 @@ # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: { imports = @@ -151,4 +151,67 @@ git # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). system.stateVersion = "22.05"; # Did you read the comment? +# code von hier https://github.com/NixOS/nixpkgs/blob/nixos-22.11/nixos/modules/system/boot/tmp.nix : + + with lib; + +let + cfg = config.boot; +in +{ + + ###### interface + + options = { + + boot.cleanTmpDir = mkOption { + type = types.bool; + default = false; + description = lib.mdDoc '' + Whether to delete all files in {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 = { + + # When changing remember to update /tmp mount in virtualisation/qemu-vm.nix + systemd.mounts = mkIf cfg.tmpOnTmpfs [ + { + what = "tmpfs"; + where = "/tmp"; + type = "tmpfs"; + mountConfig.Options = concatStringsSep "," [ "mode=1777" + "strictatime" + "rw" + "nosuid" + "nodev" + "size=${toString cfg.tmpOnTmpfsSize}" ]; + } + ]; + + systemd.tmpfiles.rules = optional config.boot.cleanTmpDir "D! /tmp 1777 root root"; + + }; + }