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