forked from jyrimatti/haskell-dev-env
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
402 lines (313 loc) · 18.5 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
### Customizable Haskell development environment with IDEs in one VagrantFile
### #vagrant #virtualbox #nixos #nix #haskell #ghcjs
# 1) put this file to the directory you wish to mount as /vagrant
# 2) install an XServer (if you want to run GUI apps)
# 3) install Vagrant
# 4) > vagrant plugin install vagrant-nixos
# 5) > vagrant up
# 6) > vagrant ssh # or vagrant ssh -- -Y if you want to run GUI apps)
# This NixOS uses NixPKGS GIT repo for all the latest and greatest stuff.
# A specific revision is checked out to ensure an eternally consistent environment.
# You can upgrade if you wish by checking out a more recent revision:
# > cd /home/vagrant/nixpkgs && git pull origin master
# Pretty much nothing at all is installed in the root shell.
# You can start a suitable nix-shell the usual way, or use these predefined commands:
# Run a build-independent cabal command, e.g. init a new cabal project:
# > cabal.sh init
# test X11 is working:
# > nix-shell -p xeyes --command 'xeyes'
# Start Firefox:
# > firefox.sh
# Start a cabal project shell for a cabal-project in the current dir:
# > shell.sh
# The following scripts are intended to be run within a project-specific shell (started for example via shell.sh):
# Hoogle:
# > hoogle.sh 'Maybe a -> a'
# Continuously-compile with GHC (without cabal) and restart app whenever a source file is changed:
# > cc.sh
# Start Sublime Text:
# > sublime.sh
# Start Atom.IO:
# > atom.sh
# Start Emacs:
# > emacs.sh
# Start Leksah:
# TODO
# Start Emacs:
# TODO
# Start Vim:
# TODO
Vagrant.configure("2") do |config|
# whatever 64-bit nixos box
config.vm.box = "larryweya/nixos-14.12_64"
config.vm.provider 'virtualbox' do |v|
v.memory = 2048
v.cpus = 2
# v.gui = true # enable this if you prefer the GUI
end
# open a port for browsing web apps from the host machine
#config.vm.network "forwarded_port", guest: 80, host: 8181
# forward X11 to run GUI apps
config.ssh.forward_x11 = true
# nixos-stuff
config.vm.provision :nixos, :expression => {
environment: {
systemPackages: [:'python34Packages.pygments']
},
programs: {
# running GUI apps through SSH seems to need this...
ssh: {
setXAuthLocation: true
},
zsh: {
enable: true
}
},
users: {
defaultUserShell: "/run/current-system/sw/bin/zsh"
},
security: {
# either NixOS in general or just the used box seems to need these...
sudo: {
enable: true,
wheelNeedsPassword: false
}
},
services: {
# TODO: make work for GHCJS
httpd: {
adminAddr: "vagrant@localhost",
enable: true,
documentRoot: "/home/vagrant/.cabal/bin"
}
},
swapDevices: [{
device: '/swap',
size: 2048
}],
nix: {
# Use at most one cache due to a GHC bug:
# http://hydra.nixos.org/build/24422016/download/1/nixpkgs/manual.html#how-to-recover-from-ghcs-infamous-non-deterministic-library-id-bug
# https://ghc.haskell.org/trac/ghc/ticket/4012
# Remove caches altogether if still fails.
binaryCaches: [ "https://hydra.nixos.org" ],
trustedBinaryCaches: [ "https://hydra.nixos.org" ]
}
}
# the used box does not work with vagrant-nixos-plugin out-of-the-box, thus these hacks
config.vm.provision :shell,
inline: "test -e /etc/nixos/configuration.orig.nix || (mv /etc/nixos/configuration.nix /etc/nixos/configuration.orig.nix && echo '{ config, pkgs, ... }: { imports = [ ./configuration.orig.nix ./vagrant.nix ];}' > /etc/nixos/configuration.nix)"
# "install" NixPkgs GIT repo
config.vm.provision :shell,
inline: $initpkgs,
privileged: false
# update nixos
config.vm.provision :shell,
inline: 'sudo nixos-rebuild switch'
# install oh-my-zsh
config.vm.provision :shell,
inline: $ohmyzsh,
privileged: false
# init config.nix to allow some packages
config.vm.provision :shell,
inline: "test -e /home/vagrant/.nixpkgs || (mkdir -p /home/vagrant/.nixpkgs && echo '{ allowUnfree = true; allowBroken = true; }' > /home/vagrant/.nixpkgs/config.nix)",
privileged: false
# generic shell.nix for invoking different default.nix-files
config.vm.provision :shell,
inline: $shellnix,
privileged: false
# initialize a directory for scripts
config.vm.provision :shell,
inline: "test -e /home/vagrant/bin || (mkdir /home/vagrant/bin & export PATH=$PATH:/home/vagrant/bin/)",
privileged: false
# script for running some cabal commands "without cabal".
config.vm.provision :shell,
inline: $cabal,
privileged: false
# script for starting a new shell with cabal-dependencies from a cabal project in the current directory
config.vm.provision :shell,
inline: $shell,
privileged: false
# script for querying hoogle
config.vm.provision :shell,
inline: $hoogle,
privileged: false
# script for continuous-compilation with GHC
config.vm.provision :shell,
inline: $cc,
privileged: false
# script for running Sublime Text with Haskell development tools
config.vm.provision :shell,
inline: $sublime,
privileged: false
# script for running Atom.IO with Haskell development tools
config.vm.provision :shell,
inline: $atom,
privileged: false
# script for running Emacs editor
config.vm.provision :shell,
inline: $emacs,
privileged: false
# script for running Leksah editor
config.vm.provision :shell,
inline: $leksah,
privileged: false
# script for running Firefox browser
config.vm.provision :shell,
inline: $firefox,
privileged: false
# script for testing
config.vm.provision :shell,
inline: $test,
privileged: false
# permissions for Apache to see GHCJS apps, and for Cabal to install GHCJS apps.
config.vm.provision :shell,
inline: 'chmod o+x /home/vagrant && (test -e /home/vagrant/.cabal || mkdir /home/vagrant/.cabal) && chown vagrant:vagrant /home/vagrant/.cabal && (test -e /home/vagrant/.cabal/bin || mkdir /home/vagrant/.cabal/bin) && chown vagrant:vagrant /home/vagrant/.cabal/bin'
end
$initpkgs = <<SCRIPT
test -e /home/vagrant/nixpkgs || (
git clone https://github.com/NixOS/nixpkgs /home/vagrant/nixpkgs &&
# "install" cloned git repo
ln -s /home/vagrant/nixpkgs /home/vagrant/.nix-defexpr/nixpkgs &&
# remove old nixos channels
rm -rf /home/vagrant/.nix-defexpr/channels &&
rm -rf /home/vagrant/.nix-defexpr/channels_root
)
echo 'export NIX_PATH=nixpkgs=/home/vagrant/nixpkgs:$NIX_PATH' > /home/vagrant/.profile
cd /home/vagrant/nixpkgs
git fetch
# NixPkgs revision to use. Feel free to update, but note that in master branch stuff seems to break a lot...
git checkout '75cf3a27670ae0213aa12feb32ed563a4dbf3a8c'
SCRIPT
$ohmyzsh = <<SCRIPT
test -e /home/vagrant/.zshrc || (
(zsh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" || true) &&
echo 'source /home/vagrant/.profile' >> /home/vagrant/.zshrc
)
echo 'PROMPT="${PROMPT_PREFIX}λ $PROMPT"' >> /home/vagrant/.profile
echo 'alias cat=colorize' >> /home/vagrant/.profile
echo 'PATH="$PATH:$PATH_SUFFIX"' >> /home/vagrant/.profile
sed -i "s/plugins=\(git\)/plugins=(git mercurial colorize cabal)/g" /home/vagrant/.zshrc
SCRIPT
$shellnix = <<SCRIPT
echo '{app, compiler ? null, overrides ? (self: {})}:' > /home/vagrant/shell.nix
echo 'with (import <nixpkgs> {}).pkgs;' >> /home/vagrant/shell.nix
echo 'let hsp = if compiler == null then pkgs.haskellPackages else pkgs.haskell.packages.${compiler};' >> /home/vagrant/shell.nix
echo ' hsPkgs = hsp.override { overrides = self: super: overrides self; };' >> /home/vagrant/shell.nix
echo ' appPackage = with hsPkgs; callPackage app {};' >> /home/vagrant/shell.nix
echo 'in pkgs.lib.overrideDerivation appPackage.env (old: {buildInputs = old.buildInputs ++ [pkgs.haskellPackages.cabal-install hsPkgs.ghc];})' >> /home/vagrant/shell.nix
SCRIPT
# TODO: https://github.com/NixOS/nix/issues/498
# zsh in nix-shell does not work yet, so need to use --command with a twist
$shell = <<SCRIPT
echo '#!/bin/sh' > /home/vagrant/bin/shell.sh
echo 'set -u' >> /home/vagrant/bin/shell.sh
echo "def='(s: {})'" >> /home/vagrant/bin/shell.sh
echo 'overrides="${1:-$def}"' >> /home/vagrant/bin/shell.sh
echo 'app=$(if [ -f "$PWD/shell.nix" ]; then echo "$PWD/shell.nix"; else echo "$PWD/default.nix"; fi;)' >> /home/vagrant/bin/shell.sh
echo 'nix-shell -p haskellPackages.cabal2nix --command "cabal2nix . > default.nix"' >> /home/vagrant/bin/shell.sh
echo 'foo=$(grep ghcjs $app)' >> /home/vagrant/bin/shell.sh
echo 'if [ $? -eq 0 ]; then' >> /home/vagrant/bin/shell.sh
echo ' nix-shell /home/vagrant/shell.nix --arg app $app --arg overrides "$overrides" --command "PATH_SUFFIX=\$PATH PROMPT_PREFIX='"'"'%{\\$fg_bold[red]%}'"'"' exec zsh; return" --argstr compiler ghcjs' >> /home/vagrant/bin/shell.sh
echo 'else' >> /home/vagrant/bin/shell.sh
echo ' bar=$(grep haste-compiler $app)' >> /home/vagrant/bin/shell.sh
echo ' if [ $? -eq 0 ]; then' >> /home/vagrant/bin/shell.sh
echo ' nix-shell /home/vagrant/shell.nix --arg app $app --arg overrides "$overrides" --command "PATH_SUFFIX=\$PATH PROMPT_PREFIX='"'"'%{\\$fg_bold[red]%}'"'"' exec zsh; return" --argstr compiler ghc784' >> /home/vagrant/bin/shell.sh
echo ' else' >> /home/vagrant/bin/shell.sh
echo ' nix-shell /home/vagrant/shell.nix --arg app $app --arg overrides "$overrides" --command "PATH_SUFFIX=\$PATH PROMPT_PREFIX='"'"'%{\\$fg_bold[red]%}'"'"' exec zsh; return"' >> /home/vagrant/bin/shell.sh
echo ' fi' >> /home/vagrant/bin/shell.sh
echo 'fi' >> /home/vagrant/bin/shell.sh
chmod u+x /home/vagrant/bin/shell.sh
SCRIPT
$cabal = <<SCRIPT
echo '#!/bin/sh' > /home/vagrant/bin/cabal.sh
echo 'set -eu' >> /home/vagrant/bin/cabal.sh
echo 'nix-shell -p haskellPackages.cabal-install -p haskellPackages.ghc --command "cabal $*"' >> /home/vagrant/bin/cabal.sh
chmod u+x /home/vagrant/bin/cabal.sh
SCRIPT
$hoogle = <<SCRIPT
echo '#!/bin/sh' > /home/vagrant/bin/hoogle.sh
echo 'set -eu' >> /home/vagrant/bin/hoogle.sh
echo 'cd /home/vagrant/hoogledb' >> /home/vagrant/bin/hoogle.sh
echo 'nix-shell -p haskellPackages.hoogle --command "hoogle data all -d /home/vagrant/hoogledb && hoogle $*"' >> /home/vagrant/bin/hoogle.sh
chmod u+x /home/vagrant/bin/hoogle.sh
SCRIPT
$sublime = <<SCRIPT
echo '#!/bin/sh' > /home/vagrant/bin/sublime.sh
echo 'set -eu' >> /home/vagrant/bin/sublime.sh
echo 'nix-shell -p haskellPackages.stylish-haskell -p haskellPackages.hsdev -p sublime3 --command "sublime $*"' >> /home/vagrant/bin/sublime.sh
chmod u+x /home/vagrant/bin/sublime.sh
test -e /home/vagrant/.config/sublime-text-3 || (
mkdir -p "/home/vagrant/.config/sublime-text-3/Installed Packages" &&
curl https://packagecontrol.io/Package%20Control.sublime-package > "/home/vagrant/.config/sublime-text-3/Installed Packages/Package Control.sublime-package"
)
test -e /home/vagrant/.config/sublime-text-3/Packages || (
mkdir -p /home/vagrant/.config/sublime-text-3/Packages/
)
test -e /home/vagrant/.config/sublime-text-3/Packages/SublimeHaskell || (
git clone https://github.com/SublimeHaskell/SublimeHaskell.git /home/vagrant/.config/sublime-text-3/Packages/SublimeHaskell &&
(test -e /home/vagrant/.config/sublime-text-3/Packages/User || mkdir /home/vagrant/.config/sublime-text-3/Packages/User) &&
echo '{ "enable_hdevtools": false, "enable_hsdev": true }' > /home/vagrant/.config/sublime-text-3/Packages/User/SublimeHaskell.sublime-settings
)
cd /home/vagrant/.config/sublime-text-3/Packages/SublimeHaskell
git pull
git checkout hsdev
git checkout 'c1f92945bfbc3b52c719d4cb8f26c1eb4fd5b27b'
SCRIPT
$atom = <<SCRIPT
echo '#!/bin/sh' > /home/vagrant/bin/atom.sh
echo 'set -eu' >> /home/vagrant/bin/atom.sh
echo 'nix-shell -p atom --command "apm install language-haskell haskell-ghc-mod ide-haskell autocomplete-haskell"' >> /home/vagrant/bin/atom.sh
echo 'nix-shell -p "pkgs.haskellPackages.ghcWithPackages (pkgs: [pkgs.ghc-mod])" -p haskellPackages.cabal-install -p haskellPackages.hlint -p haskellPackages.stylish-haskell -p atom --command "atom $*"' >> /home/vagrant/bin/atom.sh
chmod u+x /home/vagrant/bin/atom.sh
SCRIPT
$emacs = <<SCRIPT
test -e /home/vagrant/.spacemacs || (
git clone --recursive https://github.com/syl20bnr/spacemacs /home/vagrant/.emacs.d &&
cp /home/vagrant/.emacs.d/core/templates/.spacemacs.template /home/vagrant/.spacemacs &&
sed -i "s/emacs-lisp/emacs-lisp (haskell :variables haskell-enable-ghci-ng-support t)/g" /home/vagrant/.spacemacs &&
sed -i "s/dotspacemacs-excluded-packages '()/dotspacemacs-excluded-packages '(exec-path-from-shell)/g" /home/vagrant/.spacemacs
)
cd /home/vagrant/.emacs.d
git pull
echo '#!/bin/sh' > /home/vagrant/bin/emacs.sh
echo 'set -eu' >> /home/vagrant/bin/emacs.sh
echo 'nix-shell -p "pkgs.haskellPackages.ghcWithPackages (pkgs: [pkgs.ghc-mod])" -p haskellPackages.cabal-install -p haskellPackages.hlint -p haskellPackages.stylish-haskell -p haskellPackages.hasktags -p emacs --command "emacs $*"' >> /home/vagrant/bin/emacs.sh
chmod u+x /home/vagrant/bin/emacs.sh
SCRIPT
$leksah = <<SCRIPT
echo '#!/bin/sh' > /home/vagrant/bin/leksah.sh
echo 'set -eu' >> /home/vagrant/bin/leksah.sh
echo 'nix-shell -p leksah --command "leksah $*"' >> /home/vagrant/bin/leksah.sh
chmod u+x /home/vagrant/bin/leksah.sh
SCRIPT
$firefox = <<SCRIPT
echo '#!/bin/sh' > /home/vagrant/bin/firefox.sh
echo 'set -eu' >> /home/vagrant/bin/firefox.sh
echo 'nix-shell -p firefox --command "firefox $*"' >> /home/vagrant/bin/firefox.sh
chmod u+x /home/vagrant/bin/firefox.sh
SCRIPT
$cc = <<SCRIPT
echo '#!/bin/sh' > /home/vagrant/bin/cc.sh
echo 'set -eu' >> /home/vagrant/bin/cc.sh
echo 'PID=$$' >> /home/vagrant/bin/cc.sh
echo 'while true; do' >> /home/vagrant/bin/cc.sh
echo ' test -e build || mkdir build' >> /home/vagrant/bin/cc.sh
echo ' time ghc --make -outputdir build -o build/prog -isrc src/Main.hs $@' >> /home/vagrant/bin/cc.sh
echo ' build/prog &' >> /home/vagrant/bin/cc.sh
echo ' nix-shell -p inotifyTools --command "inotifywait -e modify -e move -e create -e delete src || true"' >> /home/vagrant/bin/cc.sh
echo ' pkill -P $PID || true' >> /home/vagrant/bin/cc.sh
echo 'done' >> /home/vagrant/bin/cc.sh
chmod u+x /home/vagrant/bin/cc.sh
SCRIPT
$test = <<SCRIPT
echo '#!/bin/sh' > /home/vagrant/bin/test.sh
echo 'set -eu' >> /home/vagrant/bin/test.sh
echo 'cd /tmp/ && cabal.sh init -n' >> /home/vagrant/bin/test.sh
echo 'firefox.sh' >> /home/vagrant/bin/test.sh
echo 'emacs.sh' >> /home/vagrant/bin/test.sh
echo 'sublime.sh' >> /home/vagrant/bin/test.sh
echo 'atom.sh' >> /home/vagrant/bin/test.sh
echo "hoogle.sh 'Maybe a -> a'" >> /home/vagrant/bin/test.sh
chmod u+x /home/vagrant/bin/test.sh
SCRIPT