From 17be62f56cce92fb6c38d9ba3e8535b37e3b75a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Sat, 22 Jun 2019 20:10:03 +0200 Subject: [PATCH] Add configurationLimit to systemd-boot to prevent running out of disk space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #23926 (cherry picked from commit 224a6562a4880195afa5c184e755b8ecaba41536) Signed-off-by: Domen Kožar --- .../loader/systemd-boot/systemd-boot-builder.py | 4 +++- .../boot/loader/systemd-boot/systemd-boot.nix | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py index 6016a85ea061..5d91b6d5c1a0 100644 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py @@ -124,7 +124,9 @@ def get_generations(profile=None): universal_newlines=True) gen_lines = gen_list.split('\n') gen_lines.pop() - return [ (profile, int(line.split()[0])) for line in gen_lines ] + + configurationLimit = @configurationLimit@ + return [ (profile, int(line.split()[0])) for line in gen_lines ][-configurationLimit:] def remove_old_entries(gens): rex_profile = re.compile("^@efiSysMountPoint@/loader/entries/nixos-(.*)-generation-.*\.conf$") diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix index 9ad2a2779e18..670f2a0bac3f 100644 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix @@ -22,6 +22,8 @@ let editor = if cfg.editor then "True" else "False"; + configurationLimit = if cfg.configurationLimit == null then 0 else cfg.configurationLimit; + inherit (cfg) consoleMode; inherit (efi) efiSysMountPoint canTouchEfiVariables; @@ -55,6 +57,19 @@ in { ''; }; + configurationLimit = mkOption { + default = null; + example = 120; + type = types.nullOr types.int; + description = '' + Maximum number of latest generations in the boot menu. + Useful to prevent boot partition running out of disk space. + + null means no limit i.e. all generations + that were not garbage collected yet. + ''; + }; + consoleMode = mkOption { default = "keep";