diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41195ff..00ebd5d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,3 +39,19 @@ jobs: - name: Test run: go test ./... + nix: + runs-on: ubuntu-latest + env: + CGO_ENABLED: 0 + steps: + - uses: actions/checkout@v7 + - uses: cachix/install-nix-action@6b2916c41eac5735ac995c58c9e8561a78c42319 # v31 + # Check that the flake is at least correct on all systems, does not run + # any builds + - name: Run nix flake check + run: | + nix flake check -vL --no-build --all-systems + # Checks get run during the nix build + - name: Nix build/test + run: | + nix build -vL .#clawscli --print-out-paths diff --git a/.gitignore b/.gitignore index d7cf440..9b78807 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,7 @@ claws.log node_modules/ .claude .gtrconfig + +# Nix +result +result-* diff --git a/README.md b/README.md index 3cd8f2b..4009c66 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,14 @@ go install github.com/clawscli/claws/cmd/claws@latest docker run -it --rm -v ~/.aws:/home/claws/.aws:ro ghcr.io/clawscli/claws ``` +### Nix + +```bash +nix profile add github:clawscli/claws +# or run it without installing to a profile: +nix run github:clawscli/claws -- ... +``` + ## Quick Start ```bash diff --git a/flake.nix b/flake.nix index ebd6c8e..5a6113e 100644 --- a/flake.nix +++ b/flake.nix @@ -6,58 +6,113 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = import nixpkgs { inherit system; }; lib = pkgs.lib; - indexionPlatform = { - "aarch64-darwin" = "darwin-arm64"; - "x86_64-darwin" = "darwin-x64"; - "aarch64-linux" = "linux-arm64"; - "x86_64-linux" = "linux-x64"; - }.${system} or (throw "indexion: unsupported system ${system}"); - - indexionHash = { - "darwin-arm64" = "1w3m4px4f5hjr0776rxf3682rizz909zrvsh8i115ig67n1riqq5"; - "darwin-x64" = "0000000000000000000000000000000000000000000000000000"; - "linux-arm64" = "0000000000000000000000000000000000000000000000000000"; - "linux-x64" = "0y7dbkrxyr56kdz326hxpm6i3pljp2z4jpzv1mc5qqwrzqfgybbd"; - }.${indexionPlatform}; - - # No upstream release binary for this platform yet (e.g. linux-arm64). - # Dummy hash = unsupported; drop indexion from the shell instead of failing. - indexionSupported = indexionHash != "0000000000000000000000000000000000000000000000000000"; - - indexion = pkgs.stdenvNoCC.mkDerivation { - pname = "indexion"; - version = "0.16.0"; - src = pkgs.fetchzip { - url = "https://github.com/trkbt10/indexion/releases/download/v0.16.0/indexion-${indexionPlatform}.tar.gz"; - sha256 = indexionHash; - stripRoot = true; - }; - installPhase = '' - mkdir -p $out/bin $out/share/indexion - cp indexion $out/bin/ - cp -r kgfs $out/share/indexion/ - ''; + indexion = + let + indexionHashes = { + "aarch64-darwin" = "1w3m4px4f5hjr0776rxf3682rizz909zrvsh8i115ig67n1riqq5"; + "x86_64-linux" = "0y7dbkrxyr56kdz326hxpm6i3pljp2z4jpzv1mc5qqwrzqfgybbd"; + }; + nodePlatform = pkgs.stdenv.targetPlatform.node; + indexionFile = "indexion-${nodePlatform.platform}-${nodePlatform.arch}.tar.gz"; + in + pkgs.stdenvNoCC.mkDerivation (fa: { + pname = "indexion"; + version = "0.16.0"; + src = pkgs.fetchzip { + url = "https://github.com/trkbt10/${fa.pname}/releases/download/v${fa.version}/${indexionFile}"; + sha256 = indexionHashes.${system} or (throw "indexion: unsupported system"); + stripRoot = true; + }; + installPhase = '' + mkdir -p $out/bin $out/share/indexion + cp indexion $out/bin/ + cp -r kgfs $out/share/indexion/ + ''; + meta = { + platforms = builtins.attrNames indexionHashes; + }; + }); + in + { + packages = { + clawscli = pkgs.buildGoModule (fa: { + pname = "claws"; + version = "git-${self.dirtyShortRev or self.shortRev}"; + # Needs to be changed whenever dependencies are updated + vendorHash = "sha256-Ef/2Xs15E5noUYJk2J9k48g0kfTPB6v+D9uUHdOyya0="; + src = + let + inherit (pkgs.lib.fileset) toSource unions; + in + toSource { + root = ./.; + fileset = unions [ + ./go.mod + ./go.sum + ./cmd + ./custom + ./docs + ./internal + ./scripts + ./testdata + ]; + }; + # Note: only building `cmd/claws` does not run the checks properly + excludedPackages = [ + "scripts/gen-imports" + ]; + ldflags = [ + "-s" + "-w" + "-X main.version=${fa.version}" + ]; + # Replace these absolute path to echo with the nix path for testing + postPatch = '' + substituteInPlace internal/action/action_test.go \ + --replace-warn '/bin/echo' '${pkgs.coreutils}/bin/echo' + ''; + # Fix home to be a writable tmp directory for config tests + preCheck = '' + export HOME=$(mktemp -d) + ''; + }); + gen-imports = self.packages.${system}.clawscli.overrideAttrs ( + f: p: { + pname = "gen-imports"; + subPackages = p.excludedPackages or [ ]; + excludedPackages = [ ]; + } + ); + default = self.packages.${system}.clawscli; }; - in { devShells.default = pkgs.mkShell { - packages = with pkgs; [ - go_1_25 - go-task - gopls - golangci-lint - vhs - ttyd - nodejs - bash - ] ++ lib.optionals indexionSupported [ - indexion - ]; + packages = + with pkgs; + [ + go_1_25 + go-task + gopls + golangci-lint + vhs + ttyd + nodejs + bash + ] + ++ lib.optionals (builtins.elem pkgs.stdenv.targetPlatform.system indexion.meta.platforms) [ + indexion + ]; env.GOROOT = "${pkgs.go_1_25}/share/go";