Git-credential-manager on NixOS

How do I set up git-credential-manager on NixOS? So far I have tried setting it up via Home Manager, but that did not give me any results. I do see this PR on the nixpkgs repo that should fix my problem. Is there any other way I can set it up so I can log into my GitHub account?

1 Like

Wdym “doesn’t give any results”?

As you linked an unmerged PR that adds the software to nixpkgs, I assume that you can’t install it, because it’s simply not available.

If you tried anything that’s different from writing a random pkgs.git-credential-manager anywhere, then please tell us.

It attempted to login using password authentication which has apparently been removed since august of 2021

I tried adding programs.git.extrConfig.credential.helper = "${pkgs.gitAndTools.gitFull}/bin/git-credential-libsecret";

Hello, original author of the PR you linked here. You can, in fact, install GCM through my NUR (where I’ve already added the package as the PR got lost in the thousands of open PRs on nixpkgs). NURs are basically alternative repositories by individual users, and often have more obscure or customized packages. It’s listed here, and you can see instructions for using NURs here.

The package would then be nur.repos.utybo.git-credential-manager. You can then follow the instructions in the PR for using it with Home Manager, but with the correct package, i.e.:

programs.git = {
  enable = true;
  # ...
  extraConfig = {
    credential = {
      credentialStore = "secretservice";
      helper = "${nur.repos.utybo.git-credential-manager}/bin/git-credential-manager-core";
    };
  };
};
1 Like

oooh thanks! Ill try this in a bit

Not removed, the package just moved to top-level (pkgs.gitFull). And the NixOS option was renamed. I would expect something like the following to work today:

programs.git = {
  enable = true;
  package = pkgs.gitFull;
  config.credential.helper = "libsecret";
};
2 Likes

I had success with:

  home.packages = with pkgs; [
    git
    git-credential-manager
];

  programs.git = {
    extraConfig.credential.helper = "manager";
    extraConfig.credential."https://github.com".username = "YourUserName";
    extraConfig.credential.credentialStore = "cache";
    enable = true;
  };

which will output this in your /home/nixos/.config/git/config

[credential]
	credentialStore = "cache"
	helper = "manager"

[credential "https://github.com"]
	username = "YourUserName"

I don’t exactly know why it works, specially the credential.helper=“manager”. …

2 Likes
  programs = {
    git = {
      extraConfig.credential.helper = "manager";
      extraConfig.credential."https://github.com".username = "YourUserName";
      extraConfig.credential.credentialStore = "cache";
      enable = true;
    };

       error: The option `programs.git.extraConfig' does not exist. Definition values:

Does not work…

It does:

https://nix-community.github.io/home-manager/options.xhtml#opt-programs.git.extraConfig

Unless you are not using HM, in which case you have to tell us what you use.

Hello, thanks.

I’m just using configuration.nix, no home-manager, no flakes.

Then it should be rather obvious, that you can not use the proposed HM configuration, and instead have to use some equivalent NixOS option.

So programs.git.config seems to be relevant here. And as I personally am quite strict against configuring git at the system level, I can not say, whether what I propose now, is a correct and working NixOS equivalent of the HM-code above:

programs.git.config.credential = {
  helper = "manager";
  "https://github.com".username = "YourUserName";
  credentialStore = "cache";
}

Thanks.

  1. Do I need to install git-credential-manager packge?
  2. Will this make so that by default a password for a repo is asked only once and then it’ll be saved?
    Thanks

I have no clue, I just translated the HM snippet to NixOS options, and am not even sure if it would be done that way.

I have no clue. I do not use credential managers, I use SSH keys and SSH remotes, they are much easier to use in my experience…

1 Like