Last active
May 21, 2026 10:18
-
-
Save bobymicroby/1e67e728621e094004967b237c02e53d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Redis from source, hermetically built via Nix. | |
| # | |
| # Requires: Nix with `experimental-features = nix-command flakes`. | |
| # | |
| # ── Run from a local clone ───────────────────────────────────────────── | |
| # nix build . # build → ./result/bin/redis-server | |
| # nix run . # start redis-server (forwards flags) | |
| # nix run . -- --port 7000 # e.g. on a custom port | |
| # nix run .#redis-cli -- -p 6379 ping # other binaries as apps | |
| # nix develop # shell with the build toolchain | |
| # | |
| # Pick a different upstream revision (commit, branch, or tag): | |
| # nix build . --override-input redis-src github:redis/redis/<sha-or-ref> | |
| # nix run . --override-input redis-src github:redis/redis/8.0.0 | |
| # | |
| # ── Run straight from this gist (no clone) ───────────────────────────── | |
| # The gist is read-only, so always pass `--no-write-lock-file`. | |
| # | |
| # GIST=git+https://gist.github.com/bobymicroby/1e67e728621e094004967b237c02e53d | |
| # | |
| # # Build: | |
| # nix build "$GIST" --no-write-lock-file | |
| # | |
| # # Start redis-server (forwards flags after `--`): | |
| # nix run "$GIST" --no-write-lock-file | |
| # nix run "$GIST" --no-write-lock-file -- --port 7000 | |
| # | |
| # # Run redis-cli from the same build: | |
| # nix run "$GIST#redis-cli" --no-write-lock-file -- -p 6379 ping | |
| # | |
| # # Pick a different upstream redis revision (commit, branch, or tag): | |
| # nix run "$GIST" --no-write-lock-file \ | |
| # --override-input redis-src github:redis/redis/8.0.0 | |
| # nix run "$GIST" --no-write-lock-file \ | |
| # --override-input redis-src github:redis/redis/<sha> | |
| # | |
| # # Pin to a specific gist revision (gists move; this freezes the flake): | |
| # nix run "$GIST?rev=<gist-sha>" --no-write-lock-file | |
| { | |
| description = "Redis built from upstream source"; | |
| inputs = { | |
| nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | |
| flake-utils.url = "github:numtide/flake-utils"; | |
| # Default redis source. Override at build time to pick a different | |
| # commit/branch/tag: | |
| # nix build . --override-input redis-src github:redis/redis/<sha-or-ref> | |
| redis-src = { | |
| url = "github:redis/redis/unstable"; | |
| flake = false; | |
| }; | |
| }; | |
| outputs = { self, nixpkgs, flake-utils, redis-src }: | |
| flake-utils.lib.eachDefaultSystem (system: | |
| let | |
| pkgs = import nixpkgs { | |
| inherit system; | |
| config.allowUnfreePredicate = pkg: | |
| (pkgs.lib.getName pkg) == "redis"; | |
| }; | |
| revShort = | |
| if redis-src ? rev then builtins.substring 0 7 redis-src.rev | |
| else "dirty"; | |
| redis = pkgs.stdenv.mkDerivation { | |
| pname = "redis"; | |
| version = "unstable-${revShort}"; | |
| src = redis-src; | |
| nativeBuildInputs = [ pkgs.pkg-config ]; | |
| buildInputs = [ pkgs.openssl ]; | |
| enableParallelBuilding = true; | |
| dontConfigure = true; | |
| buildPhase = '' | |
| runHook preBuild | |
| make -C src -j$NIX_BUILD_CORES BUILD_TLS=yes \ | |
| redis-server redis-sentinel redis-cli redis-benchmark \ | |
| redis-check-rdb redis-check-aof | |
| runHook postBuild | |
| ''; | |
| installPhase = '' | |
| runHook preInstall | |
| mkdir -p $out/bin | |
| cp src/redis-server src/redis-cli src/redis-benchmark $out/bin/ | |
| ln -sf redis-server $out/bin/redis-sentinel | |
| ln -sf redis-server $out/bin/redis-check-rdb | |
| ln -sf redis-server $out/bin/redis-check-aof | |
| runHook postInstall | |
| ''; | |
| passthru.serverBin = "redis-server"; | |
| meta = with pkgs.lib; { | |
| description = "In-memory data store"; | |
| homepage = "https://redis.io"; | |
| license = with licenses; [ sspl agpl3Only ]; | |
| platforms = platforms.unix; | |
| mainProgram = "redis-server"; | |
| }; | |
| }; | |
| startScript = pkgs.writeShellApplication { | |
| name = "redis-start"; | |
| runtimeInputs = [ redis ]; | |
| text = '' | |
| exec redis-server "$@" | |
| ''; | |
| }; | |
| in { | |
| packages = { | |
| default = redis; | |
| redis = redis; | |
| }; | |
| apps = { | |
| default = { | |
| type = "app"; | |
| program = "${startScript}/bin/redis-start"; | |
| }; | |
| redis-server = { | |
| type = "app"; | |
| program = "${redis}/bin/redis-server"; | |
| }; | |
| redis-cli = { | |
| type = "app"; | |
| program = "${redis}/bin/redis-cli"; | |
| }; | |
| }; | |
| devShells.default = pkgs.mkShell { | |
| inputsFrom = [ redis ]; | |
| packages = [ pkgs.python3 ]; | |
| }; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment