ieda: init at 0-unstable-2024-10-11 (#338769)
[NixPkgs.git] / pkgs / by-name / es / espanso / package.nix
blob636bec07ee1ec6b96f3b9cd4f4b973f97950758e
2   lib,
3   coreutils,
4   fetchFromGitHub,
5   rustPlatform,
6   pkg-config,
7   extra-cmake-modules,
8   dbus,
9   libX11,
10   libXi,
11   libXtst,
12   libnotify,
13   libxkbcommon,
14   openssl,
15   xclip,
16   xdotool,
17   setxkbmap,
18   wl-clipboard,
19   wxGTK32,
20   makeWrapper,
21   stdenv,
22   apple-sdk_11,
23   darwinMinVersionHook,
24   waylandSupport ? false,
25   x11Support ? stdenv.hostPlatform.isLinux,
26   testers,
27   espanso,
29 # espanso does not support building with both X11 and Wayland support at the same time
30 assert stdenv.hostPlatform.isLinux -> x11Support != waylandSupport;
31 assert stdenv.hostPlatform.isDarwin -> !x11Support;
32 assert stdenv.hostPlatform.isDarwin -> !waylandSupport;
33 rustPlatform.buildRustPackage rec {
34   pname = "espanso";
35   version = "2.2-unstable-2024-05-14";
37   src = fetchFromGitHub {
38     owner = "espanso";
39     repo = "espanso";
40     rev = "8daadcc949c35a7b7aa20b7f544fdcff83e2c5f7";
41     hash = "sha256-4MArENBmX6tDVLZE1O8cuJe7A0R+sLZoxBkDvIwIVZ4=";
42   };
44   cargoLock = {
45     lockFile = ./Cargo.lock;
46     outputHashes = {
47       "yaml-rust-0.4.6" = "sha256-wXFy0/s4y6wB3UO19jsLwBdzMy7CGX4JoUt5V6cU7LU=";
48     };
49   };
51   nativeBuildInputs = [
52     extra-cmake-modules
53     pkg-config
54     makeWrapper
55     wxGTK32
56   ];
58   # Ref: https://github.com/espanso/espanso/blob/78df1b704fe2cc5ea26f88fdc443b6ae1df8a989/scripts/build_binary.rs#LL49C3-L62C4
59   buildNoDefaultFeatures = true;
60   buildFeatures =
61     [
62       "modulo"
63     ]
64     ++ lib.optionals waylandSupport [
65       "wayland"
66     ]
67     ++ lib.optionals stdenv.hostPlatform.isLinux [
68       "vendored-tls"
69     ]
70     ++ lib.optionals stdenv.hostPlatform.isDarwin [
71       "native-tls"
72     ];
74   buildInputs =
75     [
76       wxGTK32
77     ]
78     ++ lib.optionals stdenv.hostPlatform.isLinux [
79       openssl
80       dbus
81       libnotify
82       libxkbcommon
83     ]
84     ++ lib.optionals stdenv.hostPlatform.isDarwin [
85       apple-sdk_11
86       (darwinMinVersionHook "10.13")
87     ]
88     ++ lib.optionals waylandSupport [
89       wl-clipboard
90     ]
91     ++ lib.optionals x11Support [
92       libXi
93       libXtst
94       libX11
95       xclip
96       xdotool
97     ];
99   postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
100     substituteInPlace scripts/create_bundle.sh \
101       --replace-fail target/mac/ $out/Applications/ \
102       --replace-fail /bin/echo ${coreutils}/bin/echo
103     patchShebangs scripts/create_bundle.sh
104     substituteInPlace espanso/src/res/macos/Info.plist \
105       --replace-fail "<string>espanso</string>" "<string>${placeholder "out"}/Applications/Espanso.app/Contents/MacOS/espanso</string>"
106     substituteInPlace espanso/src/path/macos.rs  espanso/src/path/linux.rs \
107       --replace-fail '"/usr/local/bin/espanso"' '"${placeholder "out"}/bin/espanso"'
108   '';
110   # Some tests require networking
111   doCheck = false;
113   postInstall =
114     if stdenv.hostPlatform.isDarwin then
115       ''
116         EXEC_PATH=$out/bin/espanso BUILD_ARCH=current ${stdenv.shell} ./scripts/create_bundle.sh
117       ''
118     else
119       ''
120         wrapProgram $out/bin/espanso \
121           --prefix PATH : ${
122             lib.makeBinPath (
123               lib.optionals stdenv.hostPlatform.isLinux [
124                 libnotify
125                 setxkbmap
126               ]
127               ++ lib.optionals waylandSupport [
128                 wl-clipboard
129               ]
130               ++ lib.optionals x11Support [
131                 xclip
132               ]
133             )
134           }
135       '';
137   passthru.tests.version = testers.testVersion {
138     package = espanso;
139     # remove when updating to a release version
140     version = "2.2.1";
141   };
143   meta = with lib; {
144     description = "Cross-platform Text Expander written in Rust";
145     mainProgram = "espanso";
146     homepage = "https://espanso.org";
147     license = licenses.gpl3Plus;
148     maintainers = with maintainers; [
149       kimat
150       pyrox0
151       n8henrie
152     ];
153     platforms = platforms.unix;
155     longDescription = ''
156       Espanso detects when you type a keyword and replaces it while you're typing.
157     '';
158   };