From e55d4b46ddf8102185e1bdee718469a800ad0d4f Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Fri, 10 Nov 2023 13:07:42 +0100 Subject: [PATCH] [nix] Make own module --- nixos/hosts/Tibo-NixDesk/default.nix | 17 +++++------------ nixos/hosts/Tibo-NixFat/default.nix | 11 +++++------ nixos/modules/nix/default.nix | 6 ++++++ nixos/modules/nix/flakes/default.nix | 14 ++++++++++++++ nixos/modules/nix/gc/default.nix | 25 +++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 nixos/modules/nix/default.nix create mode 100644 nixos/modules/nix/flakes/default.nix create mode 100644 nixos/modules/nix/gc/default.nix diff --git a/nixos/hosts/Tibo-NixDesk/default.nix b/nixos/hosts/Tibo-NixDesk/default.nix index c5bdc77..5eb7234 100644 --- a/nixos/hosts/Tibo-NixDesk/default.nix +++ b/nixos/hosts/Tibo-NixDesk/default.nix @@ -13,6 +13,11 @@ networking.openconnect-sso.enable = true; + nix = { + flakes.enable = true; + gc.onFull.enable = true; + }; + programs = { home-manager.enable = true; sops.enable = true; @@ -61,23 +66,11 @@ time.timeZone = "Europe/Brussels"; nix = { - # Allow Nix Flakes # Keep derivations so shells don't break (direnv) - # If the disk has less than 100MiB, free up to 2GiB by garbage-collecting. extraOptions = '' - experimental-features = nix-command flakes keep-outputs = true keep-derivations = true - min-free = ${toString (100 * 1024 * 1024)} - max-free = ${toString (2048 * 1024 * 1024)} ''; - # Scheduled garbage-collect - gc = { - automatic = true; - dates = "weekly"; - options = "--delete-older-than 30d"; - }; - package = pkgs.nixFlakes; }; i18n.defaultLocale = "en_GB.UTF-8"; diff --git a/nixos/hosts/Tibo-NixFat/default.nix b/nixos/hosts/Tibo-NixFat/default.nix index 33324b6..c05381b 100644 --- a/nixos/hosts/Tibo-NixFat/default.nix +++ b/nixos/hosts/Tibo-NixFat/default.nix @@ -13,6 +13,11 @@ networking.openconnect-sso.enable = true; + nix = { + flakes.enable = true; + gc.onFull.enable = true; + }; + programs = { home-manager.enable = true; sops.enable = true; @@ -94,17 +99,11 @@ }; nix = { - # Allow Nix Flakes # Keep derivations so shells don't break (direnv) - # If the disk has less than 100MiB, free up to 2GiB by garbage-collecting. extraOptions = '' - experimental-features = nix-command flakes keep-outputs = true keep-derivations = true - min-free = ${toString (100 * 1024 * 1024)} - max-free = ${toString (2048 * 1024 * 1024)} ''; - package = pkgs.nixFlakes; }; i18n.defaultLocale = "en_GB.UTF-8"; diff --git a/nixos/modules/nix/default.nix b/nixos/modules/nix/default.nix new file mode 100644 index 0000000..1c67c6d --- /dev/null +++ b/nixos/modules/nix/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./flakes + ./gc + ]; +} diff --git a/nixos/modules/nix/flakes/default.nix b/nixos/modules/nix/flakes/default.nix new file mode 100644 index 0000000..3c5d892 --- /dev/null +++ b/nixos/modules/nix/flakes/default.nix @@ -0,0 +1,14 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.sisyphus.nix.flakes; +in { + options.sisyphus.nix.flakes.enable = lib.mkEnableOption "Nix Flakes"; + + config.nix = lib.mkIf cfg.enable { + extraOptions = '' + experimental-features = nix-command flakes + ''; + package = pkgs.nixFlakes; + }; +} diff --git a/nixos/modules/nix/gc/default.nix b/nixos/modules/nix/gc/default.nix new file mode 100644 index 0000000..a28133f --- /dev/null +++ b/nixos/modules/nix/gc/default.nix @@ -0,0 +1,25 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.sisyphus.nix.gc; +in { + options.sisyphus.nix.gc = { + weekly.enable = lib.mkEnableOption "Scheduled Nix garbage-collection"; + onFull.enable = lib.mkEnableOption "Nix garbage-collection when disk is almost full"; + }; + + config.nix = { + # If the disk has less than 100MiB, free up to 2GiB by garbage-collecting. + extraOptions = lib.mkIf cfg.onFull.enable '' + min-free = ${toString (100 * 1024 * 1024)} + max-free = ${toString (2048 * 1024 * 1024)} + ''; + + # Scheduled garbage-collect + gc = lib.mkIf cfg.weekly.enable { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 30d"; + }; + }; +}