New to NixOS, I’m getting started on setting up a home server machine, trying to get to the “base camp” level where I have a basic working config linked to a Git repo (GitLab) so i have a means to track changes and rollback the inevitable errors I will make.
I decided to use just basic nix plus home-manager initially, without involving flakes, because Nix+home-manager+flakes is more than my poor brain can absorb in one go. I also went for the “module based” approach to home manager, so all the config is currently in configuration.nix.
The issue: The configuration I have so far is NOT correctly setting the key Git environment variables (userName, userEmail, defaultBranch) so I can’t get the link to GitLab working.
configuration.nix (relevant parts, redacted)
config, pkgs, ... }:
{
imports =
[
./hardware-configuration.nix
<home-manager/nixos>
];
...
# User accounts
users.users.me = {
isNormalUser = true;
description = "Me";
extraGroups = [ "networkmanager" "wheel" ];
shell = pkgs.zsh;
};
# Home-manager config
home-manager.useUserPackages = true; # Packages install to /etc/profiles
home-manager.useGlobalPkgs = true; # Use global package definitions
# Configure user accounts with home-manager
home-manager.users.me = { pkgs, ... }: {
home.stateVersion = "24.05"; # Required, static
home.packages = with pkgs; [
vscode-fhs # Allows extensions to be added directly via the code UI
];
programs.git = {
enable = true;
userName = "GitLab Username";
userEmail = "GitLab Email";
extraConfig = {
init.defaultBranch = "main";
};
};
};
# Allow unfree packages
nixpkgs.config.allowUnfree = true;
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs; [
git
wget
curl
home-manager
zsh
keepassxc
firefox
thunderbird
];
# Enable the OpenSSH daemon.
services.openssh.enable = true;
# State version
system.stateVersion = "24.05"; # Required, static
}
This (in original unredacted form) builds ok, but if I open a new shell the git environment settings have not taken effect-
So, i’m left scratching my head on this. Maybe the home-manager module options have changed, leaving the video and the documentation out of date, but if so (and given there are no error messages) i’m not clear how i’m supposed to debug this.
me@Hilly:~/.config/ > ls -l ~/.config/git
ls: cannot access '/home/me/.config/git': No such file or directory
home-manager is doing something because the home.pkgs clause does succeed in making vscode available, but the programs.git section seems to be ineffective.
In the current configuration on my machine git is set up as a system package within environment.systemPackages and at the user profile level with
programs.git = {
enable = true;
...
};
as shown in the first example.
I originally thought this was redundant. However I have since found that having a package in environment.systemPackages is not always the same thing as having that package “enabled”. Thunderbird for example works fine just by being declared in systemPackages, but zsh generates warning unless it is also “enabled”. Hopefully at some point this will make more sense.
Yes I missed the enable = true; line out in the second example, while experimenting with @firecat53 's suggestion. I reverted back to the original setup and it does generate a config file, which looks like-
which looks plausible. More importantly git config now shows the results of the nix-side configuration!
I’m very confused as to why it’s behaving differently, I THOUGHT I had reverted back to exactly the same syntax I had originally, and I did start a new terminal+shell for each test to pick up environment changes. This is exactly why i’m trying to get Git set up of course!
So, it seems i’m making progress, even if I don’t understand quite how.