feat: add nix flake packaging

This commit is contained in:
2026-07-26 22:55:24 +04:00
parent 3393f9e767
commit a13d9d11f7
5 changed files with 172 additions and 4 deletions
+4
View File
@@ -1 +1,5 @@
bin/*
# Nix build artifacts
result
result-*
+42 -4
View File
@@ -36,10 +36,11 @@ Sarin is designed for efficient HTTP load testing with minimal resource consumpt
## Installation
### Docker (Recommended)
<details open>
<summary><b>Docker</b></summary>
```sh
docker pull aykhans/sarin:latest
docker run -it aykhans/sarin:latest --version
```
With a local config file:
@@ -54,11 +55,46 @@ With a remote config file:
docker run --rm -it aykhans/sarin -f https://example.com/config.yaml
```
### Pre-built Binaries
</details>
<details>
<summary><b>Nix</b></summary>
Run directly without installing (requires flakes enabled):
```sh
nix run github:aykhans/sarin/v1.3.2 -- -U http://example.com -r 100 -c 10
```
Install into your profile:
```sh
nix profile install github:aykhans/sarin/v1.3.2
```
Or add it to your own flake via the overlay:
```nix
{
inputs.sarin.url = "github:aykhans/sarin/v1.3.2";
# In your outputs, apply the overlay to nixpkgs:
# nixpkgs.overlays = [ inputs.sarin.overlays.default ];
# then reference pkgs.sarin
}
```
</details>
<details>
<summary><b>Pre-built Binaries</b></summary>
Download the latest binaries from the [releases](https://github.com/aykhans/sarin/releases) page.
### Building from Source
</details>
<details>
<summary><b>Building from Source</b></summary>
Requires [Go 1.26+](https://golang.org/dl/).
@@ -74,6 +110,8 @@ CGO_ENABLED=0 go build \
-o sarin ./cmd/cli/main.go
```
</details>
## Quick Start
Send 10,000 GET requests with 50 concurrent connections and a random User-Agent for each request:
Generated
+27
View File
@@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1784796856,
"narHash": "sha256-wWFrV5/Qbm+lyt5x20E/bSbfJiGKMo4RCxZV8cl/WZI=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e2587caef70cea85dd97d7daab492899902dbf5d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}
+55
View File
@@ -0,0 +1,55 @@
{
description = "Sarin - high-performance HTTP load testing tool built with Go and fasthttp";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = f: lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
rev = self.rev or self.dirtyRev or "unknown";
# self.lastModifiedDate is "YYYYMMDDHHMMSS"; reshape to RFC 3339 (UTC).
raw = self.lastModifiedDate or "19700101000000";
s = i: n: lib.substring i n raw;
buildDate = "${s 0 4}-${s 4 2}-${s 6 2}T${s 8 2}:${s 10 2}:${s 12 2}Z";
in
{
packages = forAllSystems (pkgs: {
default = pkgs.callPackage ./nix/package.nix {
inherit rev buildDate;
};
});
# nix run github:aykhans/sarin -- <args>
apps = forAllSystems (pkgs: {
default = {
type = "app";
program = "${self.packages.${pkgs.system}.default}/bin/sarin";
meta.description = "High-performance HTTP load testing tool";
};
});
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = [ pkgs.go_1_26 pkgs.golangci-lint pkgs.go-task ];
};
});
# For downstream flakes: inputs.sarin.overlays.default
overlays.default = final: _prev: {
sarin = final.callPackage ./nix/package.nix { };
};
};
}
+44
View File
@@ -0,0 +1,44 @@
{ lib
, stdenv
, buildGoModule
, go_1_26
, rev ? "unknown"
, buildDate ? "unknown"
}:
(buildGoModule.override { go = go_1_26; }) (finalAttrs: {
pname = "sarin";
version = "1.3.2"; # bump per release
src = lib.cleanSource ../.;
vendorHash = "sha256-BMH0alJeZoK/8cE9Y+s++G7D+Dg5xcZNTU4zkRMBpfU=";
subPackages = [ "cmd/cli" ];
env.CGO_ENABLED = 0; # fully static binary
ldflags = [
"-s"
"-w"
"-X=go.aykhans.me/sarin/internal/version.Version=v${finalAttrs.version}"
"-X=go.aykhans.me/sarin/internal/version.GitCommit=${rev}"
"-X=go.aykhans.me/sarin/internal/version.BuildDate=${buildDate}"
# Value has spaces, so it is single-quoted: `go build` splits -ldflags
# shell-style and honours the quotes, keeping this as one -X value.
"-X 'go.aykhans.me/sarin/internal/version.GoVersion=go version go${go_1_26.version} ${stdenv.hostPlatform.go.GOOS}/${stdenv.hostPlatform.go.GOARCH}'"
];
# cmd/cli produces a binary named "cli"; rename it to "sarin".
postInstall = ''
mv $out/bin/cli $out/bin/sarin
'';
meta = {
description = "High-performance HTTP load testing tool built with Go and fasthttp";
homepage = "https://github.com/aykhans/sarin";
license = lib.licenses.mit;
mainProgram = "sarin";
maintainers = [ ];
};
})