diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c3ae487 --- /dev/null +++ b/flake.lock @@ -0,0 +1,62 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1746397377, + "narHash": "sha256-5oLdRa3vWSRbuqPIFFmQBGGUqaYZBxX+GGtN9f/n4lU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ed30f8aba41605e3ab46421e3dcb4510ec560ff8", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "main", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7e310df --- /dev/null +++ b/flake.nix @@ -0,0 +1,44 @@ +{ + inputs = { + utils.url = "github:numtide/flake-utils/main"; + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + }; + + outputs = { self, nixpkgs, utils }: + utils.lib.eachDefaultSystem(system: + let + pkgs = import nixpkgs { inherit system; }; + cache = import ./nix/cache.nix { inherit pkgs; }; + in { + devshells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ zig zls ]; + }; + + packages.default = pkgs.stdenv.mkDerivation { + pname = "lsr"; + version = "0.1.0"; + doCheck = false; + src = ./.; + + nativeBuildInputs = with pkgs; [ zig ]; + + buildPhase = '' + export ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) + ln -sf ${cache} $ZIG_GLOBAL_CACHE_DIR/p + zig build -Doptimize=ReleaseFast --summary all + ''; + + installPhase = '' + install -Ds -m755 zig-out/bin/lsr $out/bin/lsr + ''; + + meta = with pkgs.lib; { + description = "ls(1) but with io_uring"; + homepage = "https://tangled.sh/@rockorager.dev/lsr"; + maintainers = with maintainers; [ rockorager ]; + platforms = platforms.linux; + license = licenses.mit; + }; + }; + }); +} diff --git a/nix/cache.nix b/nix/cache.nix new file mode 100644 index 0000000..d59f195 --- /dev/null +++ b/nix/cache.nix @@ -0,0 +1,23 @@ +{ pkgs, ... }: + +pkgs.stdenv.mkDerivation { + pname = "lsr-cache"; + version = "0.1.0"; + doCheck = false; + src = ../.; + + nativeBuildInputs = with pkgs; [ zig ]; + + buildPhase = '' + export ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) + zig build --fetch --summary none + ''; + + installPhase = '' + mv $ZIG_GLOBAL_CACHE_DIR/p $out + ''; + + outputHash = "sha256-hAq1/uE9eu/82+e079y+v9EnN0ViXX7k3GwkgQkxOyo="; + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; +}