From e499f0ee37ffbbd3cdef2e2bbeb7d8d2cfe577a8 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Fri, 9 Jun 2023 10:35:11 +0800 Subject: [PATCH] feat: nix.gc.automatic = true --- flake.nix | 4 +--- modules/nixos/core-desktop.nix | 14 ++++++++++++++ modules/nixos/core-server.nix | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index f5efb4ad..63035d16 100644 --- a/flake.nix +++ b/flake.nix @@ -1,11 +1,9 @@ { description = "NixOS configuration of Ryan Yin"; + # the nixConfig here only affects the flake itself, not the system configuration! nixConfig = { experimental-features = [ "nix-command" "flakes" ]; - # Manual optimise storage: nix-store --optimise - # https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-auto-optimise-store - auto-optimise-store = true; substituters = [ # replace official cache with a mirror located in China diff --git a/modules/nixos/core-desktop.nix b/modules/nixos/core-desktop.nix index 68075457..ec711f3f 100644 --- a/modules/nixos/core-desktop.nix +++ b/modules/nixos/core-desktop.nix @@ -1,6 +1,20 @@ { config, pkgs, devenv, ... }: { + # for nix server, we do not need to keep too much generations + boot.loader.systemd-boot.configurationLimit = 10; + # boot.loader.grub.configurationLimit = 10; + # do garbage collection weekly to keep disk usage low + nix.gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 1w"; + }; + + # Manual optimise storage: nix-store --optimise + # https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-auto-optimise-store + auto-optimise-store = true; + # enable flakes globally nix.settings.experimental-features = [ "nix-command" "flakes" ]; diff --git a/modules/nixos/core-server.nix b/modules/nixos/core-server.nix index c8aa7834..468c085c 100644 --- a/modules/nixos/core-server.nix +++ b/modules/nixos/core-server.nix @@ -1,6 +1,20 @@ { config, pkgs, devenv, ... }: { + # for nix server, we do not need to keep too much generations + boot.loader.systemd-boot.configurationLimit = 10; + # boot.loader.grub.configurationLimit = 10; + # do garbage collection weekly to keep disk usage low + nix.gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 1w"; + }; + + # Manual optimise storage: nix-store --optimise + # https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-auto-optimise-store + auto-optimise-store = true; + # enable flakes globally nix.settings.experimental-features = [ "nix-command" "flakes" ];