diff --git a/.gitignore b/.gitignore index f56945d5..2ef0034b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,13 @@ # Build directories package +# Standalone binary compiled by npm run build:standalone +seam + +# Nix build results +result +result-* + # Shell completions generated on prepack completions diff --git a/README.md b/README.md index 3fe09abd..5a6959a5 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ Alternatively, download a standalone binary for your platform from the Inc. Apple Developer ID and notarized by Apple, so macOS runs them without a Gatekeeper prompt. -After a manual download, install the shell completions with +After a manual download, install the [shell completion] with ``` $ seam completion --install @@ -97,12 +97,27 @@ $ cd seam-bin $ makepkg -si ``` -The AUR and Homebrew packages install [shell completion] themselves. After an -npm or manual install, run `seam completion --install`. +### Nix + +Run the CLI without installing it with [Nix] with + +``` +$ nix run github:seamapi/cli +``` + +Install it into your profile with + +``` +$ nix profile install github:seamapi/cli +``` + +The flake compiles the standalone binary from source for `x86_64-linux`, +`aarch64-linux`, and `aarch64-darwin`. [aur]: https://aur.archlinux.org/packages/seam-bin [Homebrew]: https://formulae.brew.sh/cask/seam [latest GitHub release]: https://github.com/seamapi/cli/releases/latest +[Nix]: https://nixos.org/ [npm]: https://www.npmjs.com/ [Seam Wizard]: https://github.com/seamapi/wizard [shell completion]: #shell-completion diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..a2b57527 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1787135253, + "narHash": "sha256-RD2kNWCG+Bjo6h+JVjWVNntZs2GtRoeY2xHjts/FNkA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ffb3c9b700e759be2ef13237c9d8f953b32a1e46", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..f8a44ca3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,24 @@ +{ + description = "A command-line interface (CLI) for interacting with the Seam API."; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = + { nixpkgs, ... }: + let + systems = [ + "aarch64-darwin" + "aarch64-linux" + "x86_64-linux" + ]; + forEachSystem = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system}); + in + { + packages = forEachSystem (pkgs: rec { + seam = pkgs.callPackage ./package.nix { }; + default = seam; + }); + }; +} diff --git a/package.json b/package.json index cea8abba..58b5658f 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,8 @@ "build:ts": "tsc --project tsconfig.build.json", "prebuild:ts": "del 'index.*' bin lib", "postbuild:ts": "tsc-alias --project tsconfig.build.json", + "build:standalone": "bun build src/bin/cli.ts --compile --minify --outfile seam", + "prebuild:standalone": "npm run prepack", "typecheck": "tsc", "test": "vitest run --coverage", "pretest": "tsx src/index.ts", diff --git a/package.nix b/package.nix new file mode 100644 index 00000000..f9992e90 --- /dev/null +++ b/package.nix @@ -0,0 +1,54 @@ +{ + lib, + stdenv, + bun, + buildNpmPackage, + importNpmLock, + installShellFiles, +}: + +buildNpmPackage { + pname = "seam"; + version = (lib.importJSON ./package.json).version; + + src = lib.cleanSource ./.; + + npmDeps = importNpmLock { npmRoot = ./.; }; + npmConfigHook = importNpmLock.npmConfigHook; + + nativeBuildInputs = [ + bun + installShellFiles + ]; + npmBuildScript = "build:standalone"; + + installPhase = '' + runHook preInstall + + install -Dm755 seam -t $out/bin + + runHook postInstall + ''; + + postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + installShellCompletion --cmd seam \ + --bash <($out/bin/seam completion --loader bash) \ + --fish <($out/bin/seam completion --loader fish) \ + --zsh <($out/bin/seam completion --loader zsh) + ''; + + # The executable is the Bun runtime with the JavaScript bundle appended, so + # rewriting the ELF loses the bundle: stripped it runs as plain Bun, + # patchelfed it segfaults. + dontStrip = true; + dontPatchELF = true; + + meta = { + description = "Command-line interface (CLI) for interacting with the Seam API"; + homepage = "https://github.com/seamapi/cli"; + changelog = "https://github.com/seamapi/cli/releases"; + license = lib.licenses.mit; + mainProgram = "seam"; + platforms = bun.meta.platforms; + }; +}