nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 coreutils,
4 fetchFromGitHub,
5 rustPlatform,
6 pkg-config,
7 extra-cmake-modules,
8 dbus,
9 libX11,
10 libxcb,
11 libXi,
12 libXtst,
13 libnotify,
14 libxkbcommon,
15 libpng,
16 openssl,
17 xclip,
18 xdotool,
19 setxkbmap,
20 wl-clipboard,
21 wxGTK32,
22 makeWrapper,
23 securityWrapperPath ? null,
24 nix-update-script,
25 stdenv,
26 waylandSupport ? false,
27 x11Support ? stdenv.hostPlatform.isLinux,
28 testers,
29 nixosTests,
30 fetchpatch,
31}:
32# espanso does not support building with both X11 and Wayland support at the same time
33assert stdenv.hostPlatform.isLinux -> x11Support != waylandSupport;
34assert stdenv.hostPlatform.isDarwin -> !x11Support;
35assert stdenv.hostPlatform.isDarwin -> !waylandSupport;
36rustPlatform.buildRustPackage (finalAttrs: {
37 pname = "espanso";
38 version = "2.3.0";
39
40 src = fetchFromGitHub {
41 owner = "espanso";
42 repo = "espanso";
43 tag = "v${finalAttrs.version}";
44 hash = "sha256-WvFV+WZxwaGCfMVEbfHrQZS0LtgJElmOtSXK9jEeaDk=";
45 };
46
47 cargoHash = "sha256-E3z8NfKZiQsaYqDKXSIltETa4cSL0ShHnUMymjH5pas=";
48
49 nativeBuildInputs = [
50 extra-cmake-modules
51 pkg-config
52 makeWrapper
53 wxGTK32
54 ];
55
56 # Ref: https://github.com/espanso/espanso/blob/78df1b704fe2cc5ea26f88fdc443b6ae1df8a989/scripts/build_binary.rs#LL49C3-L62C4
57 buildNoDefaultFeatures = true;
58 buildFeatures = [
59 "modulo"
60 ]
61 ++ lib.optionals waylandSupport [
62 "wayland"
63 ]
64 ++ lib.optionals stdenv.hostPlatform.isLinux [
65 "vendored-tls"
66 ]
67 ++ lib.optionals stdenv.hostPlatform.isDarwin [
68 "native-tls"
69 ];
70
71 buildInputs = [
72 libpng
73 wxGTK32
74 ]
75 ++ lib.optionals stdenv.hostPlatform.isLinux [
76 openssl
77 dbus
78 libnotify
79 libxkbcommon
80 ]
81 ++ lib.optionals waylandSupport [
82 wl-clipboard
83 ]
84 ++ lib.optionals x11Support [
85 libXi
86 libXtst
87 libX11
88 libxcb
89 xclip
90 xdotool
91 ];
92
93 patches = [
94 # remove when version > 2.3.0
95 (fetchpatch {
96 name = "fix-welcome-screen-expansion.patch";
97 url = "https://github.com/espanso/espanso/commit/5d5fc84df695d628d1d9c3e7e3854c2991a64d64.patch";
98 hash = "sha256-dhoqq0V8b8mGvZvPInHiHKGmGDDFO/SH5HqMY7EA134=";
99 })
100 ];
101
102 postPatch =
103 lib.optionalString stdenv.hostPlatform.isDarwin ''
104 substituteInPlace scripts/create_bundle.sh \
105 --replace-fail target/mac/ $out/Applications/ \
106 --replace-fail /bin/echo ${coreutils}/bin/echo
107 substituteInPlace espanso/src/path/macos.rs espanso/src/path/linux.rs \
108 --replace-fail '"/usr/local/bin/espanso"' '"${placeholder "out"}/bin/espanso"'
109 ''
110 + lib.optionalString (securityWrapperPath != null) ''
111 substituteInPlace espanso/src/cli/daemon/mod.rs \
112 --replace-fail \
113 'std::env::current_exe().expect("unable to obtain espanso executable location");' \
114 'std::ffi::OsString::from("${securityWrapperPath}/espanso");'
115 '';
116
117 # Some tests require networking
118 doCheck = false;
119
120 postInstall =
121 if stdenv.hostPlatform.isDarwin then
122 ''
123 ${stdenv.shell} ./scripts/create_bundle.sh $out/bin/espanso
124 ''
125 else
126 ''
127 wrapProgram $out/bin/espanso \
128 --prefix PATH : ${
129 lib.makeBinPath (
130 lib.optionals stdenv.hostPlatform.isLinux [
131 libnotify
132 setxkbmap
133 ]
134 ++ lib.optionals waylandSupport [
135 wl-clipboard
136 ]
137 ++ lib.optionals x11Support [
138 xclip
139 ]
140 )
141 }
142 '';
143
144 passthru = {
145 inherit waylandSupport;
146 tests = nixosTests.espanso // {
147 version = testers.testVersion {
148 package = finalAttrs.finalPackage;
149 inherit (finalAttrs) version;
150 };
151 };
152 updateScript = nix-update-script { };
153 };
154
155 meta = {
156 description = "Cross-platform Text Expander written in Rust";
157 mainProgram = "espanso";
158 homepage = "https://espanso.org";
159 license = lib.licenses.gpl3Plus;
160 maintainers = with lib.maintainers; [
161 kimat
162 n8henrie
163 ];
164 platforms = lib.platforms.unix;
165 longDescription = ''
166 Espanso detects when you type a keyword and replaces it while you're typing.
167 '';
168 };
169})