Skip to content

Commit baefab6

Browse files
authored
Merge branch 'master' into aarch64-native
2 parents 40397a3 + b059ec4 commit baefab6

File tree

43 files changed

+503
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+503
-336
lines changed

README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# `haskell.nix` is infrastructure for building Haskell packages with Nix
2+
3+
[![](https://badge.buildkite.com/d453edcd29bd2f8f3f3b32c9b7d6777a33773d9671c37a6ccc.svg?branch=master)](https://buildkite.com/input-output-hk/haskell-dot-nix)
4+
[![](https://img.shields.io/buildkite/c8d5a20d3ff0f440f82adb9190b43c16c91e5e47e8adfa867a/master.svg?label=nightly%20updates)](https://buildkite.com/input-output-hk/haskell-dot-nix-nightly-updates)
5+
6+
`haskell.nix` can automatically translate your Cabal or Stack project and
7+
its dependencies into Nix code.
8+
9+
## [Documentation](https://input-output-hk.github.io/haskell.nix/)
10+
11+
## Getting started
12+
13+
### a) Using `cabal.project`
14+
15+
Add a `default.nix`:
16+
17+
```nix
18+
let
19+
# Fetch the latest haskell.nix and import its default.nix
20+
haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
21+
22+
# haskell.nix provides access to the nixpkgs pins which are used by our CI, hence
23+
# you will be more likely to get cache hits when using these.
24+
# But you can also just use your own, e.g. '<nixpkgs>'
25+
nixpkgsSrc = haskellNix.sources.nixpkgs-2003;
26+
27+
# haskell.nix provides some arguments to be passed to nixpkgs, including some patches
28+
# and also the haskell.nix functionality itself as an overlay.
29+
nixpkgsArgs = haskellNix.nixpkgsArgs;
30+
in
31+
{ pkgs ? import nixpkgsSrc nixpkgsArgs
32+
, haskellCompiler ? "ghc865"
33+
}:
34+
35+
# 'cabalProject' generates a package set based on a cabal.project (and the corresponding .cabal files)
36+
pkgs.haskell-nix.cabalProject {
37+
# 'cleanGit' cleans a source directory based on the files known by git
38+
src = pkgs.haskell-nix.haskellLib.cleanGit { name = "haskell-nix-project"; src = ./.; };
39+
compiler-nix-name = haskellCompiler;
40+
}
41+
```
42+
43+
Note that you'll need to add a comment specifying the expected sha256
44+
output for your `source-repository-packages` in your `cabal.project`
45+
file:
46+
47+
```
48+
source-repository-package
49+
type: git
50+
location: https://github.com/input-output-hk/iohk-monitoring-framework
51+
subdir: plugins/backend-editor
52+
tag: 4956b32f039579a0e7e4fd10793f65b4c77d9044
53+
--sha256: 03lyb2m4i6p7rpjqarnhsx21nx48fwk6rzsrx15k6274a4bv0pix
54+
```
55+
56+
### b) Using `stack.yaml`
57+
58+
Add a `default.nix`:
59+
60+
```nix
61+
let
62+
haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
63+
nixpkgsSrc = haskellNix.sources.nixpkgs-2003;
64+
nixpkgsArgs = haskellNix.nixpkgsArgs;
65+
in
66+
{ pkgs ? import nixpkgsSrc nixpkgsArgs
67+
}:
68+
pkgs.haskell-nix.stackProject {
69+
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
70+
}
71+
```
72+
73+
To build the library component of a package in the project run:
74+
75+
```shell
76+
nix build -f . your-package-name.components.library
77+
```
78+
79+
To build an executable:
80+
81+
```shell
82+
nix build -f . your-package-name.components.exes.your-exe-name
83+
```
84+
85+
To open a shell for use with `cabal` run:
86+
87+
```shell
88+
nix-shell -A shellFor
89+
cabal new-build your-package-name
90+
cabal new-repl your-package-name:library:your-package-name
91+
```
92+
93+
## Using binary Cache to speed up compilation
94+
95+
To use precompiled binaries you'll need:
96+
97+
- to configure a binary cache by following instructions on [iohk.cachix.org](https://iohk.cachix.org).
98+
- to pin `nixpkgs` according to [nix/sources.json](nix/sources.json).
99+
100+
101+
## Related repos
102+
103+
The `haskell.nix` repository contains the runtime system for building
104+
Haskell packages in Nix. It depends on other repos, which are:
105+
106+
- [nix-tools](https://github.com/input-output-hk/nix-tools) — provides the programs for generating Nix expressions from Haskell projects.
107+
108+
- [hackage.nix](https://github.com/input-output-hk/hackage.nix) — the latest contents of the [Hackage](https://hackage.haskell.org/) databases, converted to Nix expressions.
109+
110+
- [stackage.nix](https://github.com/input-output-hk/stackage.nix) — all of the [Stackage](https://www.stackage.org/) snapshots, converted to Nix expressions.
111+
112+
## IRC Channel
113+
114+
Join the [#haskell.nix](https://www.irccloud.com/invite?channel=%23haskell.nix&hostname=irc.freenode.net&port=6697&ssl=1) channel on [irc.freenode.net](https://freenode.net/) to get help or discuss
115+
the development of `haskell.nix` and `nix-tools`.

README.org

Lines changed: 0 additions & 119 deletions
This file was deleted.

build.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ in rec {
4646
# use)
4747
check-hydra = pkgs.buildPackages.callPackage ./scripts/check-hydra.nix {};
4848
check-closure-size = pkgs.buildPackages.callPackage ./scripts/check-closure-size.nix {
49-
inherit (haskell) nix-tools;
49+
# Includes cabal-install and hpack since these are commonly used.
50+
nix-tools = pkgs.linkFarm "common-tools" [
51+
{ name = "nix-tools"; path = haskell.nix-tools; }
52+
{ name = "cabal-install"; path = haskell.cabal-install; }
53+
{ name = "hpack"; path = haskell.haskellPackages.hpack.components.exes.hpack; }
54+
];
5055
};
5156
};
5257

ci.nix

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
{ supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ]
44
, ifdLevel ? 3
55
# Whether or not we are evaluating in restricted mode. This is true in Hydra, but not in Hercules.
6-
, restrictEval ? false }:
7-
let
6+
, restrictEval ? false
7+
, checkMaterialization ? false }:
8+
let
89
inherit (import ./ci-lib.nix) dimension platformFilterGeneric filterAttrsOnlyRecursive;
9-
inherit (import ./default.nix { checkMaterialization = false; }) sources nixpkgsArgs;
10+
sources = import ./nix/sources.nix {};
1011
nixpkgsVersions = {
1112
"R1909" = "nixpkgs-1909";
1213
"R2003" = "nixpkgs-2003";
1314
};
15+
compilerNixNames = builtins.mapAttrs (defaultCompilerNixName: _:
16+
(import ./default.nix { inherit checkMaterialization defaultCompilerNixName; }).nixpkgsArgs) {
17+
ghc865 = {};
18+
ghc883 = {};
19+
};
1420
systems = nixpkgs: nixpkgs.lib.filterAttrs (_: v: builtins.elem v supportedSystems) {
1521
# I wanted to take these from 'lib.systems.examples', but apparently there isn't one for linux!
1622
linux = "x86_64-linux";
@@ -33,54 +39,45 @@ dimension "Nixpkgs version" nixpkgsVersions (nixpkgsName: nixpkgs-pin:
3339
let pinnedNixpkgsSrc = sources.${nixpkgs-pin};
3440
# We need this for generic nixpkgs stuff at the right version
3541
genericPkgs = import pinnedNixpkgsSrc {};
36-
in dimension "System" (systems genericPkgs) (systemName: system:
37-
let pkgs = import pinnedNixpkgsSrc (nixpkgsArgs // { inherit system; });
38-
build = import ./build.nix { inherit pkgs ifdLevel; };
39-
platformFilter = platformFilterGeneric pkgs system;
40-
compilers = {
41-
inherit (pkgs.haskell-nix.compiler) ghc865 ghc883;
42-
};
43-
in filterAttrsOnlyRecursive (_: v: platformFilter v) {
44-
# Native builds
45-
# TODO: can we merge this into the general case by picking an appropriate "cross system" to mean native?
46-
native = pkgs.recurseIntoAttrs ({
47-
inherit (build) tests tools maintainer-scripts maintainer-script-cache;
48-
ghc = pkgs.recurseIntoAttrs compilers;
49-
} // pkgs.lib.optionalAttrs (ifdLevel >= 1) {
50-
iserv-proxy = pkgs.recurseIntoAttrs (
51-
pkgs.lib.mapAttrs (ghcName: _:
52-
pkgs.ghc-extra-packages."${ghcName}".iserv-proxy.components.exes.iserv-proxy
53-
) compilers);
54-
} // pkgs.lib.optionalAttrs (ifdLevel >= 2) {
55-
hello = (pkgs.haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; }).components.exes.hello;
56-
});
57-
}
58-
//
59-
dimension "Cross system" (crossSystems nixpkgsName genericPkgs system) (crossSystemName: crossSystem:
60-
# Cross builds
61-
let pkgs = import pinnedNixpkgsSrc (nixpkgsArgs // { inherit system crossSystem; });
42+
in dimension "GHC version" compilerNixNames (compilerNixName: nixpkgsArgs:
43+
dimension "System" (systems genericPkgs) (systemName: system:
44+
let pkgs = import pinnedNixpkgsSrc (nixpkgsArgs // { inherit system; });
6245
build = import ./build.nix { inherit pkgs ifdLevel; };
63-
in pkgs.recurseIntoAttrs (pkgs.lib.optionalAttrs (ifdLevel >= 1) {
64-
ghc = pkgs.recurseIntoAttrs compilers;
65-
# TODO: look into making tools work when cross compiling
66-
# inherit (build) tools;
67-
} // pkgs.lib.optionalAttrs (ifdLevel >= 2) {
68-
remote-iserv = pkgs.recurseIntoAttrs (
69-
pkgs.lib.mapAttrs (ghcName: _:
70-
pkgs.ghc-extra-packages."${ghcName}".remote-iserv.components.exes.remote-iserv
71-
) compilers);
72-
iserv-proxy = pkgs.recurseIntoAttrs (
73-
pkgs.lib.mapAttrs (ghcName: _:
74-
pkgs.ghc-extra-packages."${ghcName}".iserv-proxy.components.exes.iserv-proxy
75-
) compilers);
76-
} // pkgs.lib.optionalAttrs (ifdLevel >= 3) {
77-
hello = (pkgs.haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; }).components.exes.hello;
46+
platformFilter = platformFilterGeneric pkgs system;
47+
in filterAttrsOnlyRecursive (_: v: platformFilter v) {
48+
# Native builds
49+
# TODO: can we merge this into the general case by picking an appropriate "cross system" to mean native?
50+
native = pkgs.recurseIntoAttrs ({
51+
inherit (build) tests tools maintainer-scripts maintainer-script-cache;
52+
ghc = pkgs.haskell-nix.compiler."${compilerNixName}";
53+
} // pkgs.lib.optionalAttrs (ifdLevel >= 1) {
54+
iserv-proxy = pkgs.ghc-extra-packages."${compilerNixName}".iserv-proxy.components.exes.iserv-proxy;
55+
} // pkgs.lib.optionalAttrs (ifdLevel >= 2) {
56+
hello = (pkgs.haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; }).components.exes.hello;
57+
});
7858
}
7959
//
80-
# Tests are broken on aarch64 cross https://github.com/input-output-hk/haskell.nix/issues/513
81-
pkgs.lib.optionalAttrs (crossSystemName != "aarch64-multiplatform") {
82-
inherit (build) tests;
83-
})
60+
dimension "Cross system" (crossSystems nixpkgsName genericPkgs system) (crossSystemName: crossSystem:
61+
# Cross builds
62+
let pkgs = import pinnedNixpkgsSrc (nixpkgsArgs // { inherit system crossSystem; });
63+
build = import ./build.nix { inherit pkgs ifdLevel; };
64+
in pkgs.recurseIntoAttrs (pkgs.lib.optionalAttrs (ifdLevel >= 1) {
65+
# TODO: look into cross compiling ghc itself
66+
# ghc = pkgs.haskell-nix.compiler."${compilerNixName}";
67+
# TODO: look into making tools work when cross compiling
68+
# inherit (build) tools;
69+
} // pkgs.lib.optionalAttrs (ifdLevel >= 2) {
70+
remote-iserv = pkgs.ghc-extra-packages."${compilerNixName}".remote-iserv.components.exes.remote-iserv;
71+
iserv-proxy = pkgs.ghc-extra-packages."${compilerNixName}".iserv-proxy.components.exes.iserv-proxy;
72+
} // pkgs.lib.optionalAttrs (ifdLevel >= 3) {
73+
hello = (pkgs.haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; }).components.exes.hello;
74+
}
75+
//
76+
# Tests are broken on aarch64 cross https://github.com/input-output-hk/haskell.nix/issues/513
77+
pkgs.lib.optionalAttrs (crossSystemName != "aarch64-multiplatform") {
78+
inherit (build) tests;
79+
})
80+
)
8481
)
8582
)
8683
)

0 commit comments

Comments
 (0)