I have a script that deploys a Haskell program once a day. It currently does:
cabal update
cabal install --only-dependencies
cabal configure
cabal build
Which ensures it has the latest package index list, upgrades any dependency whose lower bound in the project.cabal has changed, and builds the code.
However, I'd really like to upgrade any dependency that has a new suitable version.
I tried adding --upgrade-dependencies but that refused to upgrade anything because it would break existing packages.
I tried combining that with --force-reinstalls, but it installed a new version of template-haskell (not a good idea) and things like QuickCheck would no longer compile.
What is the right way to upgrade packages automatically?
You could use cabal new-build and if you only want to upgrade most dependencies then freeze the few you wish to hold constant in a cabal.project.freeze file.
cat <<EOF >cabal.project.freeze
constraints: template-haskell == 2.13.0.0
EOF
And
cabal update
# Perhaps rm -rf dist-newstyle if you want a completely fresh build
cabal new-build --upgrade-dependencies
Upgrade to Cabal 2.0.0.0 or above.
From Cabal 2.0.0.0 it no longer upgrades template-haskell, as per the changelog:
Made the 'template-haskell' package non-upgradable again (#4185).
So --upgrade-dependencies --force-reinstalls works with newer versions.
Related
I have an application in a sandbox. Cabal dependencies have no constraints so cabal install --only-dependencies gives me the latest packages.
After a certain period of time I want to bump my dependencies to the latest versions but before this I want to see which dependencies are actually changed to a newer version.
I can check all of them manually of course. But I'd rather see a nice list of the things that will be upgraded.
I assume that cabal install --upgrade-dependencies --only-dependencies --dry-run is the way to do it. I would expect it to give me the list of all the packages that are at newer version that the one in my sandbox. But it never works! I mean, it just says that all dependencies are up to date when they are clearly not. Am I doing something wrong or missing/misunderstanding something?
If I destroy my sandbox completely, rerun cabal install --only-dependencies and diff the freeze files then I can see which packages got bumped. But this is silly. So how can I get cabal install --upgrade-dependencies --only-dependencies --dry-run to work correctly and print all the packages that are going to be upgraded without blowing the sandbox? Ad if those options do not work in cabal why aren't they just removed to avoid confusion?
Thank you.
You can use cabal list --installed and compare "Default available version" with "Installed versions".
Unfortunately cabal's --simple-output switch does not include that information, so to automate it you will need a smallish script.
I'm a newbie to haskell and cabal, so I'm probably missing something simple.
I updated cabal-install:
sudo cabal install cabal-install
Password:
Resolving dependencies...
Configuring cabal-install-1.22.0.0...
Building cabal-install-1.22.0.0...
Installed cabal-install-1.22.0.0
Updating documentation index
However cabal --version says:
cabal-install version 1.18.0.5
using version 1.18.1.4 of the Cabal library
What happened to cabal-install 1.22.0.0?
There are two ways of making cabal install packages globally. Note that, as a result, cabal may require sudo.
This command will install <PACKAGE> globally:
$ cabal install <PACKAGE> --global
As a more general solution, edit the file ~/.cabal/config and set user-install to False. This will automatically set the --global flag so you can just write cabal install <PACKAGE> without any worry. Here's a snippet of my config file:
...
-- split-objs: False
-- executable-stripping: True
user-install: False
-- package-db:
-- flags:
...
You may also want to set root-cmd to sudo if it's not already, so that cabal will automatically prompt for the root password when it encounters a permission problem.
There's some more info online here.
I see that there's an updated cabal at ~/Library/Haskell/bin, so I could replace /usr/bin/cabal with a symbolic link to this copy or I could copy this binary to /usr/bin.
I'm still interested if there is a more elegant/canonical way to make sure the new cabal is what gets used by default.
TLDR: Try running hash -r
Bash has a PATH hashtable that maps commands to the location of binaries. You may still have an old version of cabal installed somewhere in your PATH (possibly in a sandbox). Since cabal is not a new command, the hashtable will keep serving up the old version. hash -r rebuilds the hashtable, so the shell will correctly find the new version (providing it appears earlier in your path than the old one).
I am trying to install Elm and the instructions are to install Haskell and then
sh> cabal update
sh> cabal install cabal-install
sh> cabal install -j Elm elm-repl elm-reactor elm-get
When I do, the cabal-install installation installs text-1.2.0.0 which conflicts with the text-1.1.0.0 which uniplate requires so uniplate and its dependents fail to install. Text-1.1.0.0 is installed and present but is rejected in favour of text-1.2.0.0, even though the target needs text-1.1.0.0.
Is there a way to insist that cabal use text-1.1.0.0?
Is there a way to get text-1.1.0.0 and text-1.2.0.0 to co-exist?
Is there a way to convince uniplate that it can accept text-1.2.0.0?
Or a way to make uniplate (or cabal) believe that version text-1.1.0.0 is actually installed? Would that even work?
When I explicitly try to install version 1.1.0.0 of text, I am told that a reinstall would break other packages. Apparently it is a downgrade and not a co-installation. cabal does not seem to have an option to allow to me install two versions of the same library at the same time.
If I uninstall Haskell and all the libraries and then re-install Elm (without installing cabal-install so I don't get text-1.2.0.0 installed so there is no clash), I get 100 or so lines of
package aeson-0.7.0.4-8f84b14cc682e4c9b009352420076a45 is unusable due to missing or recursive dependencies:
attoparsec-0.10.4.0-ec2d0a330db1f6e3a6a3b79471a403ef hashable-1.2.2.0-45bd22df8c4ead6b3a7fb1d08bb07f7d mtl-2.1.3.1-8bcc0591131896cfc8761a93703d4c61 scientific-0.2.0.2-5e275f5d96527da6dc1f05642692a484 syb-0.4.1-be94ebe67c3607f5df1dfcc1906f5d5c text-1.1.0.0-9bd69e9ace700e05fb08e463086bc383 unordered-containers-0.2.4.0-69836b34d13649bcfacc8fb0c9f53e64 vector-0.10.9.1-c550551354bc7c2b5a1d261f39b2f3f4
package aeson-pretty-0.7.1-5dc26d5a4560afe110e90283479a1251 is unusable due to missing or recursive dependencies:
aeson-0.7.0.4-8f84b14cc682e4c9b009352420076a45
text-1.1.0.0-9bd69e9ace700e05fb08e463086bc383
unordered-containers-0.2.4.0-69836b34d13649bcfacc8fb0c9f53e64
vector-0.10.9.1-c550551354bc7c2b5a1d261f39b2f3f4
package asn1-encoding-0.9.0-94e9066cccf7ead73bee5ae4aa982071 is unusable due to missing or recursive dependencies:
mtl-2.1.3.1-8bcc0591131896cfc8761a93703d4c61
package asn1-parse-0.9.0-af4efc4777a8a0d9d19a626d5e4b08ff is unusable due to missing or recursive dependencies:
asn1-encoding-0.9.0-94e9066cccf7ead73bee5ae4aa982071
mtl-2.1.3.1-8bcc0591131896cfc8761a93703d4c61
text-1.1.0.0-9bd69e9ace700e05fb08e463086bc383
I have no idea at all how in resolve this or where to even try. Has anybody trod this path before and do you have any advice or pointers?
Thank you.
Edit
Installing in a sandbox changes the outcome only by degrees: text-1.1.0.0 does not clash with text-1.1.0.0 but still can not be loaded (despite being installed) and still remains the unsatisfied dependency.
blaze-builder is first to fail with cannot satisfy -package-id text-1.1.0.0-9bd69e9ace700e05fb08e463086bc383 yet the same log earlier stated [_12] trying: text-1.1.0.0/installed-9bd... (dependency of Elm-0.13) without apparent error or complaint.
cabal list shows both text-1.1.0.0 and text-1.2.0.0 as installed.
Installing blaze-builder separately looks the same. Dependency resolution shows
[_56] trying: blaze-builder-0.3.3.4 (user goal)
[_57] next goal: text (dependency of blaze-builder-0.3.3.4)
[_57] trying: text-1.1.0.0/installed-9bd...
[_58] done
All looks good but later, same log has
<command line>: cannot satisfy -package-id text-1.1.0.0-9bd69e9ace700e05fb08e463086bc383
(use -v for more information)
The ghc command line already had the -v flag and trying to re-run the command line copied from the log, with more -vs, gives an error with "can't find a package database at
dist/dist-sandbox-ad0bcd57/package.conf.inplace".
No package.conf.inplace seems to exist.
Further edit
On the Elm install page is a link to a BuildFromSource.hs script that is also supposed to work installing Elm. In the time that it took for that script to run and fail to work, I managed to install leiningen, node, npm, grunt and Clojure. I am now further along the road to getting Clojurescript installed in about 20 minutes than I am in getting Elm installed in nearly a week.
Elm looked really interesting but it is playing way too hard to get.
Thanks again to everyone who tried to help.
* Edit *
I finally got it.
Every executable installed by the installer at http://elm-lang.org/Install.elm caused a segfault.
The "Build from source" option at the same page did not work because the dependencies either stepped all over each other or could not get themselves straight in the first place.
The ghc at http://new-www.haskell.org/downloads/osx needs a later version of Mac OS than I have. (A link to older versions would not have gone astray.)
The solution (and it is obvious in retrospect) was to port install haskell-platform and port install hs-cabal-install and cabal install Elm .... I did have to run one of those installers twice because it could not find hackage.haskell.org (How is that a 'user' error?) but my hello-world.elm now compiles.
Thank you all again.
It looks like some dependency issues with elements you already have installed. You will probably need to install it in a sandbox.
First, update to the latest version of cabal:
$ cabal update
$ cabal install cabal cabal-install
Next, make sure you have the installed version of cabal on your $PATH.
$ which cabal
> /path/to/cabal/bin/cabal
If it says something like /usr/bin/cabal you will need to export cabal to be on your $PATH. For me this is `/home/username/.cabal/bin
$ export PATH=/path/to/cabal/bin/cabal;$PATH
Run which cabal again and ensure it is pointing to that path.
Now that you have the latest version of cabal. Run the following:
$ mkdir elm
$ cd elm
$ cabal sandbox init
This will initialize a sandbox where dependencies are completely independent of your other installs. Within this directory, you should be able to install the elm platform by running:
$ cabal install Elm elm-repl elm-reactor elm-get
These will be installed in a sub-directory called .cabal-sanbox/bin/ For convenience, you will probably want to add this to your $PATH so you can run the executables from any directory.
Hope this helps!
I'm in situation where I cannot install new package without reinstalling others (my distribution comes without sandbox).
Is it possible to determine which version of each package I should use so that there will be no conflicts with new one included?
How can I encode this set to create new cabal sandbox?
cabal install --dry-run --avoid-reinstalls should give you some output that indicates the installation plan for a particular package, or fail if it cannot avoid reinstalls due to dependencies.
However, sandboxes are really quite helpful. Independent of how you bootstrap your cabal installation (tarballs, distribution packages, etc.), you should probably add ~/.cabal/bin early in your path and then cabal install cabal-install. This should only fail if the latest version of cabal doesn't work on your version of ghc / base.
I was trying to install cabal-dev in my mac. After cloing, I tried to run ./bin/build. to get this error message.
cabal: cannot configure cabal-dev-0.9.1. It requires MonadRandom ==0.1.*, tar
==0.3.*, test-framework >=0.3 && <0.6 and test-framework-hunit >=0.2
There is no available version of MonadRandom that satisfies ==0.1.*
There is no available version of tar that satisfies ==0.3.*
There is no available version of test-framework that satisfies >=0.3 && <0.6
There is no available version of test-framework-hunit that satisfies >=0.2
What's wrong with this? How do I install the dependency files in Haskell?
I downloaded and installed from Haskell platform.
You don't have to use that build script; you can install cabal-dev just by running cabal install cabal-dev, which will automatically download and install cabal-dev and its dependencies.
But if you do want to use it, try cabal install --only-dependencies in cabal-dev's source directory first (the one with cabal-dev.cabal in it). That script's purpose is to avoid avoid installing into the global and user package databases — basically, it uses the same sandboxing cabal-dev itself does. It's probably not worth the effort, since cabal-dev installs just fine like every other program.
Issue the command cabal install cabal-dev. It will resolve the dependencies for you, assuming you have the standard cabal dist.