Skip to content

Commit 5f59b36

Browse files
author
pfalzgraf
committed
adds shell.nix, default.nix exports myHaskellPackages, updates README
1 parent d1e30d9 commit 5f59b36

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

README.md

+12-19
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ You need the `-n` to stop hoogle from trying to use https locally. You will need
6565

6666
### Add external tool to `default.nix`
6767

68-
The sources you pull down with `niv` are accessible under `sources.<name>`. Its a derivation with the attributes you need to fetch the source, not the source itself. If you want to pull in a source you need to either give it to a function that knows how to fetch the contents like `callCabal2nix` or if the source has a `default.nix` you can import it directly, like so: `import sources.niv {}`.
68+
The sources you pull down with `niv` are accessible under `sources.<name>` (fyi: `<name>` is the key in `sources.json`). However, that is a derivation with the attributes you need to fetch the source, not the source itself. If you want to pull in a source you need to either give it to a function that knows how to fetch the contents like `callCabal2nix` or if the source has a `default.nix` you can import it directly, like so: `import sources.<name> {}`.
6969

7070
---
7171

@@ -77,7 +77,7 @@ in
7777
inherit exe;
7878
inherit docker;
7979
### Added here
80-
src = import sources.niv {};
80+
src = import sources.<name> {};
8181
}
8282
8383
```
@@ -93,7 +93,7 @@ On the other hand here is an example with `callCabal2nix` adding the specific ve
9393
cabal-install
9494
### Added modified development tool here
9595
(pkgs.haskell.lib.justStaticExecutables
96-
(callCabal2nix "ghcid" (sources.ghcid) {}))
96+
(pkgs.haskellPackages.callCabal2nix "ghcid" (sources.ghcid) {}))
9797
ormolu
9898
hlint
9999
pkgs.niv
@@ -116,7 +116,7 @@ Then add it to the end of your `callCabal2nix` call:
116116

117117
```
118118
(pkgs.haskell.lib.justStaticExecutables
119-
(callCabal2nix "ghcid" (sources.ghcid) {inherit extra;}))
119+
(pkgs.haskellPackages.callCabal2nix "ghcid" (sources.ghcid) {inherit extra;}))
120120
```
121121

122122
Note: I am building `ghcid` with `haskellPackages` not `myHaskellPackages`. If the tool fails to build you might want to either use a different package set or modify one yourself so the tool has the right dependencies.
@@ -170,21 +170,9 @@ This will not only add `extra` to your project, but also build the documentation
170170

171171
### Override dependency in `default.nix`
172172

173-
If you want to override a dependency you add it like we did above with `extra`, just make sure the name is identical to what is in the package set. As you would expect, the name in the package set is the same as the name on Hackage. There are a few packages with multiple versions, like `zip` and `zip_1_4_1`.
173+
If you want to override a dependency you add it like we did above with `extra`, just make sure the name is identical to what is in the package set. As you would expect, the name in the package set is the same as the name on Hackage. However, there are a few packages with multiple versions, like `zip` and `zip_1_4_1`.
174174

175-
If you want to see exactly what is in your modified package set add this to your `default.nix` :
176-
177-
```
178-
in
179-
if pkgs.lib.inNixShell then shell else {
180-
inherit exe;
181-
inherit docker;
182-
### Added here
183-
inherit myHaskellPackages;
184-
}
185-
```
186-
187-
Then call `nix repl default.nix` and you will get this:
175+
If you want to see exactly what is in your modified package run `nix repl default.nix` and you will get this:
188176

189177
```
190178
@@ -200,7 +188,12 @@ Then you can tab complete to see what is in `myHaskellPackages`
200188
nix-repl> myHaskellPackages.ex<tab>
201189
```
202190

203-
Note: the reason we don't have this attribute added by default is you really only need this for debugging and wouldn't want your continuous integration to build the package set as an output of your project.
191+
This is also the best way to find out what versions of libraries are in a package set. Instead of having to add them to your cabal file to find out the version you can just view the version attribute. Again in `nix repl`
192+
193+
```
194+
nix-repl> myHaskellPackages.extra.version
195+
1.6.20
196+
```
204197

205198
### Deploy to Docker Image
206199

{{cookiecutter.project_name}}/default.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ let
3838
config.Cmd = [ "${exe}/bin/{{cookiecutter.project_name}}" ];
3939
};
4040
in
41-
if pkgs.lib.inNixShell then shell else {
41+
{
42+
inherit shell;
4243
inherit exe;
4344
inherit docker;
45+
inherit myHaskellPackages;
4446
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(import ./default.nix {}).shell

0 commit comments

Comments
 (0)