forked from diku-dk/futhark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
128 lines (114 loc) · 4.55 KB
/
default.nix
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
# This default.nix builds a tarball containing a statically linked
# Futhark binary and some manpages. Likely to only work on linux.
#
# Just run 'nix-build' and fish the tarball out of 'result/'.
#
# For the Haskell dependencies that diverge from our pinned Nixpkgs,
# we use cabal2nix like thus:
#
# $ cabal2nix cabal://sexp-grammar-2.2.1 > nix/sexp-grammar.nix
#
# And then import them into the configuration. Although note that
# Nixpkgs also tends to contain the newest version of each Hackage
# package, even if it is not the default.
#
# To update the Nixpkgs snapshot (which also includes tooling), use:
#
# $ niv update nixpkgs -b master
#
# Also remember this guide: https://github.com/Gabriel439/haskell-nix/blob/master/project1/README.md
{ suffix ? "nightly",
commit ? "" }:
let
config = {
packageOverrides = pkgs: rec {
haskellPackages = pkgs.haskellPackages.override {
overrides = haskellPackagesNew: haskellPackagesOld: rec {
futhark-data =
haskellPackagesNew.callPackage ./nix/futhark-data.nix { };
futhark-server =
haskellPackagesNew.callPackage ./nix/futhark-server.nix { };
futhark-manifest =
haskellPackagesNew.callPackage ./nix/futhark-manifest.nix { };
zlib =
haskellPackagesNew.callPackage ./nix/zlib.nix {zlib=pkgs.zlib;};
futhark =
# callCabal2Nix does not do a great job at determining
# which files must be included as source, which causes
# trouble if you have lots of other large files lying
# around (say, data files for testing). As a workaround
# we explicitly tell it which files are needed. This must
# be _manually_ kept in sync with whatever the cabal file requires.
let sources = ["futhark.cabal"
"Setup.hs"
"LICENSE"
"^src.*"
"^rts.*"
"^docs.*"
"^prelude.*"
"^assets.*"
"^unittests.*"
];
cleanSource = src: pkgs.lib.sourceByRegex src sources;
in
pkgs.haskell.lib.overrideCabal
(pkgs.haskell.lib.addBuildTools
(haskellPackagesOld.callCabal2nix "futhark" (cleanSource ./.) { })
[ pkgs.python39Packages.sphinx ])
( _drv: {
isLibrary = false;
isExecutable = true;
enableSharedExecutables = false;
enableSharedLibraries = false;
enableLibraryProfiling = false;
configureFlags = [
"--ghc-option=-Werror"
"--ghc-option=-optl=-static"
"--ghc-option=-split-sections"
"--extra-lib-dirs=${pkgs.ncurses.override { enableStatic = true; }}/lib"
"--extra-lib-dirs=${pkgs.glibc.static}/lib"
"--extra-lib-dirs=${pkgs.gmp6.override { withStatic = true; }}/lib"
"--extra-lib-dirs=${pkgs.zlib.static}/lib"
"--extra-lib-dirs=${pkgs.libffi.overrideAttrs (old: { dontDisableStatic = true; })}/lib"
];
preBuild = ''
if [ "${commit}" ]; then echo "${commit}" > commit-id; fi
'';
postBuild = (_drv.postBuild or "") + ''
make -C docs man
'';
postInstall = (_drv.postInstall or "") + ''
mkdir -p $out/share/man/man1
cp docs/_build/man/*.1 $out/share/man/man1/
mkdir -p $out/share/futhark/
cp LICENSE $out/share/futhark/
'';
}
);
};
};
};
};
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs { inherit config; };
futhark = pkgs.haskellPackages.futhark;
in pkgs.stdenv.mkDerivation rec {
name = "futhark-" + suffix;
version = futhark.version;
src = tools/release;
buildInputs = [ futhark ];
buildPhase = ''
cp -r skeleton futhark-${suffix}
cp -r ${futhark}/bin futhark-${suffix}/bin
mkdir -p futhark-${suffix}/share
cp -r ${futhark}/share/man futhark-${suffix}/share/
chmod +w -R futhark-${suffix}
cp ${futhark}/share/futhark/LICENSE futhark-${suffix}/
[ "${commit}" ] && echo "${commit}" > futhark-${suffix}/commit-id
tar -Jcf futhark-${suffix}.tar.xz futhark-${suffix}
'';
installPhase = ''
mkdir -p $out
cp futhark-${suffix}.tar.xz $out/futhark-${suffix}.tar.xz
'';
}