diff --git a/README.md b/README.md index 5d66a2fd..23426623 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,44 @@ cargo install --force --locked --git https://seed.radicle.xyz/z39mP9rQAaGmERfUMP This will install `rad-tui`. All available commands can be shown by running `rad-tui --help`. +#### Nix + +There is a `flake.nix` present in the repository. This means that for +development, it should be as simple as using [`direnv`](https://direnv.net/) and +having the following `.envrc` file: + +``` +# .envrc +use flake +``` + +For using the binary in a NixOS, in your `flake.nix` you can add one of the +following to the `inputs` set: + +```nix +inputs = { + # Replace with the specific tag to build + radicle-tui = { + url = "git+https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git?tag="; + } +} +``` + +```nix +inputs = { + # Replace with the specific commit to build + rad-tui = { + url = "git+https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git?rev="; + } +} +``` + +Then in your `home.nix` you can add: + +``` +home.packages.inputs.radicle-tui.packages.{system}.default +``` + ### Usage Soon, `rad-tui` will be integrated into [`heartwood`](https://app.radicle.xyz/nodes/seed.radicle.xyz/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5). Until then, you can use the `rad` proxy script that is provided. It's considered to be a drop-in replacement for `rad` and can be used for testing and prototyping purposes. It should reflect the current behavior, as if `rad-tui` would have been integrated, e.g. diff --git a/deny.toml b/deny.toml new file mode 100644 index 00000000..42853dbc --- /dev/null +++ b/deny.toml @@ -0,0 +1,7 @@ +[licenses] +allow = [ + "MIT", + "Apache-2.0", + "Unicode-DFS-2016", + "BSD-3-Clause" +] diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..7738a688 --- /dev/null +++ b/flake.lock @@ -0,0 +1,120 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1718755832, + "narHash": "sha256-bSY6HPtJ9vCp0AGjL5X910aTg0mq32p3BcJmZQkNkMs=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "8eb99abe8c369b48bbd4ca04133e1f05be22a778", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1718730147, + "narHash": "sha256-QmD6B6FYpuoCqu6ZuPJH896ItNquDkn0ulQlOn4ykN8=", + "owner": "ipetkov", + "repo": "crane", + "rev": "32c21c29b034d0a93fdb2379d6fabc40fc3d0e6c", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1718955215, + "narHash": "sha256-3vNXv4zrblZFobrxz1P3RwLpHl6X3/GzfArdTxq0+nI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "201ed88e66f7f34d5c74e46d2e4399cc4bea1501", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "advisory-db": "advisory-db", + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1718936281, + "narHash": "sha256-jslEDCVFoRcNilJT0xYGSxqMjOe+USnLknpHIAZJ02A=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "c9a793a5278f711a59fe77b9bf54b215667022c6", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "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 00000000..11593e5d --- /dev/null +++ b/flake.nix @@ -0,0 +1,126 @@ +{ + description = "A TUI for the Radicle code forge"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/release-24.05"; + + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + flake-utils.url = "github:numtide/flake-utils"; + + advisory-db = { + url = "github:rustsec/advisory-db"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, crane, flake-utils, advisory-db, rust-overlay, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + lib = nixpkgs.lib; + pkgs = import nixpkgs { + inherit system; + overlays = [(import rust-overlay)]; + }; + + rustToolChain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain; + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolChain; + + src = craneLib.cleanCargoSource ./.; + + # Common arguments can be set here to avoid repeating them later + commonArgs = { + inherit src; + strictDeps = true; + + buildInputs = [ + # Add additional build inputs here + ] ++ lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv + ]; + }; + + # Build *just* the cargo dependencies, so we can reuse + # all of that work (e.g. via cachix) when running in CI + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + # Build the actual crate itself, reusing the dependency + # artifacts from above. + radicle-tui = craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; + doCheck = false; + }); + in + { + checks = { + # Build the crate as part of `nix flake check` for convenience + inherit radicle-tui; + + # Run clippy (and deny all warnings) on the crate source, + # again, reusing the dependency artifacts from above. + # + # Note that this is done as a separate derivation so that + # we can block the CI if there are issues here, but not + # prevent downstream consumers from building our crate by itself. + clippy = craneLib.cargoClippy (commonArgs // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + doc = craneLib.cargoDoc (commonArgs // { + inherit cargoArtifacts; + }); + + # Check formatting + fmt = craneLib.cargoFmt { + inherit src; + }; + + # TODO: re-enable to fix 4 vulnerabilities + # Audit dependencies + # audit = craneLib.cargoAudit { + # inherit src advisory-db; + # }; + + # Audit licenses + deny = craneLib.cargoDeny { + inherit src; + }; + + # Run tests with cargo-nextest + nextest = craneLib.cargoNextest (commonArgs // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + }); + }; + + packages = { + inherit radicle-tui; + default = radicle-tui; + }; + + apps.default = flake-utils.lib.mkApp { + name = "rad-tui"; + drv = self.packages.${system}.radicle-tui; + }; + + devShells.default = craneLib.devShell { + packages = [ + pkgs.cargo-watch + pkgs.cargo-nextest + pkgs.ripgrep + pkgs.rust-analyzer + ]; + }; + }); +} diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 00000000..3245dca3 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +1.77