1{
2 lib,
3 stdenv,
4 buildGoModule,
5 rustPlatform,
6 fetchFromGitHub,
7 fetchYarnDeps,
8
9 cargo-tauri,
10 desktop-file-utils,
11 installShellFiles,
12 jq,
13 makeBinaryWrapper,
14 moreutils,
15 nodejs,
16 pkg-config,
17 yarnConfigHook,
18 wrapGAppsHook3,
19
20 glib-networking,
21 libayatana-appindicator,
22 openssl,
23 webkitgtk_4_1,
24
25 testers,
26}:
27
28let
29 version = "0.6.15";
30
31 src = fetchFromGitHub {
32 owner = "loft-sh";
33 repo = "devpod";
34 tag = "v${version}";
35 hash = "sha256-fLUJeEwNDyzMYUEYVQL9XGQv/VAxjH4IZ1SJa6jx4Mw=";
36 };
37
38 meta = {
39 description = "Codespaces but open-source, client-only and unopinionated: Works with any IDE and lets you use any cloud, kubernetes or just localhost docker";
40 mainProgram = "devpod";
41 homepage = "https://devpod.sh";
42 license = lib.licenses.mpl20;
43 maintainers = with lib.maintainers; [
44 maxbrunet
45 tomasajt
46 ];
47 };
48
49 devpod = buildGoModule (finalAttrs: {
50 pname = "devpod";
51 inherit version src meta;
52
53 vendorHash = null;
54
55 env.CGO_ENABLED = 0;
56
57 ldflags = [
58 "-X github.com/loft-sh/devpod/pkg/version.version=v${version}"
59 ];
60
61 excludedPackages = [ "./e2e" ];
62
63 nativeBuildInputs = [ installShellFiles ];
64
65 postInstall = ''
66 $out/bin/devpod completion bash >devpod.bash
67 $out/bin/devpod completion fish >devpod.fish
68 $out/bin/devpod completion zsh >devpod.zsh
69 installShellCompletion devpod.{bash,fish,zsh}
70 '';
71
72 passthru.tests.version = testers.testVersion {
73 package = finalAttrs.finalPackage;
74 command = "devpod version";
75 version = "v${version}";
76 };
77 });
78
79 devpod-desktop = rustPlatform.buildRustPackage {
80 pname = "devpod-desktop";
81 inherit version src;
82
83 sourceRoot = "${src.name}/desktop";
84
85 offlineCache = fetchYarnDeps {
86 yarnLock = "${src}/desktop/yarn.lock";
87 hash = "sha256-0Ov+Ik+th2IiuuqJyiO9t8vTyMqxDa9juEwbwHFaoi4=";
88 };
89
90 cargoRoot = "src-tauri";
91 buildAndTestSubdir = "src-tauri";
92
93 cargoHash = "sha256-BwuV5nAQcTAtdfK4+NKEt8Cj7gqnatRwHh/BYJJrIPo=";
94
95 patches = [
96 # don't create a .desktop file automatically registered to open the devpod:// URI scheme
97 # we edit the in-store .desktop file in postInstall to support opening the scheme,
98 # but users will have to configure the default handler manually
99 ./dont-auto-register-scheme.patch
100
101 # disable the button that symlinks the `devpod-cli` binary to ~/.local/bin/devpod
102 # and don't show popup where it prompts you to press the above mentioned button
103 # we'll symlink it manually to $out/bin/devpod in postInstall
104 ./dont-copy-sidecar-out-of-store.patch
105
106 # otherwise it's going to get stuck in an endless error cycle, quickly increasing the log file size
107 ./exit-update-checker-loop.patch
108 ];
109
110 postPatch = ''
111 ln -s ${lib.getExe devpod} src-tauri/bin/devpod-cli-${stdenv.hostPlatform.rust.rustcTarget}
112
113 # disable upstream updater
114 jq '.plugins.updater.endpoints = [ ] | .bundle.createUpdaterArtifacts = false' src-tauri/tauri.conf.json \
115 | sponge src-tauri/tauri.conf.json
116 ''
117 + lib.optionalString stdenv.hostPlatform.isLinux ''
118 substituteInPlace $cargoDepsCopy/libappindicator-sys-*/src/lib.rs \
119 --replace-fail "libayatana-appindicator3.so.1" "${libayatana-appindicator}/lib/libayatana-appindicator3.so.1"
120 '';
121
122 nativeBuildInputs = [
123 cargo-tauri.hook
124 jq
125 moreutils
126 nodejs
127 yarnConfigHook
128 ]
129 ++ lib.optionals stdenv.hostPlatform.isLinux [
130 desktop-file-utils
131 pkg-config
132 wrapGAppsHook3
133 ]
134 ++ lib.optionals stdenv.hostPlatform.isDarwin [
135 makeBinaryWrapper
136 ];
137
138 buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
139 glib-networking
140 libayatana-appindicator
141 openssl
142 webkitgtk_4_1
143 ];
144
145 postInstall =
146 lib.optionalString stdenv.hostPlatform.isDarwin ''
147 # replace sidecar binary with symlink
148 ln -sf ${lib.getExe devpod} "$out/Applications/DevPod.app/Contents/MacOS/devpod-cli"
149
150 makeWrapper "$out/Applications/DevPod.app/Contents/MacOS/DevPod Desktop" "$out/bin/DevPod Desktop"
151 ''
152 + lib.optionalString stdenv.hostPlatform.isLinux ''
153 # replace sidecar binary with symlink
154 ln -sf ${lib.getExe devpod} "$out/bin/devpod-cli"
155
156 # set up scheme handling
157 desktop-file-edit "$out/share/applications/DevPod.desktop" \
158 --set-key="Exec" --set-value="\"DevPod Desktop\" %u" \
159 --set-key="MimeType" --set-value="x-scheme-handler/devpod"
160
161 # whitespace in the icon name causes gtk-update-icon-cache to fail
162 desktop-file-edit "$out/share/applications/DevPod.desktop" \
163 --set-key="Icon" --set-value="DevPod-Desktop"
164
165 for dir in "$out"/share/icons/hicolor/*/apps; do
166 mv "$dir/DevPod Desktop.png" "$dir/DevPod-Desktop.png"
167 done
168 ''
169 + ''
170 # propagate the `devpod` command
171 ln -s ${lib.getExe devpod} "$out/bin/devpod"
172 '';
173
174 # we only want to wrap the main binary
175 dontWrapGApps = true;
176
177 postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
178 wrapGApp "$out/bin/DevPod Desktop"
179 '';
180
181 meta = meta // {
182 mainProgram = "DevPod Desktop";
183 platforms = lib.platforms.linux ++ lib.platforms.darwin;
184 };
185 };
186in
187{
188 inherit devpod devpod-desktop;
189}