-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
177 lines (158 loc) · 4.34 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
{
inputs = {
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
...
}: let
version =
if (self ? shortRev)
then self.shortRev
else "dev";
ndeps = pkgs:
with pkgs;
[
pkg-config
]
++ lib.optionals stdenv.isLinux [
swiftPackages.swiftNoSwiftDriver
swiftPackages.swiftpm
];
bdeps = pkgs:
with pkgs;
[
# SwiftExif
libexif
libiptcdata
# swift-vips deps
cfitsio
expat.dev
fftw.dev
fribidi
glib.dev
lcms2.dev
libdatrie.dev
libgsf.dev
libimagequant
librsvg.dev
libthai
libwebp
matio
openexr.dev
openjpeg.dev
orc.dev
pango.dev
pcre2.dev
vips.dev
# Added 2024-02-07
libarchive.dev
cgif
libspng.dev
xorg.libXdmcp.dev
libhwy
# Added 2024-06-04
openssl.dev
# If the compilation of swift-vips is failing with something like:
# fatal error: 'glib.h' file not found
# look for a warning before the error like:
# warning: couldn't find pc file for spng
# and find that library in Nix and add it to the buildDeps.
]
++ lib.optionals stdenv.isLinux [
swiftPackages.stdenv
swiftPackages.XCTest
swiftPackages.Foundation
swiftPackages.Dispatch
swift-corelibs-libdispatch
glibc.dev
# swift-vips linux deps
libselinux.dev
libsepol.dev
pcre.dev
util-linux.dev
];
in
{
overlay = _: prev: let
pkgs = nixpkgs.legacyPackages.${prev.system};
in {
munin = let
generated = pkgs.swiftpm2nix.helpers ./nix;
src = builtins.filterSource (path: _:
!(builtins.elem (baseNameOf path) [
"flake.nix"
"flake.lock"
".git"
".build"
".direnv"
]))
./.;
in
pkgs.swift.stdenv.mkDerivation {
pname = "munin";
inherit version;
inherit src;
LD_LIBRARY_PATH =
if pkgs.stdenv.isLinux
then "${pkgs.swiftPackages.Dispatch}/lib"
else null;
strictDeps = true;
# Including SwiftPM as a nativeBuildInput provides a buildPhase for you.
# This by default performs a release build using SwiftPM, essentially:
# swift build -c release
nativeBuildInputs = ndeps pkgs;
buildInputs = bdeps pkgs;
# The helper provides a configure snippet that will prepare all dependencies
# in the correct place, where SwiftPM expects them.
configurePhase = generated.configure;
# swiftpmFlags = ["--target x86_64-pc-linux-gnu"];
installPhase = ''
# This is a special function that invokes swiftpm to find the location
# of the binaries it produced.
binPath="$(swiftpmBinPath)"
# Now perform any installation steps.
mkdir -p $out/bin
cp $binPath/munin $out/bin/
'';
};
};
}
// flake-utils.lib.eachDefaultSystem
(system: let
pkgs = import nixpkgs {
overlays = [self.overlay];
inherit system;
};
in {
# `nix develop`
devShell = pkgs.mkShell.override {inherit (pkgs.swift) stdenv;} {
LD_LIBRARY_PATH =
if pkgs.stdenv.isLinux
then "${pkgs.swiftPackages.Dispatch}/lib"
else null;
nativeBuildInputs = ndeps pkgs;
buildInputs =
(bdeps pkgs)
++ [
pkgs.swift-format
pkgs.sourcekit-lsp
pkgs.swiftpm2nix
# pkgs.swiftPackages.xcbuild
];
};
apps = {
inherit (pkgs) munin;
};
defaultApp = pkgs.munin;
overlays.default = self.overlay;
# `nix build`
packages = with pkgs; {
inherit munin;
};
defaultPackage = pkgs.munin;
});
}