Home manager doesn't generate git config

Hi,

While trying to use home manager for managing git config I encountered an issue, where rebuild does not generate ~/.config/git/config file.

I have home manager installed as a module through flake.

I was following Home Manager - NixOS Wiki by putting this snippet in home.nix:

 programs.git = {
    enable = true;
    userName  = "my_git_username";
    userEmail = "my_git_username@gmail.com";
  };

Using similar code for my neovim config does work properly.

After some additional testing I noticed that neither setting enable = false nor removing whole snippet does remove git from the system. Git is not declared anywhere else in .nix files and I did not install it through nix-env. Before using home manager I had it in environment.systemPackages in configuration.nix, but later removed it. Having it back in does not change anything.

Some commands that I did try:

[user@host:~]$ nix-env --uninstall git
warning: selector 'git' matched no installed derivations

[user@host:~]$ which git
/home/user/.nix-profile/bin/git

[user@host:~]$ which git | xargs realpath
/nix/store/q1zaii9cirbfpmwr7d86hpppql3kjcpf-git-2.51.0/bin/git

I’m pretty new to NixOS and still learning the Nix way of doing things, so I will appreciate any hints what might be wrong.

Alright obviously I am just a newbie but there is an interesting fact for me is that .nix-profile is a broken symbolic link in my laptop. This piqued my curiosity, so I did a little research, and now I’m here to tell you what I think.

Firstly, after a bit of searching, I got this manual page. So I guess your git may be installed by something like this:

nix-env -iA nixpkgs.<package> # old
nix profile install nixpkgs#<package> # new

But now that you’re mentioning below, I’m not quite sure what’s going on.

Nevertheless, maybe you can still try these command to find packages in your profile:

nix-env --query --installed
nix profile list

And according to your thread maybe try below to remove git from your profile. You can do it twice, once as a normal user and once as root. Not guaranteed to work. :wink:

nix-env --uninstall <git-with-version-number>
nix profile remove /nix/store/q1zaii9cirbfpmwr7d86hpppql3kjcpf-git-2.51.0/bin/git

For <git-with-version-number>, maybe you will get it from the output of nix-env --query --installed.

After this, maybe the mysterious git will be uninstalled (or not :sob:). And for your main problem, I just recommend that paste your repo address so that people can check your code.

EDIT: here is my knowledge resource (Sounds like a bit AI but I am really not :wink: ).

2 Likes

Thank you very much for your tips!

The underlying problem has been me mixing two types of using home manager - due to my lack of understanding I was using syntax for standalone version, while at the same time my home manager was installed as a module. Of course sharing repo with the config would let you spot that right away, but I didn’t have it in the repo due to issues with git - I couldn’t create a commit without email and name set and couldn’t set them due to config not working :sweat_smile: Everything was working fine before I tried to modularise while not fully understanding what I was doing, thus not properly sourcing some files.

As a summary I used a flake.nix (shortened version with only lines regarding home manager):

{
  inputs = {

...

    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };

...

  };

  outputs = {
    self,
    nixpkgs,
    home-manager,
    ...
  } @ inputs: let
    inherit (self) outputs;

    system = "x86_64-linux";
    pkgs = import nixpkgs {
      inherit system;
    };
  in {

...

     homeConfigurations = {
       "user@host" = home-manager.lib.homeManagerConfiguration {
         pkgs = nixpkgs.legacyPackages.x86_64-linux;
         extraSpecialArgs = {inherit inputs outputs;};
         modules = [
           ./hosts/host/home.nix
         ];
       };
     };

    homeManagerModules = import ./homeManagerModules;
    
...

  };
}

Instead of adding this to my configuration.nix:

{
  config,
  pkgs,
  inputs,
  outputs,
  ...
}: {
  imports = [
    ./hardware-configuration.nix
    inputs.home-manager.nixosModules.home-manager
  ];

  home-manager = {
    extraSpecialArgs = { inherit inputs outputs; };
    users.user = import ./home.nix;
  };

...

}

Hopefully this will help somebody in the future in case they would get lost in this big new world the same way I did.