-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVagrantfile
231 lines (184 loc) · 8.02 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
### 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
config.vm.synced_folder "scripts/", "/home/vagrant/bin/"
# 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
# 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 Sublime Text with Haskell development tools
config.vm.provision :shell,
inline: $sublime,
privileged: false
# script for running Emacs editor
config.vm.provision :shell,
inline: $emacs,
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 'f16533449269bf798cd49eac41ba876b71eeddc0'
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
$sublime = <<SCRIPT
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
$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
SCRIPT