Skip to content

Instantly share code, notes, and snippets.

@ThoNohT
Last active April 24, 2024 23:30
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThoNohT/30020c93fe6a8acea27f867b860047ee to your computer and use it in GitHub Desktop.
Save ThoNohT/30020c93fe6a8acea27f867b860047ee to your computer and use it in GitHub Desktop.
Cleaning haskell packages from pacman

Cleaning up haskell packages on Arch Linux

In Arch Linux, all haskell packages are dynamically linked. This can be a headache for the user, since it results in a large amount of haskell-* packages being installed on your system, and the possibility for version conflicts. A way around this is to not depend on pacman at all for haskell packages, but manually install them. In this document I explain how I switched from a lot of haskell packages installed with pacman, to a few manually installed packages.

Finding packages to uninstall

To determine which packages to uninstall (and replace), a few tools are useful:

  • pacman itself
  • pacgraph
  • pactree

For starters, just running pacgraph simply makes a pacgraph.png and pacgraph.svg file in your home folder, which displays all of the installed packages and their dependencies. This may be nice for getting a high level overview of all installed packages, but it is probably way too big and cluttered for any detailed insights.

With pacman, a command like

pacman -Q | grep haskell

should provide a good overview of all the haskell packages that are installed. This list is invaluable, when you combine it with pactree. The command

pactree -r package-name

prints the reverse dependency of the specified package. So doing this with one of the haskell packages indicates which programs you actually have installed that required all of the haskell packages. For me, the packages stack, xmobar and dhall-lsp-server were the culprits (I also have xmonad, but it was already installed via a custom stack install).

Not all packages have to be found at once. When one package is identified, it can be uninstalled with its dependencies using

pacman -Rs package-name

and it will show you that a good number of haskell packages go with it. After it is installed, check for more haskell packages with pacman -Q | grep haskell, check their reverse dependencies with pactree -r and remove a root package with pacman -Rs, until there are no more packages left.

Once all packages have been removed, try the same trick with pacman -Q | grep ghc, because this may also yield some packages that are no longer required.

Installing the packages again

Ghcup

We want to install the packages with stack now, but we don't have stack, and don't want to use pacman to install it. To get around this, we install ghcup. The AUR has a ghcup-hs-bin package, which can be installed however you install AUR packages, for example, I use:

paru -S ghcup-hs-bin

In order to be able to use the binaries installed by ghcup, we need to add the following folder to our PATH: ~/.ghcup/bin. For example,

I have the line

export PATH=$HOME/.ghcup/bin:$PATH

in my ~/.bash_profile.

Stack

Using ghcup is easiest via its TUI, with the command:

ghcup tui

In there, install the recommended versions of Stack and GHC.

ghcup can also be used directly without its tui if you wish to create a script to automatically install the correct packages. Just call it without any arguments to find the documentation on how to do this.

We should not have everything we need to manually install our other haskell packages (that could not be installed with ghcup).

Other packages

To install a package manually, find its source repository. In my case, for the packages I needed to install, the repositories are:

Make some directory to check these repositories out in:

mkdir ~/haskell-installs
cd ~/haskell-installs/

Then clone the repositories from the clone url provided by github, and cd into the folder.

git clone git@github.com:dhall-lang/dhall-haskell.git
cd dhall-haskell

You may not want to be on the bleeding edge, because blindly checking out the repository will often include commits that are not yet part of any release. So it could be wise to checkout a tag in the repository such that you can pick which release to install. At the time of writing, the latest tag for me was 1.41.1.

git checkout 1.41.1

In the case of dhall-lsp-server I don't need all of the packages, so I can specify which one I need to install:

stack install dhall-lsp-server

Now stack should go and download and build the package and its dependencies, and then place the executable in ~/.local/bin/. So make sure this directory is in your PATH variable.

For xmobar, the process is similar, but I don't need to specify which package to install.

cd ~/haskell-installs
git clone git@github.com:jaor/xmobar.git
git checkout 0.42
cd xmobar/
stack install

After you have done this with all packages that you removed from pacman, but do still need, you should be good to go.

Keeping up to date

One thing to note is that we fixed the tag in our git checkouts, and we are not using a package manager for these packages, so there will be no automatic updates. So it is worth it to periodically check if there are updates, git checkout the latest tag, and run another stack install.

@vaknin
Copy link

vaknin commented Feb 2, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment