diff --git a/.gitignore b/.gitignore index a5d4586..3179840 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target +/result # Nix / devenv /.devenv/ diff --git a/README.org b/README.org index 1a06d27..4cc5012 100644 --- a/README.org +++ b/README.org @@ -8,6 +8,36 @@ This is a small tool that helps to list the files you have changed (added/modifi This can be useful when working with large repositories, as you can run tools on a specific subset of files instead of the entire repository. It can be easily integrated into your workflow to streamline your development process. +** Install with Nix + +This project is a Nix flake. It gives you the ~git-changed~ package, an overlay and an app. + +Run the tool without an installation: + +#+begin_src bash +$ nix run github:function-artisans/git-changed +#+end_src + +Add the flake to your own configuration: + +#+begin_src nix +{ + inputs.git-changed.url = "github:function-artisans/git-changed"; +} +#+end_src + +Then take the package for your system: + +#+begin_src nix +inputs.git-changed.packages.${system}.default +#+end_src + +Or add the overlay and take ~pkgs.git-changed~: + +#+begin_src nix +nixpkgs.overlays = [ inputs.git-changed.overlays.default ]; +#+end_src + ** Usage To get the recent changes comparing to the default branch you can type: diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..28a0c8b --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1794386569, + "narHash": "sha256-x9sADJvoVG0L6RejZB+/BB4YiGZFBZrfTlhF4uBq1tQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d4f25a3e562008648d45bcf2d70bcc7422cad84e", + "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..8832ac6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,41 @@ +{ + description = "Lists files modified since branching off"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = + { self, nixpkgs }: + let + systems = [ + "aarch64-darwin" + "aarch64-linux" + "x86_64-darwin" + "x86_64-linux" + ]; + + forEachSystem = nixpkgs.lib.genAttrs systems; + in + { + overlays.default = final: _prev: { + git-changed = final.callPackage ./package.nix { }; + }; + + packages = forEachSystem (system: { + git-changed = nixpkgs.legacyPackages.${system}.callPackage ./package.nix { }; + default = self.packages.${system}.git-changed; + }); + + apps = forEachSystem (system: rec { + git-changed = { + type = "app"; + program = nixpkgs.lib.getExe self.packages.${system}.git-changed; + meta.description = "List the files that changed since the branch point"; + }; + default = git-changed; + }); + + checks = forEachSystem (system: { + inherit (self.packages.${system}) git-changed; + }); + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..8f220a5 --- /dev/null +++ b/package.nix @@ -0,0 +1,38 @@ +{ + lib, + rustPlatform, + pkg-config, + libgit2, + git, +}: + +rustPlatform.buildRustPackage { + pname = "git-changed"; + version = "0.0.1"; + + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./Cargo.lock + ./Cargo.toml + ./src + ./tests + ]; + }; + + cargoLock.lockFile = ./Cargo.lock; + + # Link the libgit2 of nixpkgs. The git2 crate then builds no copy of its own. + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ libgit2 ]; + env.LIBGIT2_NO_VENDOR = 1; + + # The test scenarios create their repositories with the git command. + nativeCheckInputs = [ git ]; + + meta = { + description = "Lists files modified since branching off"; + homepage = "https://github.com/function-artisans/git-changed"; + mainProgram = "git-changed"; + }; +}