stack-clean-old: Clean away old stack build artifacts

[ bsd3, distribution, program ] [ Propose Tags ]

A tool for removing old .stack-work/install builds and .stack/snapshots & programs for older ghc versions to recover diskspace.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1, 0.2, 0.2.1, 0.2.2, 0.3, 0.3.1, 0.4, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.5, 0.4.6, 0.4.7, 0.4.8, 0.5, 0.5.1
Change log ChangeLog.md
Dependencies base (>=4.8 && <5), directory (>=1.2.5), extra (>=1.4.3), filemanip, filepath, simple-cmd (>=0.1.4), simple-cmd-args (>=0.1.2), simple-prompt (>=0.2) [details]
License BSD-3-Clause
Copyright 2020-2023 Jens Petersen <juhpetersen@gmail.com>
Author Jens Petersen <juhpetersen@gmail.com>
Maintainer Jens Petersen <juhpetersen@gmail.com>
Category Distribution
Home page https://github.com/juhp/stack-clean-old
Bug tracker https://github.com/juhp/stack-clean-old/issues
Source repo head: git clone https://github.com/juhp/stack-clean-old.git
Uploaded by JensPetersen at 2023-12-17T07:52:57Z
Distributions LTSHaskell:0.5.1, NixOS:0.5.1, Stackage:0.5.1
Executables stack-clean-old
Downloads 2023 total (61 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
Last success reported on 2023-12-17 [all 1 reports]

Readme for stack-clean-old-0.5.1

[back to package description]

stack-clean-old

A small tool to clean away older Haskell stack snapshot builds and ghc versions to recover diskspace.

Usage

stack-clean-old [size|list|remove|keep-minor|purge-older|delete-work] [(-P|--project)|(-G|--global)|(-C|--compilers)|(-T|--tarballs)] [(-s|--subdirs)|(-r|--recursive)] [-d|--delete] [GHCVER]`

In a project directory it acts on .stack-work/install/ by default, otherwise on ${STACK_ROOT}/{snapshots,programs}/ (the default Stack root is ~/.stack/): see the Stack root documentation.

Subcommands:

size: prints the total size of .stack-work/ of project(s) or the Stack root. directories (size does not take a GHCVER argument).

list: shows the total size and number of snapshots per ghc version (the GHCVER argument is optional).

remove: removes for the specified ghc version (the GHCVER argument is required).

keep-minor: removes the builds/installs for older minor releases of ghc major versions. If GHCVER is given then only minor versions older than it (or than the latest installed minor version) are removed. If no GHCVER is given it applies to each installed ghc major version.

purge-older: removes snapshot builds with older timestamps

delete-work: removes .stack-work directories completely

dry-run mode is used by default and one should use --delete (-d) for actual deletion of files, after checking the dry-run output.

If you should remove any needed snapshot builds, then they will get rebuilt again by stack next time you build any projects needing them, so removals should be done carefully but can recover a lot of diskspace.

Further the commands can use --subdirs or --recursive to run over the projects in subdirs under the current directory or all matching .stack-work dirs from the current directory and below respectively.

If you have different ghc variants/archs installed you can use --platform to restrict to one of then, otherwise they are each listed by default.

Example usage

List a project's builds:

$ stack-clean-old list
149M  9.2.8  (5 dirs)
163M  9.4.7  (5 dirs)
155M  9.6.2  (5 dirs)

Remove project's 9.0.2 builds:

$ stack-clean-old remove --delete --project 9.0.2
:

(--project is optional in a project dir).

Remove stack ghc-9.4 snapshot builds and minor compilers before 9.4.7:

$ stack-clean-old list --global 9.4
x86_64-linux-tinfo6:
1.8G  9.4.6  (61 dirs)
279M  9.4.7  (6 dirs)
x86_64-linux:
ghc-tinfo6-9.4.6
ghc-tinfo6-9.4.7
$ stack-clean-old keep-minor --global 9.4
ghc-tinfo6-9.4.6 compiler would be removed
x86_64-linux-tinfo6:
61 dirs in ~/.stack/snapshots/x86_64-linux-tinfo6/*/9.4.6 would be removed

(use --delete (-d) for removal)
$ stack-clean-old keep-minor --global 9.4 -d
ghc-tinfo6-9.4.6 compiler removed
x86_64-linux-tinfo6:
61 dirs in ~/.stack/snapshots/x86_64-linux-tinfo6/*/9.4.6 removed

(--global is optional outside a project dir).

If you have different latest minor versions for compilers and snapshots you may prefer to specify the latest minor version to keep to get more certain behaviour.

Purging older stack project builds

stack-clean-old purge-older

This command removes older stack builds from .stack-work/install/. By default it keeps 5 newest builds per ghc version.

The preservation/deletion is calculated and done per ghc version.

NB: If you regularly build your project for several branches/tags against the same LTS or ghc version then it is safer to avoid using purge-older.

Deleting all .stack-work/ subdirectories

stack-clean-old delete-work --recursive can be used to remove recursively all .stack-work/ dirs within (or outside) a project directory to save space (seems same as stack clean --full inside a project).

Help output

(Note you can also run this tool via stack clean-old.)

To get help you can run stack-clean-old --help or just: $ stack-clean-old --version

0.5

$ stack-clean-old --help

Stack clean up tool

Usage: stack-clean-old [--version] COMMAND

  Cleans away old stack-work builds (and pending: stack snapshots) to recover
  diskspace. Use the --delete option to perform actual removals.
  https://github.com/juhp/stack-clean-old#readme

Available options:
  -h,--help                Show this help text
  --version                Show version

Available commands:
  size                     Total size
  list                     List sizes per ghc version
  remove                   Remove for a ghc version
  keep-minor               Remove for previous ghc minor versions
  purge-older              Purge older builds in .stack-work/install
  delete-work              Remove project's .stack-work/ (optionally
                           recursively)

Command options

Most of the commands have similar options, e.g.:

$ stack-clean-old remove --help

Usage: stack-clean-old remove [(-d|--delete) [-y|--yes]] 
                              [(-P|--project) | (-S|--snapshots) | 
                                (-C|--compilers) | (-T|--tarballs) | 
                                (-G|--global)] 
                              [(-s|--subdirs) | (-r|--recursive)] GHCVER 
                              [-o|--platform SYSTEM]

  Remove for a ghc version

Available options:
  -d,--delete              Do deletion [default is dryrun]
  -y,--yes                 Assume yes for all prompts
  -P,--project             Act on current project's .stack-work/ [default in
                           project dir]
  -S,--snapshots           Act on ~/.stack/snapshots/
  -C,--compilers           Act on ~/.stack/programs/ installations
  -T,--tarballs            Act on ~/.stack/programs/ tarballs
  -G,--global              Act on both ~/.stack/{programs,snapshots}/ [default
                           outside project dir]
  -s,--subdirs             List subdirectories
  -r,--recursive           List subdirectories
  -o,--platform SYSTEM     Specify which OS platform to work on (eg
                           'x86_64-linux-tinfo6', 'aarch64-linux-nix',
                           'x86_64-osx', 'aarch64-osx', etc)
  -h,--help                Show this help text

(The list and size commands don't have --delete and --yes.)

Installation

Run stack install or cabal install

This tool complements stack-all which builds projects across LTS major versions and hence generates a lot of stack builds.

cabal-clean is a similar tool for cleaning old cached cabal build files.

Contributing

BSD license

Project: https://github.com/juhp/stack-clean-old

Disclaimer

Use at your own risk: the author takes no responsibility for any loss or damaged caused by using this tool.

Bug reports, suggestions, and improvements are welcome.