Authenticate glab CLI on Nix

Hi everyone!

I’m trying to authenticate my glab CLI with nix by running the command glab auth login. I can easily go through most steps but I’ve got an issue with my git config file. When gitlab asks “Authenticate Git with your GitLab credentials?” and I answered it “Yes” the CLI exits with the following error.

Could not sign in! error=error: could not lock config file /home/wavesinaroom/.config/git/config: Read-only file system
git: exit status 255

I’m aware that I have control over git config file with my home.nix file but since I’m a Nixos beginner I honestly don’t know how to set glab with Nix. If I don’t authenticate git with my gitlab credentials I’m not able to push, pull etc etc.

Can anyone point out what I’m missing doing wrong here please?

You aren’t doing anything wrong per se. You presumably configured your git config with home-manager, and now it’s read-only. glabwants to modify it. All you do is add the modification it wants to make to your git config and move on :slight_smile: Assuming you are on 25.11 + home-manager:

programs.git.settings.credential."https://gitlab.com".helper = "!${lib.getExe pkgs.glab} auth git-credential";

will do the trick. This will of course guarantee that glab is installed, and up to date.

2 Likes

Hi!

Thanks for taking time to read my question. I upgraded nixos and pkgs to their latest version (25.11). I also added your line to my home.nix file (yes, I’m using home manager). But I got the following error:

The option programs.git.settings does not exist

Could you walk me through the solution a bit further please?

It used to be programs.git.extraConfig for home-manager 25.05 and older. You’ve probably forgotten to upgrade home-manager.

Are you using home-manager standalone? If you used the NixOS module it should warn you and disallow switching your configuration without moving it to the same major release. I really recommend using the NixOS module if you use NixOS, rather than installing home-manager standalone.