Problems with Home Manager

Hi! I’m new to NixOS, I was tying to install Home Manager by adding channel and editing

environment.SystemPackages = with pkgs; [ home-manger];

Everything work at first, I made mistake with channels somewhere, and now
nix-channel --list
outputs this: home-manager https://github.com/nix-community/home-manager/archive/release-23.11.tar.gz
But shell aliases which i wrote in home.nix don’t work

Can you please, at least, share that home.nix ?

path: ~/.config/nixpkgs/home.nix

{ config, pkgs, ... }: {
   home = {
      username = "user";
      homeDirectory = "/home/user";
      stateVersion = "23.11";
   };

   programs.bash = {
      shellAliases = {
         edit-conf = "sudo nano /etc/nixos/configuration.nix";
         nix-rebuild = "sudo nixos-rebuild switch";
         nix-upg = "sudo nix-channel --update && nixos-rebuild switch --upgrade";
      };
   };
}

In order for the home.nix to have any effect when using home-manager standalone, you need to run home-manager switch. – It’s similar to nixos-rebuild, where with nixos-rebuild you edit the config, and the changes only apply after running nixos-rebuild switch.

c.f. the Using Home Manager section of the manual

I am aware of this, I have tried to enter this command several times, but it does not help

Perhaps add an enable = true; under programs.bash in order to enable the programs.bash.shellAliases to have any effect. (Should update ~/.profile, and will warn if that file is in the way).

Try: nix run nixpkgs#home-manager -- switch

Ho wait, the switch works, but the shell aliases are not. Please ignore my previous comment then.

Have you tried this instead? Appendix A. Home Manager Configuration Options

It doesn’t help either

More questions:

  1. What is your default shell ?
  2. Do you close and restart the current shell before trying an alias?

1.Default shell - bash
2.Yes I restart shell

Have you tried this too?

Have you tried another shell (fish?)

It seems to me that the problem is related to the channel, because it was after several manipulations with the channels that this problem arose

I entered the parameter and it didn’t help, about the shell, now I’ll try zsh

If, when you run home-manager, you see output like:

Starting Home Manager activation
Activating checkFilesChanged
...

then I’d doubt that the issue is related to channels.

I was able to use home-manager to set bash aliases with the code:

              programs.bash = {
                enable = true;
                shellAliases = {
                  ",l" = "ls -l";
                };
              };

Check readlink ~/.profile. If it’s not a symlink, then home-manager isn’t affecting it. If it is a symlink, it ought to look like /nix/store/....-home-manager-files/.profile. When I applied the above HM code, it had the contents:

. "/home/rgoulter/.nix-profile/etc/profile.d/hm-session-vars.sh"
1 Like

when you talk about the .profile file, you mean .bash_profile ?

HM uses ~/.profile and ~/.bash_profile for programs.bash:

$ ls -a ~ | rg profile
.nix-profile

## enable programs.bash.enable, then apply HM
$ home-manager switch --flake .#rgoulter-x86_64-linux
Starting Home Manager activation
Activating checkFilesChanged
...

$ ls -a ~ | rg profile
.bash_profile
.nix-profile
.profile

$ cat ~/.bash_profile
# include .profile if it exists
[[ -f ~/.profile ]] && . ~/.profile

# include .bashrc if it exists
[[ -f ~/.bashrc ]] && . ~/.bashrc

I removed existing .bash_profile
and led ~/.config/nixpkgs/home.nix to this kind of:

{ config, pkgs, ... }: {
   home = {
      username = "user";
      homeDirectory = "/home/user";
      stateVersion = "23.11";
      programs.home-manager.enable = true;
       };

programs.bash = {
   enable = true;
   shellAliases = {
   g = "fastfetch";
     };
}

after that I home-manager switch
.bash_profile and .profile don’t appear

I was wondering about what’s in ~/.config exist directory home-manager besides ~/.config/nixpkgs which I create by yourself. I edited ~/.config/home-manager/home.nix and HM work properly.
HM took config files from ~/.config/home-manager/home.nix and not from that directory that I create.So stupid of me.I’m sorry for taking your time.

1 Like