diff --git a/flake.nix b/flake.nix index 0d7c9bd..6d32819 100644 --- a/flake.nix +++ b/flake.nix @@ -157,9 +157,6 @@ ); lib = lib; formatter = lib.eachSystem (system: nixpkgs.legacyPackages.${system}.nixpkgs-fmt); - - # OpenWrt router management - # ------------- packages = lib.eachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; @@ -167,6 +164,7 @@ in { openwrt-glmain = (openwrt (import ./openwrt-routers/glmain.nix)).deployScript; + grok-cli = lib.pkgs.${system}.grok-cli; } ); diff --git a/modules/core/default.nix b/modules/core/default.nix index 0c8bc1f..3817e37 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -11,6 +11,10 @@ # Must use pythonPackagesExtensions to patch the python3Packages.pipx that # the build system actually uses, not just the top-level pkgs.pipx wrapper. nixpkgs.overlays = [ + (final: _prev: { + # xAI Grok CLI — prebuilt binary, see pkgs/grok-cli. + grok-cli = final.callPackage ../../pkgs/grok-cli { }; + }) (final: prev: { pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ (pyFinal: pyPrev: { diff --git a/modules/lib.nix b/modules/lib.nix index de80a3c..398134f 100644 --- a/modules/lib.nix +++ b/modules/lib.nix @@ -20,6 +20,11 @@ let config = { allowUnfree = true; }; + overlays = [ + (final: _prev: { + grok-cli = final.callPackage ../pkgs/grok-cli { }; + }) + ]; } ); osModules = [ diff --git a/modules/nixos/desktop/packages.nix b/modules/nixos/desktop/packages.nix index 61ff91c..8055a7c 100644 --- a/modules/nixos/desktop/packages.nix +++ b/modules/nixos/desktop/packages.nix @@ -39,6 +39,9 @@ in # terminal ghostty + + # AI coding agents + grok-cli ]); }; } diff --git a/pkgs/grok-cli/default.nix b/pkgs/grok-cli/default.nix new file mode 100644 index 0000000..da4a21a --- /dev/null +++ b/pkgs/grok-cli/default.nix @@ -0,0 +1,80 @@ +{ lib, stdenvNoCC, fetchurl }: + +# Grok CLI — xAI's command-line coding agent. +# +# Upstream ships prebuilt, self-contained binaries (static-pie ELF on Linux, +# Mach-O on macOS) via the installer at https://x.ai/cli/install.sh. There is no +# public source build, so we just fetch the right artifact per platform and drop +# it in $out/bin. No patchelf/autoPatchelfHook is needed — the Linux binary is +# statically linked. +# +# To bump: set `version` and refresh the hashes. The latest stable version is at +# https://storage.googleapis.com/grok-build-public-artifacts/cli/stable +# and the per-platform hash is: +# nix hash file --type sha256 --sri \ +# <(curl -fsSL https://storage.googleapis.com/grok-build-public-artifacts/cli/grok--) + +let + version = "0.2.33"; + + baseUrl = "https://storage.googleapis.com/grok-build-public-artifacts/cli"; + + # nix system → { upstream platform slug, artifact hash } + sources = { + "x86_64-linux" = { + platform = "linux-x86_64"; + hash = "sha256-DAd7As5qRqZkm8G7eSva05acwbL6ZzCmTPm67opkKEM="; + }; + "aarch64-linux" = { + platform = "linux-aarch64"; + hash = "sha256-Csl/20RdR5/skH2Zdv0FeuBwU7wHdXSRZ1iCp0lB88A="; + }; + "x86_64-darwin" = { + platform = "macos-x86_64"; + hash = "sha256-UzLQHZ2UXljG2rfmGxXPA0jLkHoung/UnVBtlvV3Uxg="; + }; + "aarch64-darwin" = { + platform = "macos-aarch64"; + hash = "sha256-ifFeGIepNtlhYCJj4kmZuQD/mjZGjizzKSQSjOS1LoA="; + }; + }; + + system = stdenvNoCC.hostPlatform.system; + source = sources.${system} or (throw "grok-cli: unsupported system '${system}'"); +in +stdenvNoCC.mkDerivation { + pname = "grok-cli"; + inherit version; + + src = fetchurl { + url = "${baseUrl}/grok-${version}-${source.platform}"; + inherit (source) hash; + }; + + dontUnpack = true; + + installPhase = '' + runHook preInstall + install -Dm755 "$src" "$out/bin/grok" + # Upstream installs an `agent` alias alongside `grok` (the binary dispatches + # on argv[0]); preserve it. + ln -s grok "$out/bin/agent" + runHook postInstall + ''; + + # The Linux artifact is static-pie linked, so the only check we can run is the + # one the upstream installer does: confirm it executes. + doInstallCheck = stdenvNoCC.hostPlatform.isLinux; + installCheckPhase = '' + "$out/bin/grok" --version /dev/null + ''; + + meta = { + description = "xAI's Grok command-line coding agent"; + homepage = "https://x.ai/cli"; + license = lib.licenses.unfree; + sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; + platforms = builtins.attrNames sources; + mainProgram = "grok"; + }; +}