{ self, inputs, ... }: { perSystem = { pkgs, system, lib, ... }: { _module.args.pkgs = import inputs.nixpkgs { inherit system; config = { android_sdk.accept_license = true; allowUnfree = true; }; }; packages = let unpatched = pkgs.callPackage ./pkg { src = self; commit = self.shortRev or self.dirtyShortRev; }; # Without this, GTK3 can't create a GL context on Mesa builds without GLES 1 # (Flathub's since 26.2.8). Drop once nixpkgs has a GTK3 release with it. # Swapped into the finished closure, as an overlay would rebuild half of nixpkgs withPatchedGtk = drv: pkgs.replaceDependencies { inherit drv; replacements = [ { oldDependency = pkgs.gtk3; newDependency = pkgs.gtk3.overrideAttrs (old: { patches = old.patches or [ ] ++ [ ./patches/gtk3-egl-renderable-type.patch ]; # So the flatpak gets text-input-v3 (and with it the OSK) without our immodules.cache mesonFlags = old.mesonFlags or [ ] ++ [ "-Dbuiltin_immodules=wayland" ]; }); } ]; } // { inherit (drv) pname version meta; }; default = withPatchedGtk unpatched; in { inherit default; flatpak = inputs.nix2flatpak.lib.${system}.mkFlatpak { appName = "Nexus"; developer = "QuadRadical"; appId = "nexus.federated.nexus"; # The runtime's GStreamer gets loaded instead of ours, and it can't # load our plugins, so keep wrapGAppsHook from pointing it at them package = withPatchedGtk ( unpatched.overrideAttrs (old: { postInstall = '' unset GST_PLUGIN_SYSTEM_PATH_1_0 '' + old.postInstall; # Our GTK's default immodules.cache path isn't in the flatpak; use the runtime's preFixup = old.preFixup or "" + '' gappsWrapperArgs+=(--set-default GTK_IM_MODULE_FILE /usr/lib/${pkgs.stdenv.hostPlatform.uname.processor}-linux-gnu/gtk-3.0/3.0.0/immodules.cache) ''; # nix2flatpak swaps dropped RUNPATH entries for the runtime's libdir in place, # which would put it ahead of our patched GTK, so move GTK to the front postFixup = old.postFixup or "" + '' bin=$out/app/nexus/nexus ${lib.getExe pkgs.patchelf} --set-rpath \ "${lib.getLib pkgs.gtk3}/lib:$(${lib.getExe pkgs.patchelf} --print-rpath $bin)" $bin ''; }) ); runtime = "org.gnome.Platform/51"; # Hide the runtime's GTK3 from nix2flatpak, so it bundles our patched one runtimeIndex = pkgs.runCommand "runtime-index.json" { nativeBuildInputs = [ pkgs.jq ]; } '' jq 'del(.sonames["libgtk-3.so.0", "libgdk-3.so.0", "libgailutil-3.so.0"])' \ ${inputs.nix2flatpak}/runtimes/org.gnome.Platform/51/runtime-index.json > $out ''; permissions = { share = [ "network" ]; sockets = [ "pulseaudio" "fallback-x11" "wayland" ]; talk-names = [ "org.unifiedpush.Distributor.*" "org.freedesktop.Notifications" ]; devices = [ "dri" ]; }; }; gomuks = pkgs.callPackage ./pkg/gomuks.nix { src = self; }; }; devShells.default = pkgs.callPackage ./devshell.nix { }; apps = let buildEnv = import ./build_env.nix { inherit pkgs lib; }; testEnv = buildEnv.env // { DBUS_SESSION_CONFIG = "${pkgs.dbus}/share/dbus-1/session.conf"; }; e2e = pkgs.writeShellApplication { name = "nexus-e2e"; runtimeInputs = buildEnv.packages ++ (with pkgs; [ # TEMPORARY: matrix-continuwuity, once the local fixes are released (inputs.continuwuity.packages.${system}.default.overrideAttrs { doCheck = false; }) curl dbus ]); runtimeEnv = testEnv; text = builtins.readFile ./e2e.sh; }; screenshots = pkgs.writeShellApplication { name = "nexus-screenshots"; runtimeInputs = buildEnv.packages ++ (with pkgs; [ dbus oxipng pngquant ]); runtimeEnv = testEnv; text = builtins.readFile ./screenshots.sh; }; headless = program: lib.getExe ( pkgs.writeShellApplication { name = "${lib.getName program}-headless"; runtimeInputs = [ pkgs.cage ]; runtimeEnv = { WLR_BACKENDS = "headless"; __EGL_VENDOR_LIBRARY_FILENAMES = "${pkgs.mesa}/share/glvnd/egl_vendor.d/50_mesa.json"; }; text = '' unset DISPLAY WAYLAND_DISPLAY # Wayland needs one, which CI may not have XDG_RUNTIME_DIR="''${XDG_RUNTIME_DIR:-$(mktemp -d)}" export XDG_RUNTIME_DIR exec cage -- ${lib.getExe program} "$@" ''; } ); in { e2e = { type = "app"; program = lib.getExe e2e; }; bump-libmpv = { type = "app"; program = lib.getExe ( pkgs.writeShellApplication { name = "nexus-bump-libmpv"; runtimeInputs = with pkgs; [ coreutils curl git gnugrep gnused jq ]; text = builtins.readFile ./bump_libmpv.sh; } ); }; e2e-headless = { type = "app"; program = headless e2e; }; screenshots = { type = "app"; program = headless screenshots; }; }; }; flake.nixosModules.default = import ./module.nix self; }