summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 6158d53b83f319b9c5c2caad7f1c47b45dcac993 (plain)
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
188
189
190
# flake.nix — Lumo Desktop (Proton's privacy-first AI assistant) for Nix
#
# Upstream: https://github.com/ProtonLumo/lumo-desktop (Tauri v2, GPL-3.0)
#
# "Always current master": `nix flake update lumo-src` advances the lock.
#
# THE CRITICAL FINDING:
#   src-tauri/src/lib.rs defines the web app URL as a COMPILE-TIME
#   constant: option_env!("LUMO_URL") with default
#   "https://lumo.proton.dev" — Proton's INTERNAL DEV environment.
#   Building from the public repo without injection therefore talks to
#   the dev endpoint, whose certificate the system trust store rightly
#   rejects ("Unacceptable TLS certificate"). Production builds get
#   LUMO_URL injected in Proton's internal CI. We do the same via the
#   derivation environment (option_env! reads it at compile time).
#
# RUNTIME PIECES (all verified necessary step by step):
#   * libayatana-appindicator on LD_LIBRARY_PATH (tray dlopen)
#   * glib-networking in buildInputs — GIO's gnutls TLS backend for
#     WebKitGTK HTTPS (confirmed loaded in G_MESSAGES_DEBUG logs);
#     wrapGAppsHook exports GIO_EXTRA_MODULES, that suffices
#   * cacert bundle exported for any OpenSSL-style consumers
#   * GIO_MODULE_DIR experiment REMOVED — the backend was found
#     without it; --set would have hidden other GIO modules.
#
# VERIFIED (GitHub file tree + README + build/run logs, branch master):
#   * src-tauri/Cargo.toml, src-tauri/Cargo.lock committed
#   * webview npm script: `npm run build:webview` — builds fine offline
#   * upstream version from package.json (currently 0.5.9)
#   * updater WARN (missing "linux-x86_64" platform) was a symptom of
#     the dev endpoint; should disappear with the production URL.

{
  description = "Lumo Desktop, Proton's privacy-first AI assistant (Tauri)";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

    # Tracks upstream master; lock pins the last-updated commit.
    lumo-src = {
      url = "github:ProtonLumo/lumo-desktop";
      flake = false;
    };

    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, lumo-src, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };

        upstreamVersion = (builtins.fromJSON (builtins.readFile "${lumo-src}/package.json")).version;
        version = "${upstreamVersion}-master-${builtins.substring 0 8 lumo-src.lastModifiedDate or "unknown"}";

        src = lumo-src;

        lumoBuildInputs = with pkgs; [
          gtk3
          webkitgtk_4_1
          glib-networking     # GIO TLS module (gnutls backend) for the
                              # webview's HTTPS at runtime
          libsoup_3
          glib
          cairo
          pango
          gdk-pixbuf
          atk
          librsvg
          openssl
          aws-lc          # system AWS-LC: satisfies aws-lc-sys USE_SYSTEM=1
          libayatana-appindicator  # tray icon lib, dlopen'ed at runtime
          dbus
          libsecret
          gsettings-desktop-schemas
          hicolor-icon-theme
        ];

        lumo-desktop = pkgs.rustPlatform.buildRustPackage {
          pname = "lumo-desktop";
          inherit version src;

          # Injected into the build env; lib.rs reads it via option_env!
          # at compile time. Use the PRODUCTION web app, not the public
          # repo's dev default (lumo.proton.dev).
          LUMO_URL = "https://lumo.proton.me";

          cargoRoot = "src-tauri";
          buildAndTestSubdir = "src-tauri";

          cargoLock.lockFile = "${src}/src-tauri/Cargo.lock";
          cargoLock.outputHashes = { };

          npmDeps = pkgs.fetchNpmDeps {
            inherit src;
            hash = "sha256-GqCjpQWj7d342yqs+H+1ckIgnVMx9wNDeET0uwQP0pM=";
          };

          nativeBuildInputs = with pkgs; [
            pkg-config
            nodejs
            pkgs.npmHooks.npmConfigHook
            wrapGAppsHook3
          ];

          buildInputs = lumoBuildInputs;

          doCheck = false; # e2e suite needs a WebKitGTK container

          preConfigure = ''
            export HOME=$TMPDIR
            npm ci --ignore-scripts
            npm run build:webview
            if [ ! -e src-tauri/dist ]; then
              echo "ERROR: src-tauri/dist missing after build:webview."
              exit 1
            fi
          '';

          preFixup = ''
            gappsWrapperArgs+=(
              # Tray lib for the runtime dlopen:
              --prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath [ pkgs.libayatana-appindicator ]}"

              # CA trust store for any OpenSSL-style consumers:
              --set SSL_CERT_FILE "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
              --set NIX_SSL_CERT_FILE "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
            )
          '';

          postInstall = ''
            # TODO: src-tauri/linux/ ships prebuilt bundle metadata —
            # prefer its .desktop/icons over this hand-written entry
            # after inspecting the directory.
            mkdir -p $out/share/applications
            mkdir -p $out/share/icons/hicolor/512x512/apps
            install -Dm644 src-tauri/icons/icon.png \
              $out/share/icons/hicolor/512x512/apps/lumo.png || true
            cat > $out/share/applications/me.proton.lumo-app.desktop <<EOF
            [Desktop Entry]
            Type=Application
            Name=Lumo
            Comment=Proton's privacy-first AI assistant
            Exec=lumo-desktop
            Icon=lumo
            Terminal=false
            Categories=Network;Utility;
            EOF
          '';

          meta = with pkgs.lib; {
            description = "Lumo Desktop, Proton's privacy-first AI assistant";
            homepage = "https://github.com/ProtonLumo/lumo-desktop";
            license = licenses.gpl3Only;
            mainProgram = "lumo-desktop";
            platforms = platforms.linux ++ platforms.darwin;
          };
        };

      in
      {
        packages.default = lumo-desktop;
        packages.lumo-desktop = lumo-desktop;

        apps.default = {
          type = "app";
          program = "${lumo-desktop}/bin/lumo-desktop";
        };

        overlays.default = final: _: {
          lumo-desktop = lumo-desktop;
        };
      })

    // {
      # Minimal Home Manager module: just adds the package.
      homeManagerModules.default = { config, lib, pkgs, ... }: {
        options.services.lumo-desktop = {
          enable = lib.mkEnableOption "Lumo Desktop";
          package = lib.mkPackageOption pkgs "lumo-desktop" { };
        };
        config = lib.mkIf config.services.lumo-desktop.enable {
          home.packages = [ config.services.lumo-desktop.package ];
        };
      };

      # Optional rolling-master timer (unchanged):
      # systemd timer running `nix flake update lumo-src` daily.
    };
}