1{ lib
2, buildGoModule
3, copyDesktopItems
4, darwin
5, desktopToDarwinBundle
6, fetchFromGitHub
7, fetchYarnDeps
8, gtk3
9, installShellFiles
10, jq
11, libayatana-appindicator
12, libsoup_2_4
13, makeDesktopItem
14, mkYarnPackage
15, openssl
16, pkg-config
17, rust
18, rustPlatform
19, stdenv
20, testers
21, webkitgtk_4_0
22}:
23
24let
25 pname = "devpod";
26 version = "0.5.20";
27
28 src = fetchFromGitHub {
29 owner = "loft-sh";
30 repo = pname;
31 rev = "v${version}";
32 sha256 = "sha256-8LbqrOKC1als3Xm6ZuU2AySwT0UWjLN2xh+/CvioYew=";
33 };
34
35 meta = with lib; {
36 description = "Codespaces but open-source, client-only and unopinionated: Works with any IDE and lets you use any cloud, kubernetes or just localhost docker";
37 mainProgram = "devpod";
38 homepage = "https://devpod.sh";
39 license = licenses.mpl20;
40 maintainers = with maintainers; [ maxbrunet ];
41 };
42in
43rec {
44 devpod = buildGoModule {
45 inherit version src pname meta;
46
47 vendorHash = null;
48
49 env.CGO_ENABLED = 0;
50
51 ldflags = [
52 "-X github.com/loft-sh/devpod/pkg/version.version=v${version}"
53 ];
54
55 excludedPackages = [ "./e2e" ];
56
57 nativeBuildInputs = [ installShellFiles ];
58
59 postInstall = ''
60 $out/bin/devpod completion bash >devpod.bash
61 $out/bin/devpod completion fish >devpod.fish
62 $out/bin/devpod completion zsh >devpod.zsh
63 installShellCompletion devpod.{bash,fish,zsh}
64 '';
65
66 passthru.tests.version = testers.testVersion {
67 package = devpod;
68 command = "devpod version";
69 version = "v${version}";
70 };
71 };
72
73 devpod-desktop =
74 let
75 frontend-build = mkYarnPackage {
76 inherit version;
77 pname = "devpod-frontend";
78
79 src = "${src}/desktop";
80
81 offlineCache = fetchYarnDeps {
82 yarnLock = "${src}/desktop/yarn.lock";
83 hash = "sha256-vUV4yX+UvEKrP0vHxjGwtW2WyONGqHVmFor+WqWbkCc=";
84 };
85
86 packageJSON = ./package.json;
87
88 buildPhase = ''
89 export HOME=$(mktemp -d)
90 yarn --offline run build
91
92 cp -r deps/devpod/dist $out
93 '';
94
95 doDist = false;
96 dontInstall = true;
97 };
98
99 rustTargetPlatformSpec = stdenv.hostPlatform.rust.rustcTarget;
100 in
101 rustPlatform.buildRustPackage {
102 inherit version src;
103 pname = "devpod-desktop";
104
105 sourceRoot = "${src.name}/desktop/src-tauri";
106
107 cargoLock = {
108 lockFile = ./Cargo.lock;
109 outputHashes = {
110 "tauri-plugin-log-0.0.0" = "sha256-tM6oLJe/wwqDDNMKBeMa5nNVvsmi5b104xMOvtm974Y=";
111 };
112 };
113
114 # Workaround:
115 # The `tauri` dependency features on the `Cargo.toml` file does not match the allowlist defined under `tauri.conf.json`.
116 # Please run `tauri dev` or `tauri build` or add the `updater` feature.
117 # Upstream is not interested in fixing that: https://github.com/loft-sh/devpod/pull/648
118 patches = [ ./add-tauri-updater-feature.patch ];
119
120 postPatch = ''
121 ln -s ${devpod}/bin/devpod bin/devpod-cli-${rustTargetPlatformSpec}
122 cp -r ${frontend-build} frontend-build
123
124 substituteInPlace tauri.conf.json --replace '"distDir": "../dist",' '"distDir": "frontend-build",'
125 '' + lib.optionalString stdenv.hostPlatform.isLinux ''
126 substituteInPlace $cargoDepsCopy/libappindicator-sys-*/src/lib.rs \
127 --replace "libayatana-appindicator3.so.1" "${libayatana-appindicator}/lib/libayatana-appindicator3.so.1"
128
129 # Since `cargo build` is used instead of `tauri build`, configs are merged manually.
130 jq --slurp '.[0] * .[1]' tauri.conf.json tauri-linux.conf.json >tauri.conf.json.merged
131 mv tauri.conf.json.merged tauri.conf.json
132 '';
133
134 nativeBuildInputs = [
135 copyDesktopItems
136 pkg-config
137 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
138 jq
139 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
140 desktopToDarwinBundle
141 ];
142
143 buildInputs = [
144 libsoup_2_4
145 openssl
146 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
147 gtk3
148 libayatana-appindicator
149 webkitgtk_4_0
150 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
151 darwin.apple_sdk.frameworks.Carbon
152 darwin.apple_sdk.frameworks.Cocoa
153 darwin.apple_sdk.frameworks.WebKit
154 ];
155
156 desktopItems = [
157 (makeDesktopItem {
158 name = "DevPod";
159 categories = [ "Development" ];
160 comment = "Spin up dev environments in any infra";
161 desktopName = "DevPod";
162 exec = "DevPod %U";
163 icon = "DevPod";
164 terminal = false;
165 type = "Application";
166 mimeTypes = [ "x-scheme-handler/devpod" ];
167 })
168 ];
169
170 postInstall = ''
171 ln -sf ${devpod}/bin/devpod $out/bin/devpod-cli
172 mv $out/bin/devpod-desktop $out/bin/DevPod
173
174 mkdir -p $out/share/icons/hicolor/{256x256@2,128x128,32x32}/apps
175 cp icons/128x128@2x.png $out/share/icons/hicolor/256x256@2/apps/DevPod.png
176 cp icons/128x128.png $out/share/icons/hicolor/128x128/apps/DevPod.png
177 cp icons/32x32.png $out/share/icons/hicolor/32x32/apps/DevPod.png
178 '';
179
180 meta = meta // {
181 mainProgram = "DevPod";
182 # darwin does not build
183 # https://github.com/h4llow3En/mac-notification-sys/issues/28
184 platforms = lib.platforms.linux;
185 };
186 };
187}