Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
213 lines (172 loc) · 8.37 KB
/
Copy pathflake.nix
File metadata and controls
213 lines (172 loc) · 8.37 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
{
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.haskellNix.url = "github:input-output-hk/haskell.nix/1dde0b46d3daa5bf0ff3ea6332d579a1943b4a0c";
inputs.gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
inputs.nixpkgs.url = "github:NixOS/nixpkgs/7993f34ee47e28a3d607a525aadc6c94b73be728";
inputs.linux-dynamic-bundler.url = "github:codedownio/linux-dynamic-bundler";
outputs = { self, flake-utils, gitignore, haskellNix, nixpkgs, linux-dynamic-bundler }:
flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"] (system:
let
compiler-nix-name = "ghc9124";
overlays = [
haskellNix.overlay
# Set enableNativeBignum flag on compiler
(import ./nix/overlays/native-bignum.nix { inherit compiler-nix-name; })
# Configure hixProject
(import ./nix/overlays/hix-project.nix { inherit compiler-nix-name gitignore system; })
];
pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };
flake = (pkgs.hixProject compiler-nix-name).flake {};
flakeStatic = (pkgs.pkgsCross.musl64.hixProject compiler-nix-name).flake {};
flakeDarwin = (pkgs.pkgsCross.aarch64-darwin.hixProject compiler-nix-name).flake {};
flakeAarch64Linux = (pkgs.pkgsCross.aarch64-multiplatform.hixProject compiler-nix-name).flake {};
flakeStaticAarch64Linux = (pkgs.pkgsCross.aarch64-multiplatform-musl.hixProject compiler-nix-name).flake {};
aarch64LinuxExe = flakeAarch64Linux.packages."cpp-notebook-language-server:exe:cpp-notebook-language-server";
packageForGitHub = packageForGitHub' system;
packageForGitHub' = systemToUse: cnls: pkgs.runCommand "cpp-notebook-language-server-${cnls.version}-${systemToUse}" {} ''
name="cpp-notebook-language-server-${cnls.version}-${systemToUse}"
mkdir -p to_zip
cp -r ${cnls}/* to_zip
mkdir -p $out
tar -czvf $out/$name.tar.gz -C to_zip .
'';
# Build our minimal parser (unwrapped)
cling-parser-unwrapped = pkgs.clangStdenv.mkDerivation {
pname = "minimal-cling-parser";
version = "0.1.0";
src = ./cling-parser;
nativeBuildInputs = [ pkgs.cmake ];
buildInputs = with pkgs; [
cling.unwrapped
llvmPackages_18.llvm
];
cmakeBuildType = "Release";
meta = with pkgs.lib; {
description = "Minimal C++ parser using Cling interpreter";
license = licenses.bsd3;
platforms = platforms.unix;
mainProgram = "cling-parser";
};
};
# Wrapped version with proper cling flags
cling-parser = cling-parser-unwrapped.overrideAttrs (oldAttrs: {
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.makeWrapper ];
# cling-parser needs a collection of flags to start up properly, so wrap it by default.
# We'll provide the unwrapped version as a passthru
flags = pkgs.cling.flags ++ [
"-resource-dir"
"${pkgs.cling.unwrapped}"
"-L"
"${pkgs.cling.unwrapped}/lib"
"-l"
"${pkgs.cling.unwrapped}/lib/cling.so"
];
fixupPhase = ''
runHook preFixup
wrapProgram $out/bin/cling-parser \
--argv0 $out/bin/.cling-parser-wrapped \
--add-flags "$flags"
runHook postFixup
'';
passthru = (oldAttrs.passthru or { }) // {
unwrapped = cling-parser-unwrapped;
};
});
mkWrapped = cnls: pkgs.runCommand "cpp-notebook-language-server-${cnls.version}-wrapped" {
nativeBuildInputs = [ pkgs.makeWrapper ];
} ''
mkdir -p $out/bin
makeWrapper ${cnls}/bin/cpp-notebook-language-server $out/bin/cpp-notebook-language-server \
--prefix PATH : ${cling-parser}/bin
'';
testExe = flake.packages."cpp-notebook-language-server:test:cpp-notebook-language-server-test";
devShellInputs = with pkgs; [
stack
haskell.compiler.ghc9124
pcre
zlib
cling-parser
];
in
{
devShells = {
default = pkgs.mkShell {
NIX_PATH = "nixpkgs=${pkgs.path}";
buildInputs = devShellInputs;
};
};
packages = (rec {
inherit (pkgs) cabal2nix stack;
default = static;
inherit cling-parser;
dynamicWrapped = mkWrapped dynamic;
staticWrapped = mkWrapped static;
tests = pkgs.runCommand "cpp-notebook-language-server-tests" {
nativeBuildInputs = [pkgs.makeWrapper];
} ''
mkdir -p $out/bin
makeWrapper ${testExe}/bin/cpp-notebook-language-server-test $out/bin/cpp-notebook-language-server-test \
--prefix PATH : ${cling-parser}/bin
'';
static = flakeStatic.packages."cpp-notebook-language-server:exe:cpp-notebook-language-server";
dynamic = flake.packages."cpp-notebook-language-server:exe:cpp-notebook-language-server";
darwin = flakeDarwin.packages."cpp-notebook-language-server:exe:cpp-notebook-language-server";
aarch64Linux = let
executable = aarch64LinuxExe;
in linux-dynamic-bundler.lib.bundle {
inherit pkgs;
binaryDrv = executable;
binaryName = "cpp-notebook-language-server";
};
staticAarch64Linux = flakeStaticAarch64Linux.packages."cpp-notebook-language-server:exe:cpp-notebook-language-server";
grandCombinedGithubArtifacts = pkgs.symlinkJoin {
name = "cpp-notebook-language-server-grand-combined-artifacts";
paths = [
(packageForGitHub' "x86_64-linux" self.packages.x86_64-linux.static)
(packageForGitHub' "aarch64-linux" aarch64Linux)
(packageForGitHub' "x86_64-darwin" self.packages.x86_64-darwin.dynamic)
(packageForGitHub' "aarch64-darwin" self.packages.aarch64-darwin.dynamic)
];
};
# Print a trivial PATH that we can use to run kernel and LSP tests, to ensure
# they aren't depending on anything on the test machine's PATH.
print-basic-path = pkgs.writeShellScriptBin "basic-path.sh" ''
echo ${pkgs.lib.makeBinPath (with pkgs; [coreutils bash])}
'';
# No GMP (we test the dynamic builds to make sure GMP doesn't end up in the static builds)
verify-no-gmp = pkgs.writeShellScriptBin "verify-no-gmp.sh" ''
echo "Checking for libgmp in ${dynamic}/bin/cpp-notebook-language-server"
(echo "$(ldd ${dynamic}/bin/cpp-notebook-language-server)" | grep libgmp) && exit 1
exit 0
'';
gcroots = let
# Our own components rebuild on any source change, so only the deps are worth rooting.
inputsOf = d: pkgs.lib.filter (p: !(pkgs.lib.hasInfix "cpp-notebook-language-server" (p.name or "")))
(d.buildInputs ++ d.nativeBuildInputs);
# The cross builds can't be made from darwin, where the native build is what matters.
hostInputs = if pkgs.stdenv.hostPlatform.isDarwin
then inputsOf dynamic
else inputsOf dynamic ++ inputsOf static ++ inputsOf aarch64LinuxExe;
in pkgs.writeText "cpp-notebook-language-server-gc-roots" ''
${pkgs.symlinkJoin {
name = "cpp-notebook-language-server-deps";
paths = pkgs.lib.unique (hostInputs ++ devShellInputs);
}}
'';
nixpkgsPath = pkgs.writeShellScriptBin "nixpkgsPath.sh" "echo -n ${pkgs.path}";
});
inherit flake;
}
);
# nixConfig = {
# # This sets the flake to use the IOG nix cache.
# # Nix should ask for permission before using it,
# # but remove it here if you do not want it to.
# extra-substituters = ["https://cache.iog.io"];
# extra-tcpped-public-keys = ["hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="];
# allow-import-from-derivation = "true";
# };
}