To Dream of Magick

Dreamer Shaper Seeker Maker

Having a Private Repository Cache

Posted on Wed Aug 27 03:00:00 UTC 2014 by Savanni D'Gerinel

A very quick update just to mention a tiny microscript that I wrote this evening.

cabal-install builds a local replica of all packages that get downloaded from Hackage (or Stackage, if you prefer). This both makes the packages installable to local sandboxes, and also obviates the need for additional downloads. So, I learned how to add on my own package repository.

This is not a primer on the overall structure of your ~/.cabal/. But a very quick relevant rundown goes like so:

~/.cabal/

  • bin/
  • lib/
  • logs/
  • packages/
    • hackage.haskell.org/
      • 00-index.cache
      • 00-index.tar
      • 00-index.tar.backup
      • package folders/
    • savannidgerinel.com/
  • setup-exe-cache/
  • share/
  • config
  • world

So, here is your structure. Obviously, you will not have a savannidgerinel.com/ folder in yours, but the point of this is to make your own. This cache is for packages that you want installable locally, but for some reason don't want to push. In my case, it is because some of them are not polished enough, and in some cases I'm writing proprietary packages. If I were in an organization, I'd build a Hackage server and be done, but I'm a lone developer and can't be bothered with that level of setup.

To add to your new repository, first create the directory under packages/. Then, open up config, and right under remote-repo and remote-repo-cache, add local-repo like so:

local-repo: /home/savanni/.cabal/packages/savannidgerinel.com

Basically, you instantly have a local repository. But, presumably, you want to install a package and so it needs to be in your cache. Here's an example from my own system:

savanni@Orolo:~/src/photo-tools$ cabal sdist
Source tarball created: dist/photo-tools-0.3.0.0.tar.gz

And then you want to "cache" it.

First, create the directory for it:

mkdir -p ~/.cabal/packages/savannidgerinel.com/photo-tools/0.3.0.0

Copy the current cabal file and the tar file into the directory:

cp photo-tools.cabal ~/.cabal/packages/savannidgerinel.com/photo-tools/0.3.0.0
cp dist/photo-tools-0.3.0.0.tar.gz ~/.cabal/packages/savannidgerinel.com/photo-tools/0.3.0.0

Now, add that cabal file to 00-index.tar, without destroying any of the existing data:

cd ~/.cabal/packages/savannidgerinel.com/
tar -rf 00-index.tar photo-tools/0.3.0.0/photo-tools.cabal

What a pain... I turned it into a short bash script which I call local-cabal.sh:

LOCAL_REPO=~/.cabal/packages/savannidgerinel.com
mkdir -p $LOCAL_REPO/$1/$2
cp $1.cabal $LOCAL_REPO/$1/$2
cp dist/$1-$2.tar.gz $LOCAL_REPO/$1/$2
cd $LOCAL_REPO/
tar -rf 00-index.tar $1/$2/$1.cabal

So, now, whenever I need to cache a new package, I do this:

cabal sdist
local-cabal.sh photo-tools 0.3.0.0

Have fun! I think this is really useful, or will be until I finally have a need for my own Hackage.