diff --git a/README.md b/README.md index dd9fad1..3cab47f 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,20 @@ Use an [AUR helper](https://wiki.archlinux.org/title/AUR_helpers), such as `yay` yay -S leaf-markdown-viewer ``` +Nix: + +Run without installing: + +```bash +nix run github:RivoLink/leaf +``` + +Install into your profile: + +```bash +nix profile install github:RivoLink/leaf +``` + Verify the installation: ```bash @@ -95,6 +109,28 @@ If `~/.local/bin` is not already on your `PATH`, add it to `~/.bashrc` or `~/.zs export PATH="$HOME/.local/bin:$PATH" ``` +### Nix + +Build with Nix (no Rust toolchain required on the host): + +```bash +nix build +./result/bin/leaf --version +``` + +Enter the development shell — it provides the Rust toolchain, `pkg-config`, `oniguruma`, `cargo-watch`, and `cargo-edit`: + +```bash +nix develop +cargo build --release +``` + +Run the full check suite (build + clippy + rustfmt): + +```bash +nix flake check +``` + ## Usage ```bash diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..35fb00d --- /dev/null +++ b/flake.lock @@ -0,0 +1,77 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1778106249, + "narHash": "sha256-cM/AuKy5tMhwOOQIbha8ZRRMHVfNf7cv2aljIw+qoCg=", + "owner": "ipetkov", + "repo": "crane", + "rev": "6d015ea29630b7ad2402841386da2cb617a470a7", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1778274207, + "narHash": "sha256-I4puXmX1iovcCHZlRmztO3vW0mAbbRvq4F8wgIMQ1MM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b3da656039dc7a6240f27b2ef8cc6a3ef3bccae7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6c95af3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,79 @@ +{ + description = "leaf - A friendly terminal Markdown previewer"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + crane.url = "github:ipetkov/crane"; + }; + + outputs = { self, nixpkgs, flake-utils, crane }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + + craneLib = crane.mkLib pkgs; + + nativeBuildInputs = with pkgs; [ pkg-config ]; + + # syntect's regex-onig feature requires the oniguruma C library. + # reqwest uses rustls-tls (pure-Rust TLS) so no Security/SystemConfiguration + # frameworks are needed. crossterm uses POSIX terminal APIs covered by the + # stdenv SDK, so no explicit darwin framework inputs are required. + buildInputs = with pkgs; [ oniguruma ]; + + commonArgs = { + src = craneLib.cleanCargoSource ./.; + strictDeps = true; + inherit nativeBuildInputs buildInputs; + # Tell the oniguruma-sys build script to link the system library. + RUSTONIG_SYSTEM_LIBONIG = true; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + leaf = craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; + meta = with pkgs.lib; { + description = "A friendly terminal Markdown previewer"; + homepage = "https://github.com/RivoLink/leaf"; + license = licenses.mit; + mainProgram = "leaf"; + platforms = platforms.unix; + }; + }); + in + { + packages = { + default = leaf; + inherit leaf; + }; + + apps.default = flake-utils.lib.mkApp { drv = leaf; }; + + checks = { + inherit leaf; + + leaf-clippy = craneLib.cargoClippy (commonArgs // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + leaf-fmt = craneLib.cargoFmt { + src = commonArgs.src; + }; + }; + + devShells.default = craneLib.devShell { + checks = self.checks.${system}; + packages = with pkgs; [ + clippy + rustfmt + cargo-edit + cargo-watch + ]; + RUSTONIG_SYSTEM_LIBONIG = true; + }; + } + ); +}