Setup home-manager with flake for nixos-unstable

I was of the opinion to setup home-manager with flake for nixos-unstable channel properly. But an attempt to use the option programs.git.prompt.enable from nixos-unstable shows that’s not the case.

$ home-manager build
...
       error: The option `programs.git.prompt' does not exist. Definition values:
       - In `/nix/store/x83iry17im4s7z3i3fdywgxh4yla5r32-source/home.nix':
           {
             enable = true;
           }

Any idea what went wrong and how it can be fixed?

Below my home-manager, flake and os configs

  • ~/.config/home-manager/flake.nix
{
..
  inputs = {
    # Specify the source of Home Manager and Nixpkgs.
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, home-manager, ... }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      homeConfigurations."me" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        modules = [ ./home.nix ];
      };
    };
}
  • ~/.config/home-manager/home.nix
{ config, pkgs, ... }:

{
  home.username = "me";
  home.homeDirectory = "/home/me";
  home.stateVersion = "23.11";
  home.packages = with pkgs; [...];
 
  programs.git = {
    enable = true;
    prompt.enable = true;
  }
}
$ nix-info --markdown
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.68, NixOS, 23.11 (Tapir), 23.11.2004.1e2e384c5b7c`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos-23.11"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

That’s a NixOS option, not a home manager option. See here for HM options: Appendix A. Home Manager Configuration Options

2 Likes

Oh, I see. Thank you. Does that mean there is no way to use a NixOS option with home-manager?

1 Like

Are you only using home-manager, and seeking to avoid NixOS options? If so, then you could add the appropriate sourcing to programs.bash.initExtra in home-manager. Something like:

  programs.bash.initExtra = ". ${pkgs.git}/share/bash-completion/completions/git-prompt.sh";
3 Likes

No. NixOS options require full root system access, and need the underlying system to be NixOS (because it relies on symlinking stuff into various places on boot). You can’t use NixOS options without NixOS.

You can use this configuration to get the same result instead:

programs.bash.initExtra = ''
  source ${config.programs.git.package}/share/bash-completion/completions/git-prompt.sh
'';

Obviously apply different options if you’re using a different shell. This requires that you use also home-manager to configure bash.

Edit: d’oh, I skimmed past @bowmanjd x)

3 Likes

programs.bash.initExtra based approach works, if programs.bash.enable is true. Thank you, all.

programs.bash.enable = true;
programs.bash.initExtra = ''
    GIT_PS1_SHOWCOLORHINTS=true
    source ${config.programs.git.package}/share/bash-completion/completions/git-prompt.sh
    export PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
'';
1 Like