-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
158 lines (140 loc) · 4.76 KB
/
Copy pathflake.nix
File metadata and controls
158 lines (140 loc) · 4.76 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
{
description = "whisper - Encrypted DM pipe for Nostr (NIP-17 + NIP-44)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
libnostr-c = {
url = "github:privkeyio/libnostr-c";
flake = false;
};
noscrypt = {
url = "github:privkeyio/noscrypt";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, libnostr-c, noscrypt }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
noscryptLib = pkgs.stdenv.mkDerivation {
pname = "noscrypt";
version = "0.1.0";
src = noscrypt;
nativeBuildInputs = [ pkgs.cmake ];
buildInputs = [ pkgs.openssl pkgs.secp256k1 ];
cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Release"
"-DBUILD_SHARED_LIBS=ON"
];
};
libnostrC = pkgs.stdenv.mkDerivation {
pname = "libnostr-c";
version = "0.1.4";
src = libnostr-c;
nativeBuildInputs = [ pkgs.cmake pkgs.pkg-config ];
buildInputs = [
pkgs.cjson
pkgs.secp256k1
pkgs.libwebsockets
pkgs.openssl
noscryptLib
];
# Patch cmake for Nix build
preConfigure = ''
# Add noscrypt include path (headers are in include/noscrypt/)
sed -i '2i include_directories(${noscryptLib}/include/noscrypt)' CMakeLists.txt
# Skip pkg-config check for noscrypt
sed -i 's/pkg_check_modules(NOSCRYPT noscrypt)/# pkg_check_modules disabled for Nix/' CMakeLists.txt
# Install generated nostr_features.h header
printf '\ninstall(FILES ''${CMAKE_CURRENT_BINARY_DIR}/include/nostr_features.h DESTINATION include)\n' >> CMakeLists.txt
'';
cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Release"
"-DNOSTR_FEATURE_NIP17=ON"
"-DNOSTR_FEATURE_NIP44=ON"
"-DNOSTR_FEATURE_NIP59=ON"
"-DNOSTR_FEATURE_RELAY=ON"
"-DBUILD_EXAMPLES=OFF"
"-DBUILD_TESTS=OFF"
# Manually specify noscrypt since there's no pkg-config file
"-DNOSCRYPT_FOUND=ON"
"-DNOSCRYPT_LIBRARIES=${noscryptLib}/lib/libnoscrypt.so"
];
};
whisper = pkgs.stdenv.mkDerivation {
pname = "whisper";
version = "0.1.0";
src = ./.;
buildInputs = [
libnostrC
noscryptLib
pkgs.cjson
pkgs.secp256k1
pkgs.libwebsockets
pkgs.openssl
pkgs.notcurses
];
buildPhase = ''
$CC -Wall -Wextra -O2 -std=c99 -D_DEFAULT_SOURCE \
-I${libnostrC}/include \
-c -o main.o main.c
$CC -Wall -Wextra -O2 -std=c99 -D_DEFAULT_SOURCE \
-I${libnostrC}/include \
-c -o send.o send.c
$CC -Wall -Wextra -O2 -std=c99 -D_DEFAULT_SOURCE \
-I${libnostrC}/include \
-c -o recv.o recv.c
$CC -Wall -Wextra -O2 -std=c99 -D_DEFAULT_SOURCE \
-I${libnostrC}/include \
-c -o util.o util.c
$CC -Wall -Wextra -O2 -std=c99 -D_DEFAULT_SOURCE \
-I${libnostrC}/include -I${pkgs.notcurses}/include \
-DHAVE_NOTCURSES \
-c -o tui.o tui.c
$CC -o whisper main.o send.o recv.o util.o tui.o \
-L${libnostrC}/lib -lnostr \
-L${noscryptLib}/lib -lnoscrypt \
-L${pkgs.notcurses}/lib -lnotcurses-core \
-lcjson -lsecp256k1 -lwebsockets -lssl -lcrypto -lpthread -lm
'';
installPhase = ''
mkdir -p $out/bin
cp whisper $out/bin/
'';
meta = with pkgs.lib; {
description = "Encrypted DM pipe for Nostr (NIP-17 + NIP-44)";
homepage = "https://github.com/privkeyio/whisper";
license = licenses.mit;
platforms = platforms.unix;
};
};
in {
packages = {
default = whisper;
whisper = whisper;
libnostr-c = libnostrC;
noscrypt = noscryptLib;
};
devShells.default = pkgs.mkShell {
buildInputs = [
libnostrC
noscryptLib
pkgs.cjson
pkgs.secp256k1
pkgs.libwebsockets
pkgs.openssl
pkgs.notcurses
pkgs.pkg-config
];
shellHook = ''
echo "whisper dev shell"
echo "Run: make"
'';
};
apps.default = {
type = "app";
program = "${whisper}/bin/whisper";
};
}
);
}