Skip to content
Draft
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
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
77 changes: 77 additions & 0 deletions flake.lock

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

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