Can cabal not un-install packages? - haskell

cabal help shows thers isnot "uninstall" option.
then what's the best way to uninstall the packages installed by cabal ?
% cabal update
% cabal install mighttpd2
mighttpd2 is installed successfully. However the ghc-pkg cannot find & unregister it:
% ghc-pkg list | grep -i might
% ghc-pkg unregister mighttpd2
ghc-pkg: cannot find package mighttpd2
Sincerely!
>find .cabal | grep -i mighttp
.cabal/share/doc/mighttpd2-2.3.3
.cabal/share/doc/mighttpd2-2.3.3/LICENSE
.cabal/share/mighttpd2-2.3.3
.cabal/share/mighttpd2-2.3.3/sample.conf
.cabal/share/mighttpd2-2.3.3/sample.route
.cabal/packages/hackage.haskell.org/mighttpd2
.cabal/packages/hackage.haskell.org/mighttpd2/2.3.3
.cabal/packages/hackage.haskell.org/mighttpd2/2.3.3/mighttpd2-2.3.3.tar.gz
>ghc-pkg list | grep -i package\.conf
/usr/local/lib/ghc-7.0.3/package.conf.d:
/home/sw2wolf/.ghc/i386-freebsd-7.0.3/package.conf.d:
So ".cabal/packages/hackage.haskell.org" cannot be seen by ghc-pkg.

you might not have the Cabal path as part of your GHC path.
step 1
First, try to find out what your GHC package path is,
ghc-pkg list
# displays stuff like "/home/username/.../package.conf.d"
then, make sure the one Cabal is writing to is active. For me, Cabal adds packages to
/home/username/.ghc/x86_64-linux-7.0.4/package.conf.d
step 2
If there is no such directory on your system, see what Cabal's writing.
strace -f -o trace.txt cabal install mighttpd2
grep "package\.cache" trace.txt
then add the package path to this system environment variable
export GHC_PACKAGE_PATH=NEWPATH:/usr/local/lib/ghc-7.0.3/package.conf.d
try again, if it doesn't work proceed to step 3
step 3
look in that directory and see if there's a file like
mighthttpd2-version-LONGHASHCODE.conf
if it's there, then you probably need to recache
ghc-pkg recache --user

The GHC package system is not used for executables, and the mighttpd2 package only builds executables. To uninstall it, simply remove the two executables (mighty and mkindex) and the two data files (sample.conf and sample.route) listed in the package's cabal file. You can find which directories these files were installed to by perusing cabal's config file in ~/.cabal/config.

Related

How can I know in advance where cabal will place a generated executable?

When I run cabal build for my project, it places my compiled executable in
dist-newstyle/build/$PLATFORM/$GHC/$PACKAGE-$VERSION/x/$PACKAGE/build/$PACKAGE/$PACKAGE
I'm using a Makefile to run cabal build as needed when I need to run the executable.
Since I'm working on different platforms at various times, I need a way to tell my Makefile what to expect the $PLATFORM value to be.
There's a couple ways I could go about this:
run cabal build once unconditionally, and then use wildcards:
BIN := $(wildcard dist-newstyle/build/*/ghc-*/foo-*/x/foo/build/foo/foo)
use uname to predict what the platform will be
BIN := dist-newstyle/build/$(shell uname -m)-$(shell uname -s | some magic)/ghc-$(shell ghc --version | some magic)/foo-$(VERSION)/x/foo/build/foo/foo
give up on making sure the binary is up to date within the Makefile and just run cabal run unconditionally
Any of those would work, but I would like to know if I could just ask cabal to tell me where it expects to place an executable.
Is there a cabal command I can run to tell me what $PLATFORM and/or $GHC values it detects?
Say you just ran cabal build and produced a foo binary somewhere in the dist-newstyle/ directory. You can now run:
cabal exec which foo
This will print out the absolute path to the foo executable.
Note: It may be necessary to run cabal exec --verbose=0 which foo so that cabal does not print out extra information about packages or configuration.
Why does this work?
cabal exec lets you run commands with the same environment used when running other cabal commands, like cabal build. So you can run printenv and cabal exec printenv to see how it adds and changes some environment variables. Notice that it adds the whole dist-newstyle/ path to your PATH variable!
So saying cabal exec which foo works because it is just like running which foo, but with the extended PATH variable.
This means you can extract the dist-newstyle/ path itself using a fancier command:
cabal exec --verbose=0 printenv PATH | tr ':' '\n' | grep dist-newstyle | head -1
This may be useful if you need to know the path before you run cabal build, in which case the binary will not exist yet.
cabal exec which $EXENAME$ will give you the full path of the compiled executable.
Since cabal 3.8, you can use the list-bin command:
$ cabal list-bin my-executable-name
That will print the path at which cabal will place the executable if built. Note that it doesn't actually guarantee that the executable is built, so depending on your use case you might want to check that too.

Global install of a program built in sandbox

I'm using sandboxes all the time when building Haskell programs and libraries. But occasionally, I build a program that I would like to install system wide. There doesn't seem to be an easy way of taking a program which is built in a sandbox and installing it outside of the sandbox.
Linking Idris to a PATH-folder
If you are on linux it's as simple as putting a symbolic link somewhere into your path - I have a ~/bin for that. So it's the same as bheklilr mentioned only that I usually get the dev-version from github:
git clone git://github.com/idris-lang/Idris-dev idris
cd idris
cabal sandbox init
cabal update
cabal install --dependencies only
make
after this I go to ~/bin and use ln -s [path to idris]/.cabal-sandbox/bin/idris - you can link the other executables too if you like but this one will should be enough to play with idris
If the binary is statically linked (which is true in most cases) then you can do the following
> mkdir tools
> cd tools
> cabal sandbox init
> cabal install tool1 tool2
# Wait a long time
> cp .cabal-sandbox/bin/tool1 ~/.cabal/bin
> cp .cabal-sandbox/bin/tool2 ~/.cabal/bin
On windows you'll have to do
> cp .cabal-sandbox\bin\tool1.exe %APPDATA%\Roaming\cabal\bin
> cp .cabal-sandbox\bin\tool2.exe %APPDATA%\Roaming\cabal\bin
Obviously you should have your user cabal directory on your path.
Your mileage may vary, it's dependent on the executable being built, so for some it might be more difficult to do this sort of thing. In my experience this works pretty well, though. I use it for ghc-mod, hlint, pointfree, and others.

ghc can't find my cabal installed packages

I've installed ghc 6.12.3, and then the Haskell Platform. I'm trying to compile a test program:
$ ghc test.hs
test.hs:3:0:
Failed to load interface for `Bindings':
Use -v to see a list of the files searched for.
so, naturally, I do
cabal install Bindings
Which works fine, and places the package in ~/.cabal/lib/bindings-0.1.2 The problem is, that when I go to compile again with ghc, it still doesn't find the package I've installed with cabal.
compiling in verbose mode gives:
ghc -v test.hs
Using binary package database: /home/ludflu/ghc/lib/ghc-6.12.3/package.conf.d/package.cache
Using binary package database: /home/ludflu/.ghc/x86_64-linux 6.12.3/package.conf.d/package.cache
As suggested by another stackoverflow user, I tried:
ghc-pkg describe rts > rts.pkg
vi rts.pkg # add the /home/ludflu/.cabal/lib to `library-dirs` field
ghc-pkg update rts.pkg
But to no avail. How to I add the .cabal to the list of package directories to search?
Thank you!
You can check which packages are installed with ghc-pkg list. It may be that you need to either specify the packages to ghc with -package <pkgname> or I believe adding --make to will trigger a chasing down of dependencies, including packages.
Edit: the bindings package is obsolete indeed, see the hackage page. This isn't a package management problem, the only module available is Bindings.Deprecated, which you are perfectly able to load, even though it is an empty module. I believe the relevant parts have been broken out into bindings-<module>, so if you want the bindings functionality you should look to those packages.
http://www.haskell.org/haskellwiki/Cabal-install
One thing to be especially aware of, is that the packages are installed locally by default by cabal, whereas the commands
runhaskell Setup configure
runhaskell Setup build
runhaskell Setup install
install globally by default. If you install a package globally, the local packages are ignored. The default for cabal-install can be modified by editing the configuration file.
I was getting the same error with the runhaskell command. I used the cabal in the directory that had the .cabal file and was able to resolve the error.

Using GHC, cabal with GMP installed in user-space

I have been trying to install Haskell Platform and cabal-install installed on Linux in user-space on a system that doesn't have the GNU Multi-Precision package (GMP) installed.
I managed to get GHC-6.12.1 installed and GHCi working by setting up LB_LIBRARY_PATH to point at the lib directory where I installed GMP, but then ran into problems in the next step, getting cabal-install to work. It kept trying to (statically) link to GMP.
This fails because the GMP is not installed in the system and ld hasn't a clue where to find the libraries, and there is no environment variable (that I am aware of) that can tell ld where to find the user-installed GMP, and (apparently) no way of telling configuring Cabal to supply the relevant -L flag.
After much fruitless searching and hacking attempts I hit on the absurdly simple idea of installing my own ld shell script that invokes the system ld with the appropriate -L flag.
This is shell scripting 101, of course:
#!/bin/sh
/usr/bin/ld -L$HOME/gnu/lib "$#"
With this script installed in a directory on my PATH ahead of /usr/bin all the problems seem to have gone away.
Basically, your ghc is not working yet. Yes, it can compile things, but it cannot link programs because it needs to link them to gmp.
What we can do is to edit some core package, e.g. the rts package, so that ghc will always use the right -L flag:
ghc-pkg describe rts > rts.pkg
vi rts.pkg # add the gmp dir to the `library-dirs` field
sudo ghc-pkg update rts.pkg

Enable --hyperlink-source for "cabal install"

The command cabal haddock has very useful --hyperlink-source option.
I would like to have the source hyperlinked when building documentation with cabal install.
The ticket #517 seems to be just about it: http://hackage.haskell.org/trac/hackage/ticket/517
However, perhaps it is possible to set this flag via ~/.cabal/config file?
If not, how can I get working cabal-install build with the patch from #517 without installing Cabal-1.9, which is currently mandatory (due to one patch from December)?
Currently you cannot get the equivalent of the --hyperlink-source option when using the "all in one" cabal install command. The ticket you cite is exactly about this issue.
For me this worked:
cabal update
cabal install haddock
Edit config file ~/.cabal/config
Enable Documentation: True (removing "-- " at the beginning of the line is fine)
Cabal Library:
cd ...someNicePlace...
cabal unpack Cabal
Edit file Distribution/Simple/Setup.hs, therein find defaultHaddockFlags = ...
I switched some of them from False to True:
...
haddockHoogle = Flag True,
...
haddockHtml = Flag True,
...
haddockExecutables = Flag True,
...
haddockHscolour = Flag True,
...
having haddockHscolour the only important one (don't have to change the others if not want to).
Install updated Cabal Library:
sudo cabal install --global
cabal-install (cabal shell command)
To get the updated Cabal Libary working within cabal shell command, I reinstalled cabal-install also:
cd ...someNicePlace...
cabal unpack cabal-install
sudo cabal install --global
Since then the shell command cabal --version says to me:
cabal-install version 1.16.0.2
using version 1.16.0.3 of the Cabal library
And, as wanted, any new cabal install is now installing full haddock html documentation with source codes hyperlinked as default.
Ticket #517 is about passing haddock options via cabal, like if you have special needs like building a hoogle database or usa a different CSS
Most users will be happy with standard haddock and hyperlinked sources though, which is possible with Cabal-1.8. Ticket #517 is if you have bigger needs.
Simply calling cabal haddock --hyperlink-source should do the trick.
If you want this as the default, you can edit ~/.cabal/config as you mentioned.

Resources