zaphyra's git: tgcNUR

fork of https://git.transgirl.cafe/zaphoid/tgc-nix-user-repository

commit 55820e390cad2f4aaa349ed6fdf89a4bf184ecce
parent f5a2cfea2cc2d0365ce69c046af9106382579e04
Author: Katja Ramona Sophie Kwast (zaphyra) <git@zaphyra.eu>
Date: Wed, 20 Aug 2025 16:03:12 +0200

packages: add `gomuks-web`
3 files changed, 202 insertions(+), 0 deletions(-)
A
packages/gomuks-web/0001-cmd-gmuks-add-flag-to-disable-auth.patch
|
68
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A
packages/gomuks-web/0001-web-remove-underscore-from-gomuks.wasm.patch
|
25
+++++++++++++++++++++++++
A
packages/gomuks-web/package.nix
|
109
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/packages/gomuks-web/0001-cmd-gmuks-add-flag-to-disable-auth.patch b/packages/gomuks-web/0001-cmd-gmuks-add-flag-to-disable-auth.patch
@@ -0,0 +1,68 @@
+From c0ad877023d4a519fd9c2995e9b623ef3656f789 Mon Sep 17 00:00:00 2001
+From: "Katja Ramona Sophie Kwast (zaphyra)" <git@zaphyra.eu>
+Date: Wed, 20 Aug 2025 09:56:49 +0200
+Subject: [PATCH] cmd/gmuks: add flag to disable auth
+
+---
+ cmd/gomuks/main.go   | 11 +++++++++--
+ pkg/gomuks/server.go |  6 ++----
+ 2 files changed, 11 insertions(+), 6 deletions(-)
+
+diff --git a/cmd/gomuks/main.go b/cmd/gomuks/main.go
+index e71a06f..be178b2 100644
+--- a/cmd/gomuks/main.go
++++ b/cmd/gomuks/main.go
+@@ -32,10 +32,14 @@ import (
+ 
+ var wantHelp, _ = flag.MakeHelpFlag()
+ var wantVersion = flag.MakeFull("v", "version", "View gomuks version and quit.", "false").Bool()
++var disableAuth = flag.MakeFull("d", "disable-auth", "Disable the basic-auth requested by the web-client", "false").Bool()
+ 
+ func main() {
+-	gomuks.PromptInput = readline.Line
+-	gomuks.PromptPassword = readline.Password
++	if !*disableAuth {
++		gomuks.PromptInput = readline.Line
++		gomuks.PromptPassword = readline.Password
++	}
++
+ 	hicli.InitialDeviceDisplayName = "gomuks web"
+ 	exhttp.AutoAllowCORS = false
+ 	flag.SetHelpTitles(
+@@ -57,6 +61,9 @@ func main() {
+ 	}
+ 
+ 	gmx := gomuks.NewGomuks()
++	if *disableAuth {
++		gmx.DisableAuth = true
++	}
+ 	gmx.Version = version.Version
+ 	gmx.Commit = version.Commit
+ 	gmx.LinkifiedVersion = version.LinkifiedVersion
+diff --git a/pkg/gomuks/server.go b/pkg/gomuks/server.go
+index 100851b..3ffd127 100644
+--- a/pkg/gomuks/server.go
++++ b/pkg/gomuks/server.go
+@@ -245,10 +245,6 @@ func (gmx *Gomuks) writeTokenCookie(w http.ResponseWriter, created, jsonOutput,
+ }
+ 
+ func (gmx *Gomuks) Authenticate(w http.ResponseWriter, r *http.Request) {
+-	if gmx.DisableAuth {
+-		w.WriteHeader(http.StatusOK)
+-		return
+-	}
+ 	jsonOutput := r.URL.Query().Get("output") == "json"
+ 	allowPrompt := r.URL.Query().Get("no_prompt") != "true"
+ 	insecureCookie := r.URL.Query().Get("insecure_cookie") == "true"
+@@ -256,6 +252,8 @@ func (gmx *Gomuks) Authenticate(w http.ResponseWriter, r *http.Request) {
+ 	if err == nil && gmx.validateAuth(authCookie.Value, false) {
+ 		hlog.FromRequest(r).Debug().Msg("Authentication successful with existing cookie")
+ 		gmx.writeTokenCookie(w, false, jsonOutput, insecureCookie)
++	} else if gmx.DisableAuth {
++		gmx.writeTokenCookie(w, true, jsonOutput, insecureCookie)
+ 	} else if found, correct := gmx.doBasicAuth(r); found && correct {
+ 		hlog.FromRequest(r).Debug().Msg("Authentication successful with username and password")
+ 		gmx.writeTokenCookie(w, true, jsonOutput, insecureCookie)
+-- 
+2.50.1
+
diff --git a/packages/gomuks-web/0001-web-remove-underscore-from-gomuks.wasm.patch b/packages/gomuks-web/0001-web-remove-underscore-from-gomuks.wasm.patch
@@ -0,0 +1,25 @@
+From ed26696e39f84cecffd25404078e9ec97f072de0 Mon Sep 17 00:00:00 2001
+From: "Katja Ramona Sophie Kwast (zaphyra)" <git@zaphyra.eu>
+Date: Wed, 20 Aug 2025 09:13:49 +0200
+Subject: [PATCH] web: remove underscore from gomuks.wasm
+
+---
+ web/src/api/wasm/wasmuks.ts | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/web/src/api/wasm/wasmuks.ts b/web/src/api/wasm/wasmuks.ts
+index c002d39..c2b94c7 100644
+--- a/web/src/api/wasm/wasmuks.ts
++++ b/web/src/api/wasm/wasmuks.ts
+@@ -13,7 +13,7 @@
+ //
+ // You should have received a copy of the GNU Affero General Public License
+ // along with this program.  If not, see <https://www.gnu.org/licenses/>.
+-import initGomuksWasm from "./_gomuks.wasm?init"
++import initGomuksWasm from "./gomuks.wasm?init"
+ import "./go_wasm_exec.js"
+ import initSqlite from "./sqlite_bridge.ts"
+ 
+-- 
+2.50.1
+
diff --git a/packages/gomuks-web/package.nix b/packages/gomuks-web/package.nix
@@ -0,0 +1,109 @@
+{
+  tgcMaintainers,
+  lib,
+  fetchFromGitHub,
+  applyPatches,
+  buildGoModule,
+  buildNpmPackage,
+  unstableGitUpdater,
+}:
+
+buildGoModule (finalAttrs: {
+  pname = "gomuks-web";
+  version = "0.4.0-unstable-2025-08-19";
+  rev = "85915b62b390c152a6cb36f4bbb9e5ff25af2cae";
+
+  srcHash = "sha256-LtNDr+gYFUrzhycKfUvJQpIiqbUR5S+fr3WzFk40gfk=";
+  npmDepsHash = "sha256-E2hCrEEsx9VvM2ypomn7EPv+ggLNrrirrqGl2oxeu+Y=";
+  vendorHash = "sha256-7/KkmoetpliQ8+o78/hENWVNPl6Y9YZPXMt+YgVKg0w=";
+
+  src = applyPatches {
+    src = fetchFromGitHub {
+      owner = "tulir";
+      repo = "gomuks";
+      rev = finalAttrs.rev;
+      hash = finalAttrs.srcHash;
+    };
+    patches = [
+      ./0001-web-remove-underscore-from-gomuks.wasm.patch
+      ./0001-cmd-gmuks-add-flag-to-disable-auth.patch
+    ];
+  };
+
+  frontend = buildNpmPackage (frontendFinalAttrs: {
+    name = "${finalAttrs.pname}_${finalAttrs.version}-frontend";
+    src = "${finalAttrs.src}/web";
+    inherit (finalAttrs) version npmDepsHash;
+
+    wasmuks = buildGoModule {
+      name = "${finalAttrs.pname}_${finalAttrs.version}-wasm";
+      inherit (finalAttrs) src vendorHash;
+
+      env.CGO_ENABLED = 0;
+
+      doCheck = false;
+
+      buildPhase = ''
+        GOOS=js GOARCH=wasm go build -tags goolm -ldflags "${lib.concatStringsSep " " finalAttrs.ldflags}" -o ./gomuks.wasm ./cmd/wasmuks
+      '';
+
+      installPhase = ''
+        mkdir -p $out
+        cp gomuks.wasm $out
+      '';
+    };
+
+    preBuildPhases = [ "preBuildPhase" ];
+
+    preBuildPhase = ''
+      cp ${frontendFinalAttrs.wasmuks}/gomuks.wasm src/api/wasm/gomuks.wasm
+    '';
+
+    installPhase = ''
+      cp -r dist $out
+    '';
+  });
+
+  # these flags have to be set, otherwise a dev-build will be created, which is missing features
+  ldflags = [
+    "-X 'go.mau.fi/gomuks/version.Tag=v0.4.0'"
+    "-X 'go.mau.fi/gomuks/version.Commit=${finalAttrs.rev}'"
+    "-X 'go.mau.fi/gomuks/version.BuildTime=2000-01-01T00:00:01+00:00'"
+    (lib.concatStrings [
+      "-X 'maunium.net/go/mautrix.GoModVersion="
+      (lib.pipe (builtins.readFile "${finalAttrs.src}/go.mod") [
+        (builtins.match "^.*maunium.net/go/mautrix ([a-z0-9\.-]+).*$")
+        lib.last
+      ])
+      "'"
+    ])
+  ];
+
+  tags = [ "goolm" ];
+
+  subPackages = [ "cmd/gomuks" ];
+
+  preBuild = ''
+    cp -rf ${finalAttrs.frontend} ./web/dist
+  '';
+
+  postInstall = ''
+    mv $out/bin/gomuks $out/bin/gomuks-web
+  '';
+
+  passthru.updateScript = {
+    inherit (finalAttrs) frontend;
+    updateScript = unstableGitUpdater {
+      branch = "main";
+    };
+  };
+
+  meta = {
+    mainProgram = "gomuks-web";
+    description = "Matrix client written in Go";
+    homepage = "https://github.com/tulir/gomuks";
+    license = lib.licenses.agpl3Only;
+    maintainers = [ tgcMaintainers.zaphyra ];
+    platforms = lib.platforms.unix;
+  };
+})