summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 2ab70068a471fbcaba19517ef79c149e4588ebb7 (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
191
192
193
194
195
196
197
198
199
200
201
# 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.
#   We inject the production URL via the derivation environment.
#
# RUNTIME PIECES (verified):
#   * libayatana-appindicator on LD_LIBRARY_PATH (tray dlopen)
#   * glib-networking in buildInputs (GIO gnutls TLS for WebKitGTK)
#   * LUMO_URL = https://lumo.proton.me at build time
#
# NOTES:
#   * overlays.default is TOP-LEVEL (not inside eachDefaultSystem).
#   * Overlay resolves the package via
#     final.stdenv.hostPlatform.system — `final.system` (like
#     `pkgs.system`) is deprecated and triggers an eval warning.

{
  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";
        };
      })

    // {
      # ------------------------------------------------------------
      # System-INDEPENDENT outputs live here, OUTSIDE eachDefaultSystem.
      # ------------------------------------------------------------

      overlays.default = final: _prev: {
        # Consumer's system via the non-deprecated accessor.
        lumo-desktop =
          self.packages.${final.stdenv.hostPlatform.system}.lumo-desktop
          or self.packages.x86_64-linux.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 (drop into your NixOS config):
      # systemd.services.lumo-desktop-update = {
      #   description = "Update lumo-desktop flake input to master";
      #   serviceConfig = {
      #     Type = "oneshot";
      #     User = "nathan";
      #     WorkingDirectory = "/home/nathan/projekte/lumo-flake";
      #   };
      #   script = ''${pkgs.nix}/bin/nix flake update lumo-src'';
      # };
      # systemd.timers.lumo-desktop-update = {
      #   wantedBy = [ "timers.target" ];
      #   timerConfig.OnCalendar = "daily";
      #   timerConfig.Persistent = true;
      # };
    };
}