-
Notifications
You must be signed in to change notification settings - Fork 2
/
default.nix
125 lines (111 loc) · 3.73 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
{ sources ? import ./nix/sources.nix
, haskellNix ? import sources.haskellNix { inherit system; }
, pkgs ? import haskellNix.sources.nixpkgs-2311 (haskellNix.nixpkgsArgs // { inherit system; })
, system ? builtins.currentSystem
, nix-filter ? import sources.nix-filter
}:
let
masterPkgs = import sources.nixpkgs { inherit system; };
yq = import ./nix/yq.nix { pkgs = masterPkgs; };
diffYaml = import ./nix/diff-yaml.nix { pkgs = masterPkgs; };
hsPkgs = pkgs.haskell-nix.stackProject {
src = nix-filter {
root = ./.;
name = "compaREST";
include = [
./stack.yaml
./stack.yaml.lock
./compaREST.cabal
];
};
modules = [
{
dontStrip = false;
dontPatchELF = false;
enableDeadCodeElimination = true;
ghcOptions = [
"-O2"
"-fexpose-all-unfoldings"
"-fspecialise-aggressively"
];
packages.pandoc.ghcOptions = [ "-O1" ];
packages.compaREST.src = nix-filter {
root = ./.;
name = "compaREST-src";
include = with nix-filter; [
(./compaREST.cabal)
(inDirectory ./test)
(inDirectory ./src)
(inDirectory ./app)
(inDirectory ./github-action)
./css/awsm.min.css
./LICENSE
];
};
}
];
};
staticify = name: drv: pkgs.runCommand name { } ''
mkdir -p $out/bin
cp ${drv + "/bin"}/* $out/bin
${pkgs.nukeReferences}/bin/nuke-refs $out/bin/*
'';
compaRESTBin = hsPkgs.compaREST.components.exes.compaREST;
compaRESTStaticBin = (staticify "compaREST-static" hsPkgs.projectCross.musl64.hsPkgs.compaREST.components.exes.compaREST);
# doesn't work
armDarwinCompaREST = hsPkgs.projectCross.aarch64-darwin.hsPkgs.compaREST.components.exes.compaREST;
compaRESTImage = pkgs.dockerTools.buildImage {
name = "compaREST";
contents = [ compaRESTStaticBin ];
config = {
Entrypoint = [ "/bin/compaREST" ];
};
};
macOSCompaRESTBundle = pkgs.runCommand "compaREST-macOS-bundled"
{
buildInputs = [ masterPkgs.macdylibbundler ];
} ''
mkdir -p $out/lib
cp ${compaRESTBin}/bin/compaREST $out/compaREST
chmod 755 $out/compaREST
dylibbundler -b \
-x $out/compaREST \
-d $out/lib \
-p '@executable_path/lib'
'';
compaRESTGithubAction =
let
action = staticify "compaREST-GitHub-Action-static" hsPkgs.projectCross.musl64.hsPkgs.compaREST.components.exes.compaREST-GitHub-Action;
wrapped = pkgs.runCommand "wrapped-compaREST-GitHub-Action" { buildInputs = [ pkgs.makeWrapper ]; } ''
makeWrapper ${action}/bin/compaREST-GitHub-Action $out/bin/pre --add-flags "pre"
makeWrapper ${action}/bin/compaREST-GitHub-Action $out/bin/run --add-flags "run"
'';
in
pkgs.dockerTools.buildImage {
name = "typeable/compaREST-GitHub-Action";
tag = "latest";
contents = [ wrapped pkgs.cacert ];
};
WindowsCompaRESTBin = hsPkgs.projectCross.mingwW64.hsPkgs.compaREST.components.exes.compaREST;
# We use the static version so that we don't have to rebuild everything on CI.
# The only binaries build on CI are static.
test = hsPkgs.projectCross.musl64.hsPkgs.compaREST.components.tests.compaREST-tests.overrideAttrs (final: old: {
buildInputs = old.buildInputs ++ [ diffYaml yq ];
nativeBuildInputs = old.nativeBuildInputs ++ (with masterPkgs; [ makeWrapper ]);
postInstall = ''
wrapProgram $out/bin/compaREST-tests \
--prefix PATH : ${masterPkgs.lib.makeBinPath [ diffYaml yq ]}
'';
});
in
{
inherit
compaRESTImage
compaRESTGithubAction
compaRESTStaticBin
compaRESTBin
hsPkgs
macOSCompaRESTBundle
WindowsCompaRESTBin
test;
}