-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpkg-fun.nix
94 lines (91 loc) · 3.48 KB
/
pkg-fun.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
# ============================================================================ #
#
# Produces a Nix Plugin with some `floco' extensions.
#
# Example plugin invocation ( for a trivial hello world plugin )
# NOTE: use `libhello.dylib' on Darwin.
# $ nix --option plugin-files './result/libexec/libhello.so' eval \
# --expr 'builtins.hello'
# "Hello, World!"
#
#
# ---------------------------------------------------------------------------- #
{ stdenv
, boost
, nlohmann_json
, treeFor
, semver
, nodejs
, npm
, bash
, nix
, pkg-config
, darwin
}: stdenv.mkDerivation {
inherit bash nix;
pname = "floco-nix";
version = "0.1.0";
src = builtins.path {
name = "source";
path = ./.;
filter = name: type:
( type == "regular" ) && ( ( builtins.match ".*\\.nix" name ) == null );
};
libExt = stdenv.hostPlatform.extensions.sharedLibrary;
nativeBuildInputs = [pkg-config];
buildInputs = [nix.dev boost.dev] ++ (
if stdenv.isDarwin then [darwin.apple_sdk.frameworks.Security] else []
);
propagatedBuildInputs = [nix nodejs npm treeFor semver];
# NOTE: Nix 2.12.x requires `-lnixfetchers' to be linked explicitly.
# npm 9.3.1
buildPhase = ''
runHook preBuild;
$CXX \
-o "libfloco$libExt" \
-fPIC \
-shared \
-I${nix.dev}/include \
-I${nix.dev}/include/nix \
-I${boost.dev}/include \
-I${nlohmann_json}/include \
-include ${nix.dev}/include/nix/config.h \
$( pkg-config --cflags nix-main nix-store nix-expr; ) \
${if stdenv.isDarwin then "-undefined suppress -flat_namespace" else ""} \
./npm-wrap.cc ./npm-fetcher.cc ./progs.cc \
-Wl,--as-needed \
$( pkg-config --libs nix-store nix-expr nix-cmd; ) \
-lnixfetchers \
-Wl,--no-as-needed \
;
runHook postBuild;
'';
installPhase = ''
runHook preInstall;
mkdir -p "$out/libexec" "$out/bin";
mv -- "./libfloco$libExt" "$out/libexec/libfloco$libExt";
cat <<EOF >"$out/bin/floco-nix"
#! $bash/bin/bash
# A wrapper around Nix that includes the \`libfloco' plugin.
# First we add runtime executables to \`PATH', then pass off to Nix.
for p in \$( <"$out/nix-support/propagated-build-inputs"; ); do
if [[ -d "\$p/bin" ]]; then
PATH="\$PATH:\$p/bin";
fi
if [[ -d "\$p/lib/node_modules" ]]; then
NODE_PATH="\''${NODE_PATH:+$NODE_PATH:}\$p/lib/node_modules";
fi
done
export PATH NODE_PATH;
exec "$nix/bin/nix" --plugin-files "$out/libexec/libfloco$libExt" "\$@";
EOF
chmod +x "$out/bin/floco-nix";
runHook postInstall;
'';
meta.mainProgram = "floco-nix";
}
# ---------------------------------------------------------------------------- #
#
#
#
# ============================================================================ #