From a0c4ad465513905c1d2a89f620162c376d05f686 Mon Sep 17 00:00:00 2001 From: Simon Chatterjee Date: Thu, 10 Feb 2022 15:52:24 +0000 Subject: [PATCH] Add nix flake This enables users who use the Nix package manager (see https://nixos.org/explore.html) to easily try out jless, and include it in a machine or user environment. --- flake.lock | 41 +++++++++++++++++++++++++++++++++++++++ flake.nix | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ac87952 --- /dev/null +++ b/flake.lock @@ -0,0 +1,41 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1643119265, + "narHash": "sha256-mmDEctIkHSWcC/HRpeaw6QOe+DbNOSzc0wsXAHOZWwo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b05d2077ebe219f6a47825767f8bab5c6211d200", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..da0f53b --- /dev/null +++ b/flake.nix @@ -0,0 +1,56 @@ +# Nix flake for jless. This means that where Nix is installed (see +# https://nixos.org/explore.html), jless can be run immediately via +# +# nix run github:PaulJuliusMartinez/jless +# +# or with arguments like this: +# +# nix run github:PaulJuliusMartinez/jless -- --help +# +# and is easy to include in a machine or user environment via the overlay. +{ + description = "A command-line pager for JSON data"; + + inputs.utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, utils }: + let + # Get metadata from Cargo.toml + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + name = cargoToml.package.name; + + # How to build + build = { rustPlatform }: rustPlatform.buildRustPackage + { + pname = name; + version = cargoToml.package.version; + src = ./.; + cargoLock = { lockFile = ./Cargo.lock; }; + doCheck = true; + }; + + # Create overlay that includes this package + overlay = final: prev: { + ${name} = final.callPackage build { }; + }; + overlays = [ overlay ]; + in + + # Finally, define the flake outputs + { inherit overlay overlays; } // + (utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system overlays; }; + in + rec { + # nix build + packages.${name} = pkgs.${name}; + defaultPackage = packages.${name}; + + # nix develop + devShell = pkgs.mkShell { + inputsFrom = [ defaultPackage ]; + buildInputs = with pkgs; [ rustc rust-analyzer clippy rustfmt ]; + }; + })); +}