1
1
# Custom Snapshots
2
2
3
- Custom snapshots allow you to create your own snapshots, which provide a list of
4
- specific hackage packages to use, along with flags and ghc-options. The
5
- definition of a basic snapshot looks like the following:
3
+ Custom snapshots were totally reworked with the extensible snapshots
4
+ overhaul in Stack 1.6.0, see
5
+ [ the writeup] ( https://www.fpcomplete.com/blog/2017/07/stacks-new-extensible-snapshots )
6
+ and
7
+ [ PR #3249 ] ( https://github.com/commercialhaskell/stack/pull/3249 ) ). This
8
+ documentation covers the new syntax only.
9
+
10
+ Custom snapshots allow you to create your own snapshots, which provide
11
+ a list of packages to use, along with flags, ghc-options, and a few
12
+ other settings. Custom snapshots may extend any other snapshot that
13
+ can be specified in a ` resolver ` field. The packages specified follow
14
+ the syntax of ` extra-deps ` in the ` stack.yaml ` file, with one
15
+ exception: to ensure reproducibility of snapshots, local directories
16
+ are not allowed for custom snapshots (as they are expected to change
17
+ regularly).
6
18
7
19
``` yaml
8
- resolver : ghc-8.0
20
+ resolver : lts-8.21 # Inherits GHC version and package set
21
+ compiler : ghc-8.0.1 # Overwrites GHC version in the resolver, optional
9
22
23
+ name : my-snapshot # User-friendly name
24
+
25
+ # Additional packages, follows extra-deps syntax
10
26
packages :
11
- - unordered-containers-0.2.7.1
12
- - hashable-1.2.4.0
13
- - text-1.2.2.1
27
+ - unordered-containers-0.2.7.1
28
+ - hashable-1.2.4.0
29
+ - text-1.2.2.1
14
30
31
+ # Override flags, can also override flags in the parent snapshot
15
32
flags :
16
33
unordered-containers :
17
34
debug : true
35
+
36
+ # Packages from the parent snapshot to ignore
37
+ drop-packages :
38
+ - wai-extra
39
+
40
+ # Packages which should be hidden (affects script command's import
41
+ # parser
42
+ hidden :
43
+ wai : true
44
+ warp : false
45
+
46
+ # Set GHC options for specific packages
47
+ ghc-options :
48
+ warp :
49
+ - -O2
18
50
` ` `
19
51
20
52
If you put this in a ` snapshot.yaml` file in the same directory as your project,
21
53
you can now use the custom snapshot like this :
22
54
23
55
` ` ` yaml
24
- resolver:
25
- name: simple-snapshot # Human readable name for the snapshot
26
- location: simple-snapshot.yaml
56
+ resolver: snapshot.yaml
27
57
` ` `
28
58
29
59
This is an example of a custom snapshot stored in the filesystem. They are
@@ -38,24 +68,6 @@ For efficiency, URLs are treated differently. If I uploaded the snapshot to
38
68
` https://domain.org/snapshot-1.yaml` , it is expected to be immutable. If you
39
69
change that file, then you lose any reproducibility guarantees.
40
70
41
- # # Extending snapshots
42
-
43
- The example custom snapshot above uses a compiler resolver, and so has few
44
- packages. We can also extend existing snapshots, by using the usual
45
- [resolver setting found in stack configurations](yaml_configuration.md#resolver).
46
- All possible resolver choices are valid, so this means that custom snapshots can
47
- even extend other custom snapshots.
48
-
49
- Lets say that we want to use `lts-7.1`, but use a different version of `text`
50
- than the one it comes with, `1.2.2.1`. To downgrade it to `1.2.2.0`, we need a
51
- custom snapshot file with the following :
52
-
53
- ` ` ` yaml
54
- resolver: lts-7.1
55
- packages:
56
- - text-1.2.2.0
57
- ` ` `
58
-
59
71
# ## Overriding the compiler
60
72
61
73
The following snapshot specification will be identical to `lts-7.1`, but instead
@@ -117,57 +129,3 @@ ghc-options:
117
129
text:
118
130
developer: true
119
131
` ` `
120
-
121
- # # YAML format
122
-
123
- In summary, the YAML format of custom snapshots has the following fields which
124
- are directly related to the same fields in the
125
- [build configuration format](yaml_configuration.md) :
126
-
127
- * `resolver`, which specifies which snapshot to extend. It takes the same values
128
- as the [`resolver` field in stack.yaml](yaml_configuration.md#resolver).
129
-
130
- * `compiler`, which specifies or overrides the selection of compiler. If
131
- ` resolver` is absent, then a specification of `compiler` is required. Its
132
- semantics are the same as the
133
- [`compiler` field in stack.yaml](yaml_configuration.md#compiler).
134
-
135
- Some fields look similar, but behave differently :
136
-
137
- * `flags` specifies which cabal flags to use with each package. In order to
138
- specify a flag for a package, it *must* be listed in the `packages` list.
139
-
140
- * `ghc-options`, which specifies which cabal flags to use with each package. In
141
- order to specify ghc-options for a package, it *must* be listed in the
142
- ` packages` list. The `*` member of the map specifies flags that apply to every
143
- package in the `packages` list.
144
-
145
- There are two fields which work differently than in the build configuration
146
- format :
147
-
148
- * `packages`, which specifies a list of hackage package versions. Note that
149
- when a package version is overridden, no `flags` or `ghc-options` are taken
150
- from the snapshot that is being extended. If you want the same options as the
151
- snapshot being extended, they must be re-specified.
152
-
153
- * `drop-packages`, which specifies a list of packages to drop from the snapshot
154
- being overridden.
155
-
156
- # # Future enhancements
157
-
158
- We plan to enhance extensible snapshots in several ways in the future. See
159
- [issue # 1265, about "implicit snapshots"](https://github.com/commercialhaskell/stack/issues/1265).
160
- In summary, in the future :
161
-
162
- 1) It will be possible to use a specific git repository + commit hash in the
163
- ` packages` list, like in regular stack.yaml configuration. Currently, custom
164
- snapshots only work with packages on hackage.
165
-
166
- 2) `stack.yaml` configurations will implicitly create a snapshot. This means
167
- that the non-local packages will get shared between your projects, so there is
168
- less redundant compilation!
169
-
170
- 3) `flags` and `ghc-options` for packages which are not listed in `packages` are
171
- silently ignored. See
172
- [#2654](https://github.com/commercialhaskell/stack/issues/2654) for the current
173
- status of this.
0 commit comments