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