From e7b541ee491c3ab19475396cb55ba8e84fd97200 Mon Sep 17 00:00:00 2001 From: es-sai-fi Date: Thu, 26 Feb 2026 18:32:53 -0500 Subject: [PATCH] feat(nix): add devshell, package derivation, flake - Initialize development shell - Add package derivation - Add flake entrypoint - Add non-flake entrypoint - Document Nix installation and development setup in README --- README.md | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++ default.nix | 2 + flake.lock | 27 +++++++++++ flake.nix | 38 ++++++++++++++++ package.nix | 19 ++++++++ shell.nix | 32 +++++++++++++ 6 files changed, 246 insertions(+) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.nix create mode 100644 shell.nix diff --git a/README.md b/README.md index 3162829..8c6e34b 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,131 @@ cd gitv cargo install --path . ``` +#### NixOS + +
+ Flake + + First add the repository to your inputs. + + Point to main branch: + + ```nix + inputs = { + ... + gitv.url = "github:JayanAXHF/gitv"; + ... + }; + ``` + + Point to a rev in main branch: + + ```nix + inputs = { + ... + gitv.url = "github:JayanAXHF/gitv/d70273b05c5e80b05446e4aa0847758e54435d62"; + ... + }; + ``` + + Point to a tag: + + ```nix + inputs = { + ... + gitv.url = "github:JayanAXHF/gitv/refs/tags/gitv-tui-v0.3.2"; + ... + }; + ``` + + Then your outputs should look something like this: + + ```nix + outputs = {...} @ inputs: { + # Don't forget to add nixpkgs to your inputs + nixosConfigurations."nixos" = inputs.nixpkgs.lib.nixosSystem { + ... + specialArgs = {inherit inputs;}; + modules = [ + ./configuration.nix + ... + ]; + }; + }; + ``` + + And finally, somewhere in your `configuration.nix`: + + ```nix + {inputs, pkgs, ...}: { + ... + environment.systemPackages = [ + inputs.gitv.packages.${pkgs.stdenv.hostPlatform.system}.default + ]; + ... + } + ``` +
+ +
+ Non-Flake + + ##### Pinning Tool + + First add the pin using your pinning tool. + + We are going to show examples using npins. + + Point to a branch: + + ```bash + npins add github JayanAXHF gitv -b main + ``` + + Point to a rev in main branch: + + ```bash + npins add github JayanAXHF gitv -b main --at d70273b05c5e80b05446e4aa0847758e54435d62 + ``` + + Point to a tag: + + ```bash + npins add github JayanAXHF gitv --at gitv-tui-v0.3.2 + ``` + + Or point to latest release: + + ```bash + npins add github JayanAXHF gitv + ``` + + Then add the package to your `systemPackages`: + + ```nix + let + sources = import ./npins; + in { + environment.systemPackages = [ + (import sources.gitv) + ]; + } + ``` + + ##### No Pinning Tool + + ```nix + let + rev = "d70273b05c5e80b05446e4aa0847758e54435d62"; + gitv = import (fetchTarball "https://github.com/JayanAXHF/gitv/archive/${rev}.tar.gz") {}; + in { + environment.systemPackages = [ + gitv + ]; + } + ``` +
+ ### Usage ``` @@ -120,6 +245,9 @@ Contributions to `gitv` are welcome! If you have an idea for a new feature or ha > [!TIP] > Run the `init.py` initialization script to set up your development environment. It installs a pre-push hook that runs `typos` and `clippy` to help maintain code quality and consistency. Ensure that you have the `typos-cli` installed and available in your PATH for the pre-push hook to work correctly. You can install it using `cargo install typos-cli`. + [!TIP] +> If you're using nix then you can use the provided devshell to get your development environment up and running, it also includes the pre-push hook provided. You can do so by executing `direnv allow` or `nix develop`. + ### License `gitv` is dual-licensed under the MIT License and the Unlicense, at your option. See the [MIT](./LICENSE-MIT) and [Unlicense](./UNLICENSE) for more information. diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..09e5683 --- /dev/null +++ b/default.nix @@ -0,0 +1,2 @@ +{pkgs ? import {}}: +pkgs.callPackage ./package.nix {} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..82d8ab7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1771848320, + "narHash": "sha256-0MAd+0mun3K/Ns8JATeHT1sX28faLII5hVLq0L3BdZU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2fc6539b481e1d2569f25f8799236694180c0993", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6db00df --- /dev/null +++ b/flake.nix @@ -0,0 +1,38 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = {nixpkgs, ...}: let + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + forAllSystems = function: + nixpkgs.lib.genAttrs + supportedSystems + (system: function nixpkgs.legacyPackages.${system}); + in { + packages = forAllSystems ( + pkgs: let + default = pkgs.callPackage ./package.nix {}; + in { + inherit default; + + debug = default.overrideAttrs (finalAttrs: _: { + cargoBuildType = "debug"; + cargoCheckType = finalAttrs.cargoBuildType; + }); + } + ); + + devShells = forAllSystems ( + pkgs: { + default = import ./shell.nix {inherit pkgs;}; + } + ); + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..9f54358 --- /dev/null +++ b/package.nix @@ -0,0 +1,19 @@ +{ + lib, + rustPlatform, +}: +rustPlatform.buildRustPackage (finalAttrs: { + name = "gitv"; + + src = ./.; + cargoLock = { + lockFile = ./Cargo.lock; + allowBuiltinFetchGit = true; + }; + + meta = with lib; { + description = "Terminal-based viewer for GitHub issues"; + homepage = "https://github.com/JayanAXHF/gitv"; + license = with lib.licenses; [mit unlicense]; + }; +}) diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..cb6c88d --- /dev/null +++ b/shell.nix @@ -0,0 +1,32 @@ +{pkgs ? import {}}: +with pkgs; + mkShell { + packages = [ + nil + alejandra + + rustc + cargo + clippy + rustfmt + rust-analyzer + + typos + ]; + + env = { + RUST_BACKTRACE = "full"; + }; + + shellHook = '' + echo "Setting up pre-push hook..." + + HOOK=".git/hooks/pre-push" + + if [ ! -f "$HOOK" ]; then + cp ./etc/pre-push.sh "$HOOK" + chmod 755 "$HOOK" + echo "Pre-push hook installed." + fi + ''; + }