gabyx / Githooks

🦎 Githooks: per-repo and shared Git hooks with version control and auto update. [✩Star] if you're using it!
MIT License
100 stars 4 forks source link

Better explanation on how to use Nix #169

Open giggio opened 2 months ago

giggio commented 2 months ago

Hey @gabyx! I have been trying version 3.0.1 using the Nix home-manager. I am kind of new to it, but I was able to install it using nix. But now I'm left with the githooks binaries, and when I try to use them they fail.

If I try to githooks-cli install, it fails with:

β›” Could not install run-wrapper link into '/home/user/.dotfiles/.git'.
   -> errors:
   Githooks has not been installed.
   The Git config variable 'githooks.pathForUseCoreHooksPath' does not exist or is empty.
β›” Fatal error -> Abort.

If I try to install with githooks-cli installer --dry-run, it fails with:

🦎 Githooks Installer [version: 3.0.1+nix.0d8d4ea97a014a14508469640b8e1e69815b667a]
🦎 Started at: 2024-05-01 02:37:20.28265989 -0300 -03 m=+0.003513434
🦎 Log file: '/tmp/githooks-installer-1342686508.log'
🦎 Running dispatched installer.
🦎 Fetching Githooks clone...
β›” Could not assert release clone '/tmp/githooks-installer-933885741/release' existing
   -> errors:
   βœ—  Current version tag 'v3.0.1+nix.0d8d4ea97a014a14508469640b8e1e69815b667a' could not be found on branch 'main'
β›” Fatal error -> Abort.

So I need to know, what are the next steps after using Nix?

Here is my flakes.nix config:

{
  description = "Home Manager configuration of giggio";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    githooks = {
      url = "github:gabyx/githooks?dir=nix&ref=v3.0.1";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, home-manager, ... }@inputs:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      homeConfigurations."giggio" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;

        modules = [ ./home.nix ];

        extraSpecialArgs = {
          inherit inputs;
        };
      };
    };
}

home.nix is using it just like you mentioned in the readme.

gabyx commented 2 months ago

@giggio : this looks all good, the only thing is: You still need to do githooks-cli installer since the Nix does not install any setup on your machine by default, it only puts the binaries of Githooks in your PATH, thats it.

So, having said that, you need to install one mode of Githooks somewhere. githooks installer .... Note: Its a package manager install, updates are disabled, checking for updates still works.

You are right: the installer had some troubles because I did some stupid versioning: Can you pin it to the current main SHA its version 3.0.1. then it should work. I am using it as well at the moment.

gabyx commented 2 months ago

https://github.com/gabyx/dotfiles/blob/main/flake.nix#L56C4-L61C1

gabyx commented 2 months ago

Maybe you can make a PR to explain better the steps in the README under Nix install...

giggio commented 2 months ago

You could make a 3.0.2 release. Sticking it to main is not a good idea.

gabyx commented 2 months ago

Thats true, but no code has changed though, I will try to do this anyway.

giggio commented 2 months ago

Yes, it is good that you did. When I ran home-manager switch with master it did not update the reference. Only when I changed it to v3.0.2 it updated.

gabyx commented 4 weeks ago

@ Feel free to reopen it.