feat: add Nix flake for building and development (#228)

Alexander Holte-Davidsen , Alexander Holte-Davidsen , and drew created

* feat: add Nix flake for building and development

* docs: add Nix Flakes in the installation methods

Signed-off-by: drew <me@andrinoff.com>

* ci: add flake update workflow

Signed-off-by: drew <me@andrinoff.com>

---------

Signed-off-by: drew <me@andrinoff.com>
Co-authored-by: Alexander Holte-Davidsen <alexander.holte.davidsen@kulturit.no>
Co-authored-by: drew <me@andrinoff.com>

Change summary

.github/workflows/update-flake.yml | 26 +++++++++++++
docs/docs/installation.md          | 14 +++++++
flake.lock                         | 61 ++++++++++++++++++++++++++++++++
flake.nix                          | 57 +++++++++++++++++++++++++++++
4 files changed, 158 insertions(+)

Detailed changes

.github/workflows/update-flake.yml 🔗

@@ -0,0 +1,26 @@
+name: Update flake.lock
+
+on:
+  push:
+    branches: [master]
+    paths: [go.sum]
+
+jobs:
+  update:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v6
+
+      - uses: DeterminateSystems/nix-installer-action@main
+
+      - name: Update flake.lock
+        run: nix flake update
+
+      - name: Commit changes
+        run: |
+          git diff --quiet flake.lock && exit 0
+          git config user.name "github-actions[bot]"
+          git config user.email "github-actions[bot]@users.noreply.github.com"
+          git add flake.lock
+          git commit -m "chore: update flake.lock [skip ci]"
+          git push

docs/docs/installation.md 🔗

@@ -64,6 +64,20 @@ You can install Matcha via Flatpak using the following command:
 flatpak install https://matcha.floatpane.com/matcha.flatpakref
 ```
 
+### Nix
+
+You can run Matcha directly using [Nix](https://nixos.org/) flakes:
+
+```bash
+nix run github:floatpane/matcha
+```
+
+Or install it into your profile:
+
+```bash
+nix profile install github:floatpane/matcha
+```
+
 ### Manual Binary Download
 
 You can download pre-compiled binaries from the [Releases page](https://github.com/floatpane/matcha/releases).

flake.lock 🔗

@@ -0,0 +1,61 @@
+{
+  "nodes": {
+    "flake-utils": {
+      "inputs": {
+        "systems": "systems"
+      },
+      "locked": {
+        "lastModified": 1731533236,
+        "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "type": "github"
+      }
+    },
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1772525000,
+        "narHash": "sha256-M7kpjimt0jdEQzmin6ptszf8ev7TVzibyZNSLaLquMM=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "72b1d820cb0149b40a35aa077b4b6d60cd1b23c3",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixpkgs-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "root": {
+      "inputs": {
+        "flake-utils": "flake-utils",
+        "nixpkgs": "nixpkgs"
+      }
+    },
+    "systems": {
+      "locked": {
+        "lastModified": 1681028828,
+        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+        "owner": "nix-systems",
+        "repo": "default",
+        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-systems",
+        "repo": "default",
+        "type": "github"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}

flake.nix 🔗

@@ -0,0 +1,57 @@
+{
+  description = "matcha — a beautiful and functional email client for the terminal";
+
+  inputs = {
+    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+    flake-utils.url = "github:numtide/flake-utils";
+  };
+
+  outputs = { self, nixpkgs, flake-utils }:
+    flake-utils.lib.eachDefaultSystem (system:
+      let
+        pkgs = nixpkgs.legacyPackages.${system};
+      in
+      {
+        packages = rec {
+          matcha = pkgs.buildGoModule.override { go = pkgs.go_1_26; } {
+            pname = "matcha";
+            version = self.shortRev or "dev";
+
+            src = ./.;
+
+            vendorHash = "sha256-fZnAZwwQH2WNewS4pEkl7Bko4smdgo5omkdtA1voXkY=";
+
+            env.CGO_ENABLED = 0;
+
+            ldflags = [
+              "-s"
+              "-w"
+              "-X main.version=${self.shortRev or "dev"}"
+              "-X main.commit=${self.rev or "dirty"}"
+              "-X main.date=1970-01-01T00:00:00Z"
+            ];
+
+            meta = {
+              description = "A beautiful and functional email client for the terminal";
+              homepage = "https://github.com/floatpane/matcha";
+              license = pkgs.lib.licenses.mit;
+              mainProgram = "matcha";
+            };
+          };
+          default = matcha;
+        };
+
+        devShells.default = pkgs.mkShell {
+          buildInputs = with pkgs; [
+            go_1_26
+            gopls
+            gotools
+          ];
+        };
+      }
+    ) // {
+      overlays.default = final: _prev: {
+        matcha = self.packages.${final.system}.matcha;
+      };
+    };
+}