#!/bin/sh
set -eu

# shellcheck source=/dev/null
. "$DOTFILES/sh/colors.sh"
yellow "Cleaning up the NixOS store\n"

PROFILES="$(mktemp)"
printf "per-user/root/channels\nper-user/andreh/profile\nper-user/andreh/channels\nsystem\n" > "$PROFILES"

while IFS='' read -r p; do
  sudo nix-env --delete-generations old -p "/nix/var/nix/profiles/$p"
done < "$PROFILES"

# Current profile, change when installing with =nix-env -iA nixpkgs.bsdgames=
nix-env --delete-generations old

nix-store --gc
nix-collect-garbage -d
