ctucx.git: nixfiles

ctucx' nixfiles

commit e70a1cbe27cf35a6b28972af1df95cc4a15ded02
parent 7842bbd92f18e5733725c68be4bc1337cf2da93c
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 24 Jan 2022 23:38:57 +0100

programs/cli/scripts: add script to clean up the nix-store
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/configurations/common.nix b/configurations/common.nix
@@ -12,6 +12,7 @@
     ./programs/cli/htop.nix
     ./programs/cli/utilities.nix
     ./programs/cli/network-utilities.nix
+    ./programs/cli/scripts.nix
   ];
 
   home-manager.useGlobalPkgs = true;
diff --git a/configurations/programs/cli/scripts.nix b/configurations/programs/cli/scripts.nix
@@ -0,0 +1,23 @@
+{ pkgs, ... }:
+
+let
+  nix-cleanup = pkgs.writeShellScriptBin "nix-cleanup" ''
+    set -eu
+
+    # Delete everything from this profile that isn't currently needed
+    nix-env --delete-generations old
+
+    # Delete generations older than a week
+    nix-collect-garbage
+    nix-collect-garbage --delete-older-than 7d
+
+    # Optimize
+    nix-store --gc --print-dead
+    nix-store --optimise
+  '';
+
+in {
+
+  home-manager.users.leah.home.packages = [ nix-cleanup ];
+
+}