-
-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathflake.nix
205 lines (176 loc) · 6.82 KB
/
flake.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
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
{
description = "lem";
inputs = {
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
# cribbing a lot from https://github.com/dariof4/lem-flake
# and from https://github.com/eriedaberrie/my-nix-packages
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems =
[ "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux" ];
perSystem = { self', pkgs, lib, ... }:
let
lem = pkgs.sbcl.buildASDFSystem rec {
pname = "lem";
version = "unstable";
systems = [ "lem-fake-interface" ];
src = ./.;
nativeBuildInputs = with pkgs; [
autoconf
automake
libffi
libtool
makeBinaryWrapper
pkg-config
];
nativeLibs = with pkgs; [ libffi openssl ];
qlBundleLibs = pkgs.stdenvNoCC.mkDerivation {
pname = "${pname}-qlot-bundle";
inherit src version;
nativeBuildInputs = with pkgs; [
sbcl.pkgs.qlot-cli
which
git
cacert
];
installPhase = ''
runHook preInstall
export HOME=$(mktemp -d)
qlot install --jobs $NIX_BUILD_CORES --no-deps --no-color
qlot bundle --no-color
# Unnecessary and also platform-dependent file
rm .bundle-libs/bundle-info.sexp
# Remove vendored .so files
find .bundle-libs \
-type f '(' -name '*.so' -o -name '*.dll' ')' -exec rm '{}' ';'
cp -r .bundle-libs $out
runHook postInstall
'';
dontBuild = true;
dontFixup = true;
outputHashMode = "recursive";
outputHash =
"sha256-NtCSBxEo/4uuhlLc9Xqlq+PM1fAbDfRBH64imMLvKYE=";
};
configurePhase = ''
runHook preConfigure
mkdir -p $out/share/lem
pushd $out/share/lem
cp -r $qlBundleLibs .bundle-libs
chmod -R +w .bundle-libs
# build async-process native part
pushd .bundle-libs/software/async-process-*
chmod +x bootstrap
./bootstrap
popd
# nixpkgs patch to fix cffi build on darwin
pushd .bundle-libs/software/cffi-*
patch -p1 <${inputs.nixpkgs}/pkgs/development/lisp-modules/patches/cffi-libffi-darwin-ffi-h.patch
popd
popd
source ${inputs.nixpkgs}/pkgs/development/lisp-modules/setup-hook.sh
buildAsdfPath
runHook postConfigure
'';
buildScript = pkgs.writeText "build-lem.lisp" ''
(defpackage :nix-cl-user
(:use :cl))
(in-package :nix-cl-user)
(load "${lem.asdfFasl}/asdf.${lem.faslExt}")
;; Avoid writing to the global fasl cache
(asdf:initialize-output-translations
'(:output-translations :disable-cache
:inherit-configuration))
(defvar *systems* (uiop:split-string (uiop:getenv "systems")))
(defvar *out-path* (uiop:getenv "out"))
(defvar *share-path* (concatenate 'string
*out-path*
"/share/lem"))
(defvar *bundle-path* (concatenate 'string
*share-path*
"/.bundle-libs/bundle.lisp"))
;; Initial load
(let ((asdf:*system-definition-search-functions*
(copy-list asdf:*system-definition-search-functions*)))
(load *bundle-path*)
(loop :for system :in *systems*
:do (asdf:load-system system)))
;; Load the bundle on every startup
(uiop:register-image-restore-hook
(lambda ()
(load *bundle-path*))
nil)
(setf uiop:*image-entry-point* #'lem:main)
(uiop:dump-image
"lem"
:executable t
:compression t)
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/share/lem
mv lem $out/bin
wrapProgram $out/bin/lem \
--prefix LD_LIBRARY_PATH : "$LD_LIBRARY_PATH" \
--prefix DYLD_LIBRARY_PATH : "$DYLD_LIBRARY_PATH"
cp -r . $out/share/lem
runHook postInstall
'';
};
lem-sdl2-shell = pkgs.mkShell {
packages = with pkgs; [
sbcl
sbcl.pkgs.qlot-cli
];
# Normally we would include pkg-config and list these dependencies
# in packages, but it does not appear that pkg-config is being used
# when available.
shellHook = with pkgs; ''
export LD_LIBRARY_PATH="''${LD_LIBRARY_PATH}:${SDL2}/lib:${SDL2_ttf}/lib:${SDL2_image}/lib:${libffi}/lib:${openssl.out}/lib"
'';
};
lem-ncurses-shell = pkgs.mkShell {
packages = with pkgs; [
sbcl
sbcl.pkgs.qlot-cli
pkg-config
ncurses.dev
];
# Normally we would include pkg-config and list these dependencies
# in packages, but it does not appear that pkg-config is being used
# when available.
shellHook = with pkgs; ''
export LD_LIBRARY_PATH="''${LD_LIBRARY_PATH}:${ncurses.out}/lib:${libffi}/lib:${openssl.out}/lib"
'';
};
in
{
devShells =
{
lem-ncurses = lem-ncurses-shell;
lem-sdl2 = lem-sdl2-shell;
default = lem-ncurses-shell;
};
packages.lem-ncurses = lem.overrideLispAttrs (o: {
pname = "lem-ncurses";
meta.mainProgram = "lem";
systems = [ "lem-ncurses" ];
nativeLibs = with pkgs; o.nativeLibs ++ [ ncurses ];
});
packages.lem-sdl2 = lem.overrideLispAttrs (o: {
pname = "lem-sdl2";
meta.mainProgram = "lem";
systems = [ "lem-sdl2" ];
nativeLibs = with pkgs;
o.nativeLibs ++ [ SDL2 SDL2_ttf SDL2_image ];
});
packages.default = self'.packages.lem-ncurses;
};
};
}