about summary refs log tree commit diff
path: root/pkgs/development/tools/devpod/default.nix
blob: 057c0d1e9df5786a630b7621a2d7c53ca27cfb5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{ lib
, buildGoModule
, copyDesktopItems
, darwin
, desktopToDarwinBundle
, fetchFromGitHub
, fetchYarnDeps
, gtk3
, installShellFiles
, jq
, libayatana-appindicator
, libsoup
, makeDesktopItem
, mkYarnPackage
, openssl
, pkg-config
, rust
, rustPlatform
, stdenv
, testers
, webkitgtk
}:

let
  pname = "devpod";
  version = "0.5.20";

  src = fetchFromGitHub {
    owner = "loft-sh";
    repo = pname;
    rev = "v${version}";
    sha256 = "sha256-8LbqrOKC1als3Xm6ZuU2AySwT0UWjLN2xh+/CvioYew=";
  };

  meta = with lib; {
    description = "Codespaces but open-source, client-only and unopinionated: Works with any IDE and lets you use any cloud, kubernetes or just localhost docker";
    mainProgram = "devpod";
    homepage = "https://devpod.sh";
    license = licenses.mpl20;
    maintainers = with maintainers; [ maxbrunet ];
  };
in
rec {
  devpod = buildGoModule {
    inherit version src pname meta;

    vendorHash = null;

    CGO_ENABLED = 0;

    ldflags = [
      "-X github.com/loft-sh/devpod/pkg/version.version=v${version}"
    ];

    excludedPackages = [ "./e2e" ];

    nativeBuildInputs = [ installShellFiles ];

    postInstall = ''
      $out/bin/devpod completion bash >devpod.bash
      $out/bin/devpod completion fish >devpod.fish
      $out/bin/devpod completion zsh >devpod.zsh
      installShellCompletion devpod.{bash,fish,zsh}
    '';

    passthru.tests.version = testers.testVersion {
      package = devpod;
      command = "devpod version";
      version = "v${version}";
    };
  };

  devpod-desktop =
    let
      frontend-build = mkYarnPackage {
        inherit version;
        pname = "devpod-frontend";

        src = "${src}/desktop";

        offlineCache = fetchYarnDeps {
          yarnLock = "${src}/desktop/yarn.lock";
          hash = "sha256-vUV4yX+UvEKrP0vHxjGwtW2WyONGqHVmFor+WqWbkCc=";
        };

        packageJSON = ./package.json;

        buildPhase = ''
          export HOME=$(mktemp -d)
          yarn --offline run build

          cp -r deps/devpod/dist $out
        '';

        doDist = false;
        dontInstall = true;
      };

      rustTargetPlatformSpec = stdenv.hostPlatform.rust.rustcTarget;
    in
    rustPlatform.buildRustPackage {
      inherit version src;
      pname = "devpod-desktop";

      sourceRoot = "${src.name}/desktop/src-tauri";

      cargoLock = {
        lockFile = ./Cargo.lock;
        outputHashes = {
          "tauri-plugin-log-0.0.0" = "sha256-tM6oLJe/wwqDDNMKBeMa5nNVvsmi5b104xMOvtm974Y=";
        };
      };

      # Workaround:
      #   The `tauri` dependency features on the `Cargo.toml` file does not match the allowlist defined under `tauri.conf.json`.
      #   Please run `tauri dev` or `tauri build` or add the `updater` feature.
      # Upstream is not interested in fixing that: https://github.com/loft-sh/devpod/pull/648
      patches = [ ./add-tauri-updater-feature.patch ];

      postPatch = ''
        ln -s ${devpod}/bin/devpod bin/devpod-cli-${rustTargetPlatformSpec}
        cp -r ${frontend-build} frontend-build

        substituteInPlace tauri.conf.json --replace '"distDir": "../dist",' '"distDir": "frontend-build",'
      '' + lib.optionalString stdenv.hostPlatform.isLinux ''
        substituteInPlace $cargoDepsCopy/libappindicator-sys-*/src/lib.rs \
          --replace "libayatana-appindicator3.so.1" "${libayatana-appindicator}/lib/libayatana-appindicator3.so.1"

        # Since `cargo build` is used instead of `tauri build`, configs are merged manually.
        jq --slurp '.[0] * .[1]' tauri.conf.json tauri-linux.conf.json >tauri.conf.json.merged
        mv tauri.conf.json.merged tauri.conf.json
      '';

      nativeBuildInputs = [
        copyDesktopItems
        pkg-config
      ] ++ lib.optionals stdenv.hostPlatform.isLinux [
        jq
      ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
        desktopToDarwinBundle
      ];

      buildInputs = [
        libsoup
        openssl
      ] ++ lib.optionals stdenv.hostPlatform.isLinux [
        gtk3
        libayatana-appindicator
        webkitgtk
      ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
        darwin.apple_sdk.frameworks.Carbon
        darwin.apple_sdk.frameworks.Cocoa
        darwin.apple_sdk.frameworks.WebKit
      ];

      desktopItems = [
        (makeDesktopItem {
          name = "DevPod";
          categories = [ "Development" ];
          comment = "Spin up dev environments in any infra";
          desktopName = "DevPod";
          exec = "DevPod %U";
          icon = "DevPod";
          terminal = false;
          type = "Application";
          mimeTypes = [ "x-scheme-handler/devpod" ];
        })
      ];

      postInstall = ''
        ln -sf ${devpod}/bin/devpod $out/bin/devpod-cli
        mv $out/bin/devpod-desktop $out/bin/DevPod

        mkdir -p $out/share/icons/hicolor/{256x256@2,128x128,32x32}/apps
        cp icons/128x128@2x.png $out/share/icons/hicolor/256x256@2/apps/DevPod.png
        cp icons/128x128.png $out/share/icons/hicolor/128x128/apps/DevPod.png
        cp icons/32x32.png $out/share/icons/hicolor/32x32/apps/DevPod.png
      '';

      meta = meta // {
        mainProgram = "DevPod";
        # darwin does not build
        # https://github.com/h4llow3En/mac-notification-sys/issues/28
        platforms = lib.platforms.linux;
      };
    };
}