From 5f76d5cd7605a352213651d6604e8f21e3a850dd Mon Sep 17 00:00:00 2001 From: Karol Broda Date: Tue, 16 Dec 2025 23:12:44 +0100 Subject: [PATCH] add nix package and installation docs --- .gitignore | 3 ++ README.md | 30 +++++++++++++++++++ flake.lock | 6 ++-- flake.nix | 87 +++++++++++++++++++++++++++++------------------------- 4 files changed, 83 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index 8f21b30..1f4384c 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,9 @@ Thumbs.db # go vendor/ +# nix +result + # misc *.log *.tmp diff --git a/README.md b/README.md index ef696da..32b1506 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,40 @@ a friendlier `ss` / `netstat` for humans. inspect network connections with a cle ## install +### go + ```bash go install github.com/karol-broda/snitch@latest ``` +### nixos / nix + +```bash +# try it +nix run github:karol-broda/snitch + +# install to profile +nix profile install github:karol-broda/snitch + +# or add to flake inputs +{ + inputs.snitch.url = "github:karol-broda/snitch"; +} +# then use: inputs.snitch.packages.${system}.default +``` + +### binary + +download from [releases](https://github.com/karol-broda/snitch/releases): + +```bash +# amd64 +curl -L https://github.com/karol-broda/snitch/releases/latest/download/snitch_linux_amd64.tar.gz | tar xz +sudo mv snitch /usr/local/bin/ + +# or install .deb/.rpm/.apk from releases +``` + ## quick start ```bash diff --git a/flake.lock b/flake.lock index 28f9bb0..bb25822 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1756217674, - "narHash": "sha256-TH1SfSP523QI7kcPiNtMAEuwZR3Jdz0MCDXPs7TS8uo=", + "lastModified": 1765687488, + "narHash": "sha256-7YAJ6xgBAQ/Nr+7MI13Tui1ULflgAdKh63m1tfYV7+M=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4e7667a90c167f7a81d906e5a75cba4ad8bee620", + "rev": "d02bcc33948ca19b0aaa0213fe987ceec1f4ebe1", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 2482201..576fa2d 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "go 1.25.0 dev flake"; + description = "snitch - a friendlier ss/netstat for humans"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; @@ -10,82 +10,89 @@ let supportedSystems = import systems; forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); - in - { - overlays.default = final: prev: + + # go 1.25 overlay (required until nixpkgs has it) + goOverlay = final: prev: let version = "1.25.0"; - platformInfo = { "x86_64-linux" = { suffix = "linux-amd64"; sri = "sha256-KFKvDLIKExObNEiZLmm4aOUO0Pih5ZQO4d6eGaEjthM="; }; "aarch64-linux" = { suffix = "linux-arm64"; sri = "sha256-Bd511plKJ4NpmBXuVTvVqTJ9i3mZHeNuOLZoYngvVK4="; }; - "i686-linux" = { suffix = "linux-386"; sri = "sha256-jGAt2dmbyUU7OZXSDOS684LMUIVZAKDs5d6ZKd9KmTo="; }; - "armv6l-linux" = { suffix = "linux-armv6l"; sri = "sha256-paj4GY/PAOHkhbjs757gIHeL8ypAik6Iczcb/ORYzQk="; }; - "x86_64-darwin" = { suffix = "darwin-amd64"; sri = "sha256-W9YOgjA3BiwjB8cegRGAmGURZxTW9rQQWXz1B139gO8="; }; "aarch64-darwin" = { suffix = "darwin-arm64"; sri = "sha256-VEkyhEFW2Bcveij3fyrJwVojBGaYtiQ/YzsKCwDAdJw="; }; }; - hostSystem = prev.stdenv.hostPlatform.system; - - chosen = - if prev.lib.hasAttr hostSystem platformInfo then platformInfo.${hostSystem} - else - throw '' - unsupported system: ${hostSystem} - add a mapping for your platform using the upstream tarball + sri sha256 - ''; + chosen = platformInfo.${hostSystem} or (throw "unsupported system: ${hostSystem}"); in { - go_1_25_bin = prev.stdenvNoCC.mkDerivation { + go_1_25 = prev.stdenvNoCC.mkDerivation { pname = "go"; - version = version; - + inherit version; src = prev.fetchurl { url = "https://go.dev/dl/go${version}.${chosen.suffix}.tar.gz"; hash = chosen.sri; }; - dontBuild = true; - installPhase = '' runHook preInstall mkdir -p "$out"/{bin,share} tar -C "$TMPDIR" -xzf "$src" cp -a "$TMPDIR/go" "$out/share/go" - ln -s "$out/share/go/bin/go" "$out/bin/go" + ln -s "$out/share/go/bin/go" "$out/bin/go" ln -s "$out/share/go/bin/gofmt" "$out/bin/gofmt" runHook postInstall ''; - dontPatchELF = true; dontStrip = true; - - meta = with prev.lib; { - description = "go compiler and tools v${version}"; - homepage = "https://go.dev/dl/"; - license = licenses.bsd3; - platforms = [ hostSystem ]; - }; }; }; + in + { + overlays.default = final: prev: { + snitch = final.callPackage ./nix/package.nix { }; + }; packages = forAllSystems (system: - let pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; }; - in { - default = pkgs.go_1_25_bin; - go_1_25_bin = pkgs.go_1_25_bin; + let + pkgs = import nixpkgs { + inherit system; + overlays = [ goOverlay ]; + }; + in + { + default = pkgs.buildGoModule { + pname = "snitch"; + version = self.shortRev or self.dirtyShortRev or "dev"; + src = self; + vendorHash = "sha256-BNNbA72puV0QSLkAlgn/buJJt7mIlVkbTEBhTXOg8pY="; + env.CGO_ENABLED = 0; + ldflags = [ + "-s" "-w" + "-X snitch/cmd.version=${self.shortRev or "dev"}" + "-X snitch/cmd.commit=${self.shortRev or "unknown"}" + ]; + meta = with pkgs.lib; { + description = "a friendlier ss/netstat for humans"; + homepage = "https://github.com/karol-broda/snitch"; + license = licenses.mit; + platforms = platforms.linux; + mainProgram = "snitch"; + }; + }; } ); devShells = forAllSystems (system: - let pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; }; - in { + let + pkgs = import nixpkgs { + inherit system; + overlays = [ goOverlay ]; + }; + in + { default = pkgs.mkShell { - packages = [ pkgs.go_1_25_bin pkgs.git ]; - + packages = [ pkgs.go_1_25 pkgs.git ]; GOTOOLCHAIN = "local"; - shellHook = '' echo "go toolchain: $(go version)" '';