Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nix flake #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 ];
};
}));
}