Help configuring zsh in home-manager

I want to set up zsh and oh-my-zsh

My home.nix is:

{ pkgs, ... }: {
  home.username = "shmuel";
  home.homeDirectory = "/home/shmuel";
  programs.home-manager.enable = true;
  home.packages = with pkgs; [
    pkgs.oh-my-zsh
  ];

  programs.zsh = {
  ... # Your zsh config
  enable = true;
  shellAliases = {
    ll = "ls -l";
    update = "sudo nixos-rebuild switch";
  };
};

 oh-my-zsh = {
    enable = true;
    plugins = [ ];
    theme = "agnoster";
  };
 };
}

When rebuilding, I get this error:

building the system configuration...
error:
       … while calling the 'head' builtin

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/attrsets.nix:960:11:

          959|         || pred here (elemAt values 1) (head values) then
          960|           head values
             |           ^
          961|         else

       … while evaluating the attribute 'value'

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: syntax error, unexpected ID, expecting '}'

       at /nix/store/9ginqzv6dbjhkga5d23skczw3n143ah9-source/home.nix:11:3:

           10|   ... # Your zsh config
           11|   enable = true;
             |   ^
           12|   shellAliases = {

Is this line part of your file or did you remove some part?

  ... # Your zsh config
1 Like

Given that this line appears in the error message literally, they did not remove it.

@shmu26, please remove the line, the ... has a certain meaning in a certain context, and it always have to be the last thing in a set pattern, thats why you get an error here.

2 Likes

Thanks to the both of you. Now new error:

building the system configuration...
error:
       … while calling the 'head' builtin

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/attrsets.nix:960:11:

          959|         || pred here (elemAt values 1) (head values) then
          960|           head values
             |           ^
          961|         else

       … while evaluating the attribute 'value'

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: syntax error, unexpected ';', expecting end of file

       at /nix/store/1xpd4jv46gnaz0yhml02gd90k2apa675-source/home.nix:22:3:

           21|   };
           22|  };
             |   ^
           23| }

my home.nix currently looks like this:

{ pkgs, ... }: {
  home.username = "shmuel";
  home.homeDirectory = "/home/shmuel";
  programs.home-manager.enable = true;
  home.packages = with pkgs; [
    pkgs.oh-my-zsh
  ];

  programs.zsh = {
   enable = true;
   shellAliases = {
    ll = "ls -l";
    update = "sudo nixos-rebuild switch";
  };
};

 oh-my-zsh = {
    enable = true;
    plugins = [ ];
    theme = "agnoster";
  };
 };
}

At the end of the log it shows you the problem.
You have the braces miss matched, one }; too many

1 Like

Thanks again. New error:

building the system configuration...
error:
       … while calling the 'head' builtin

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/attrsets.nix:960:11:

          959|         || pred here (elemAt values 1) (head values) then
          960|           head values
             |           ^
          961|         else

       … while evaluating the attribute 'value'

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: The option `home-manager.users.shmuel.oh-my-zsh' does not exist. Definition values:
       - In `/nix/store/4b797c6c48qkwf2lkzs01h3i1d7189sq-source/flake.nix':
           {
             enable = true;
             plugins = [ ];
             theme = "agnoster";
           }

This one is really easy.

Carefully read this section and then look again at the documentation for that option.
Sorry if I’m not giving you the solution here :wink:

       error: The option `home-manager.users.shmuel.oh-my-zsh' does not exist. Definition values:
       - In `/nix/store/4b797c6c48qkwf2lkzs01h3i1d7189sq-source/flake.nix':
           {
             enable = true;
             plugins = [ ];
             theme = "agnoster";
           }
1 Like

So I added it to flake.nix:

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

  outputs = { self, nixpkgs, home-manager }: {

    nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
      ./configuration.nix
      home-manager.nixosModules.home-manager
      home-manager.users.shmuel.oh-my-zsh
  {
    home-manager.useGlobalPkgs = true;
    home-manager.useUserPackages = true;
    home-manager.users.shmuel = import ./home.nix;
  }
      ];

    };
  };
}

and now the error is:

error:
       … while calling the 'seq' builtin

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       … while evaluating a branch condition

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/modules.nix:261:9:

          260|       checkUnmatched =
          261|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [] then
             |         ^
          262|           let

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'users' missing

       at /nix/store/v8xpbwmgkfaxglskm80m4ryqx0va7lvd-source/flake.nix:15:7:

           14|       home-manager.nixosModules.home-manager
           15|       home-manager.users.shmuel.oh-my-zsh
             |       ^
           16|   {

That was not the problem, the location wasn’t the issue.
Compare the oh-my-zsh config with the one for zsh.

1 Like

I am obviously not seeing the obvious. :pensive:
Before, I had oh-my-zsh = {
Now I changed it to programs.oh-my-zsh = {
But I get

building the system configuration...
error:
       … while calling the 'head' builtin

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/attrsets.nix:960:11:

          959|         || pred here (elemAt values 1) (head values) then
          960|           head values
             |           ^
          961|         else

       … while evaluating the attribute 'value'

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: The option `home-manager.users.shmuel.programs.oh-my-zsh' does not exist. Definition values:
       - In `/nix/store/ja59753nvfi4lx346srh8xqyg9y2f0qv-source/flake.nix':
           {
             enable = true;
             plugins = [ ];
             theme = "agnoster";
           }

Yes that should’ve fixed it but I suspect that you have it in the wrong place.
From what I can see it is now in the flake.nix file.
If you move it back to the home.nix it should work.

1 Like

It’s a good advice in general when you’re trying to solve a problem.
Only ever change one thing at a time, otherwise you don’t know what exactly made it work in the end.

1 Like

So if anyone out there has further ideas, this is what I have now:
flake.nix:

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

  outputs = { self, nixpkgs, home-manager }: {

    nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
      ./configuration.nix
      home-manager.nixosModules.home-manager

      {
    home-manager.useGlobalPkgs = true;
    home-manager.useUserPackages = true;
    home-manager.users.shmuel = import ./home.nix;
  }
      ];

    };
  };
}

home.nix:

{ pkgs, ... }: {
  home.username = "shmuel";
  home.homeDirectory = "/home/shmuel";
  programs.home-manager.enable = true;
  home.packages = with pkgs; [
    pkgs.oh-my-zsh
  ];

  programs.zsh = {
   enable = true;
   shellAliases = {
    ll = "ls -l";
    update = "sudo nixos-rebuild switch";
  };
};

    programs.oh-my-zsh = {
    enable = true;
    plugins = [ ];
    theme = "agnoster";
    };
}

error:

building the system configuration...
error:
       … while calling the 'head' builtin

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/attrsets.nix:960:11:

          959|         || pred here (elemAt values 1) (head values) then
          960|           head values
             |           ^
          961|         else

       … while evaluating the attribute 'value'

         at /nix/store/bg5fbkfa5x53clcjf4p5p92k1l3w8x38-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: The option `home-manager.users.shmuel.programs.oh-my-zsh' does not exist. Definition values:
       - In `/nix/store/ja59753nvfi4lx346srh8xqyg9y2f0qv-source/flake.nix':
           {
             enable = true;
             plugins = [ ];
             theme = "agnoster";
           }

The error is referencing flake.nix, but the code snippet that it quotes is in fact in home.nix. This is puzzling.

I looked at the manual and correct would be this:

 programs.zsh = {
   enable = true;
   shellAliases = {
    ll = "ls -l";
    update = "sudo nixos-rebuild switch";
  };
  oh-my-zsh = {
    enable = true;
    plugins = [ ];
    theme = "agnoster";
  };
};

I missed that it should be nested under zsh, thought it is programs.oh-my-zsh instead of programs.zsh.oh-my-zsh

This would work as well:

 programs.zsh = {
   enable = true;
   shellAliases = {
    ll = "ls -l";
    update = "sudo nixos-rebuild switch";
  };
};
programs.zsh.oh-my-zsh = {
  enable = true;
  plugins = [ ];
  theme = "agnoster";
};

Both produce what looks like the same error. I will try to look up the logs.

building the system configuration...
activating the configuration...
setting up /etc...
reloading user units for shmuel...
restarting sysinit-reactivation.target
warning: the following units failed: home-manager-shmuel.service

× home-manager-shmuel.service - Home Manager environment for shmuel
     Loaded: loaded (/etc/systemd/system/home-manager-shmuel.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Mon 2024-02-19 22:21:16 IST; 89ms ago
   Duration: 2h 11min 12.162s
    Process: 76672 ExecStart=/nix/store/xqfi0hbdgf674hhlw9l2m5bbpd82ysql-hm-setup-env /nix/store/i9dpq3jq5ml6lymihxmnvhwp5g57g1s4-home-manager-generation (code=exited, status=1/FAILURE)
   Main PID: 76672 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 71ms

Feb 19 22:21:16 nixos systemd[1]: Starting Home Manager environment for shmuel...
Feb 19 22:21:16 nixos hm-activate-shmuel[76672]: Starting Home Manager activation
Feb 19 22:21:16 nixos hm-activate-shmuel[76672]: Activating checkFilesChanged
Feb 19 22:21:16 nixos hm-activate-shmuel[76672]: Activating checkLinkTargets
Feb 19 22:21:16 nixos hm-activate-shmuel[76761]: Existing file '/home/shmuel/.zshrc' is in the way of '/nix/store/gh5yzl95z2mhp9nwxr060h86nmj9xyq0-home-manager-files/.zshrc'
Feb 19 22:21:16 nixos hm-activate-shmuel[76761]: Please move the above files and try again or use 'home-manager switch -b backup' to back up existing files automatically.
Feb 19 22:21:16 nixos systemd[1]: home-manager-shmuel.service: Main process exited, code=exited, status=1/FAILURE
Feb 19 22:21:16 nixos systemd[1]: home-manager-shmuel.service: Failed with result 'exit-code'.
Feb 19 22:21:16 nixos systemd[1]: Failed to start Home Manager environment for shmuel.
warning: error(s) occurred while switching to the new configuration
shmuel@nixos:~/nixos/ > 

Home-manager doesn’t overwrite files.
Probably your old config is still there?
You can move it to another place and then it should work.
mv /home/shmuel/.zshrc ~/Downloads/zshrc

systemctl status home-manager-shmuel.service
× home-manager-shmuel.service - Home Manager environment for shmuel
     Loaded: loaded (/etc/systemd/system/home-manager-shmuel.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Mon 2024-02-19 22:21:16 IST; 2min 29s ago
   Duration: 2h 11min 12.162s
    Process: 76672 ExecStart=/nix/store/xqfi0hbdgf674hhlw9l2m5bbpd82ysql-hm-setup-env /nix/store/>
   Main PID: 76672 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 71ms

Feb 19 22:21:16 nixos systemd[1]: Starting Home Manager environment for shmuel...
Feb 19 22:21:16 nixos hm-activate-shmuel[76672]: Starting Home Manager activation
Feb 19 22:21:16 nixos hm-activate-shmuel[76672]: Activating checkFilesChanged
Feb 19 22:21:16 nixos hm-activate-shmuel[76672]: Activating checkLinkTargets
Feb 19 22:21:16 nixos hm-activate-shmuel[76761]: Existing file '/home/shmuel/.zshrc' is in the wa>
Feb 19 22:21:16 nixos hm-activate-shmuel[76761]: Please move the above files and try again or use>
Feb 19 22:21:16 nixos systemd[1]: home-manager-shmuel.service: Main process exited, code=exited, >
Feb 19 22:21:16 nixos systemd[1]: home-manager-shmuel.service: Failed with result 'exit-code'.
Feb 19 22:21:16 nixos systemd[1]: Failed to start Home Manager environment for shmuel.
lines 1-18/18 (END)

journalctl -xeu home-manager-shmuel.service
Feb 19 22:21:16 nixos hm-activate-shmuel[76672]: Activating checkLinkTargets
Feb 19 22:21:16 nixos hm-activate-shmuel[76761]: Existing file '/home/shmuel/.zshrc' is in the wa>
Feb 19 22:21:16 nixos hm-activate-shmuel[76761]: Please move the above files and try again or use>
Feb 19 22:21:16 nixos systemd[1]: home-manager-shmuel.service: Main process exited, code=exited, >
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ An ExecStart= process belonging to unit home-manager-shmuel.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Feb 19 22:21:16 nixos systemd[1]: home-manager-shmuel.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ The unit home-manager-shmuel.service has entered the 'failed' state with result 'exit-code'.
Feb 19 22:21:16 nixos systemd[1]: Failed to start Home Manager environment for shmuel.
░░ Subject: A start job for unit home-manager-shmuel.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A start job for unit home-manager-shmuel.service has finished with a failure.
░░ 
░░ The job identifier is 33226 and the job result is failed.
lines 129-153/153 (END)

Thanks a million! That was a long one.

You’re welcome, glad we got it working :smiley:
It takes some time to getting used to this work flow.
The great thing is that when it builds it usually works and you have a known good state you can revert to.
Even if you use generations you can always use git to revert to a previous state and built it.
Just be aware that applications that use a database sometimes don’t like it when you revert.
E.g. Signal has a database and it isn’t downwards compatible so you’re either stuck with the new package or remove the database before reverting to the older version.

1 Like