Undefined variable Error while either new pkg install or system update (with flakes)

Hi all,
i wasnt able to use my nixos system for a long time(more than 6 months). Recently when i tried to install a pkg hardinfo to see if my laptop fan was running(if there is an elegant way to know about cpu fan status thing, please let me know). After making changes to my config file, i did nix flake update and nixos-rebuild switch --flake .. I ended up getting error like such

Error in adding pkg
❯ sudo nixos-rebuild switch --flake .#system
[sudo] password for mainuser: 
building the system configuration...
trace: warning: mainuser profile: The option `programs.zsh.enableAutosuggestions' defined in `/nix/store/0ah8jpwgi9mqld1d8ps27wk26acm3a69-source/sh/sh.nix' has been renamed to `programs.zsh.autosuggestion.enable'.
trace: warning: The option `services.xserver.xkbVariant' defined in `/nix/store/0ah8jpwgi9mqld1d8ps27wk26acm3a69-source/configuration.nix' has been renamed to `services.xserver.xkb.variant'.
trace: warning: The option `services.xserver.layout' defined in `/nix/store/0ah8jpwgi9mqld1d8ps27wk26acm3a69-source/configuration.nix' has been renamed to `services.xserver.xkb.layout'.
trace: warning: The option `services.xserver.displayManager.sddm.enable' defined in `/nix/store/0ah8jpwgi9mqld1d8ps27wk26acm3a69-source/configuration.nix' has been renamed to `services.displayManager.sddm.enable'.
error:
       … while calling the 'head' builtin

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/attrsets.nix:1575:11:

         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-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: undefined variable 'hardinfo2'

       at /nix/store/0ah8jpwgi9mqld1d8ps27wk26acm3a69-source/configuration.nix:142:5:

          141|     nvd
          142|     hardinfo2
             |     ^
          143|     # Media
flake.nix
{

  description = "Initial Flake";
  # Trying out module setup

  inputs = {
    nixpkgs.url = "nixpkgs/nixos-24.05";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";

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

  outputs = { self, nixpkgs, nixpkgs-unstable, home-manager, ... }:
    let
      systemSettings = {
        system = "x86_64-linux";
        hostname = "nixos";
      };
      userSettings = {
        username = "mainuser";
        dotfilesDir = "~/.dotfiles";
      };

      system = systemSettings.system;
      lib = nixpkgs.lib;
      pkgs = nixpkgs.legacyPackages.${systemSettings.system};
      pkgs-unstable = nixpkgs-unstable.legacyPackages.${systemSettings.system};

    in {
    nixosConfigurations = {
      system = lib.nixosSystem {
        system = systemSettings.system;
        modules = [
          ./configuration.nix
          home-manager.nixosModules.home-manager
            {
                home-manager.users.${userSettings.username} = import ./home.nix;
                home-manager.extraSpecialArgs = { inherit systemSettings userSettings pkgs-unstable; };
            }
          ];
        specialArgs = {
          inherit systemSettings;
          inherit userSettings;
          inherit pkgs-unstable;
        };
      };
    };
  };
}

Before Updating:

❯ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.43, NixOS, 24.05 (Uakari), 24.05.20240801.0540572`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.5`
 - channels(mainuser): `"home-manager-23.05.tar.gz"`
 - channels(root): `""`
 - nixpkgs: `/nix/store/0ma1jl6szmcx4pr9vsczrn7vw7f85b08-source`

Even after updating my system alone and then tried to add the pkg in config file im getting the same error

❯ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.43, NixOS, 24.05 (Uakari), 24.05.20241227.31ac92f`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.8`
 - channels(mainuser): `"home-manager-23.05.tar.gz"`
 - channels(root): `""`
 - nixpkgs: `/nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source`

Need some help @NobbZ please.

hardinfo2 is only available in 24.11 and newer, please update.

23.05 is not maintained anymore for quite a long time.

Please update release by release and fix warnings in that process.

Also please don’t randomly ping people.


Okay, the ping is not random, I just realized this is a follow up to Installation of a package returns Undefined Variable Error - #7 by NobbZ.

Understood, will do as said.

I dont know why you have mentioned 23.05, but im under 24.05 currently.

When you mean release by release, is it incremental like 23.11 → 24.05 → 24.11 and so on, right ?
And regarding the warnings, i thought it was automatically taken care by the nix. Will try to fix them too. thanks for pointing out (so dumb of me :bowing_man:)

I understand, Extremely sorry once again.

Your nix-info output only has a 23.05 channel, thats the reason why I thought that.

Right

Nix doesn’t touch your config files. You have to do that on your own.

I tried to edit the warnings as you have said. but just for confirmation when i searched under the nixos options (just out of curiosity), it said the option should be programs.zsh.autosuggestions.enable but the warning message suggested to write it as programs.zsh.autosuggestion.enable.

Thing is the warning messages suggestion worked, but the nixos options from the pkg collection site did not. (im yet to update my system from 24.05 to 24.11 - just looking for how to change from plasma 5 to plasma 6, which is taking time)
is that normal or should it be logged as an issue ?

According to the sources, programs.zsh.enableAutosuggestions got renamed to programs.zsh.autosuggestions.enable.

I can not find any hints on the rename you mention here.

Can you please share the full warning message?

The warning message was the one what i got before editing as per rebuilds output.

while following as per the warning message worked but as per the source programs.zsh.autosuggestions.enable. got this error

error:
       … while calling the 'head' builtin

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/attrsets.nix:1575:11:

         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-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.mainuser.programs.zsh.autosuggestions' does not exist. Definition values:
       - In `/nix/store/6r5w9vqv0dhd4pdjmx7rk820ghxx28s5-source/sh/sh.nix':
           {
             enable = true;
           }
this is how i have mentioned them in sh.nix file
  programs.zsh = {
    enable = true;
    shellAliases = SHELL_ALIASES;
#     enableAutosuggestions = true;
#     autosuggestion.enable = true;
    autosuggestions.enable = true;

ignore the comments please.

And this is the full trace output
path '/home/mainuser/.dotfiles/sh' does not contain a 'flake.nix', searching up
building the system configuration...
path '/home/mainuser/.dotfiles/sh' does not contain a 'flake.nix', searching up
error:
       … while calling anonymous lambda

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/attrsets.nix:1571:24:

         1570|     let f = attrPath:
         1571|       zipAttrsWith (n: values:
             |                        ^
         1572|         let here = attrPath ++ [n]; in

       … while calling anonymous lambda

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/attrsets.nix:1205:18:

         1204|         mapAttrs
         1205|           (name: value:
             |                  ^
         1206|             if isAttrs value && cond value

       … from call site

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/attrsets.nix:1208:18:

         1207|             then recurse (path ++ [ name ]) value
         1208|             else f (path ++ [ name ]) value);
             |                  ^
         1209|     in

       … while calling anonymous lambda

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:242:72:

          241|           # For definitions that have an associated option
          242|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
             |                                                                        ^
          243|

       … while evaluating the option `system.build.toplevel':

       … while calling anonymous lambda

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:824:28:

          823|         # Process mkMerge and mkIf properties.
          824|         defs' = concatMap (m:
             |                            ^
          825|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

       … while evaluating definitions from `/nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/nixos/modules/system/activation/top-level.nix':

       … from call site

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:825:137:

          824|         defs' = concatMap (m:
          825|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
             |                                                                                                                                         ^
          826|         ) defs;

       … while calling 'dischargeProperties'

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:896:25:

          895|   */
          896|   dischargeProperties = def:
             |                         ^
          897|     if def._type or "" == "merge" then

       … from call site

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/nixos/modules/system/activation/top-level.nix:71:12:

           70|   # Replace runtime dependencies
           71|   system = foldr ({ oldDependency, newDependency }: drv:
             |            ^
           72|       pkgs.replaceDependency { inherit oldDependency newDependency drv; }

       … while calling 'foldr'

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/lists.nix:121:20:

          120|   */
          121|   foldr = op: nul: list:
             |                    ^
          122|     let

       … from call site

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/lists.nix:128:8:

          127|         else op (elemAt list n) (fold' (n + 1));
          128|     in fold' 0;
             |        ^
          129|

       … while calling 'fold''

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/lists.nix:124:15:

          123|       len = length list;
          124|       fold' = n:
             |               ^
          125|         if n == len

       … while calling anonymous lambda

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/attrsets.nix:1205:18:

         1204|         mapAttrs
         1205|           (name: value:
             |                  ^
         1206|             if isAttrs value && cond value

       … from call site

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/attrsets.nix:1208:18:

         1207|             then recurse (path ++ [ name ]) value
         1208|             else f (path ++ [ name ]) value);
             |                  ^
         1209|     in

       … while calling anonymous lambda

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:242:72:

          241|           # For definitions that have an associated option
          242|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
             |                                                                        ^
          243|

       … while evaluating the option `assertions':

       … while calling anonymous lambda

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:824:28:

          823|         # Process mkMerge and mkIf properties.
          824|         defs' = concatMap (m:
             |                            ^
          825|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

       … while evaluating definitions from `/nix/store/q1ss75nhmjiydyqw8lbzwbx7cqk8z0qq-source/nixos/common.nix':

       … from call site

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:825:137:

          824|         defs' = concatMap (m:
          825|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
             |                                                                                                                                         ^
          826|         ) defs;

       … while calling 'dischargeProperties'

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:896:25:

          895|   */
          896|   dischargeProperties = def:
             |                         ^
          897|     if def._type or "" == "merge" then

       … from call site

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:902:11:

          901|         if def.condition then
          902|           dischargeProperties def.content
             |           ^
          903|         else

       … while calling 'dischargeProperties'

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:896:25:

          895|   */
          896|   dischargeProperties = def:
             |                         ^
          897|     if def._type or "" == "merge" then

       … from call site

         at /nix/store/q1ss75nhmjiydyqw8lbzwbx7cqk8z0qq-source/nixos/common.nix:110:20:

          109|
          110|       assertions = flatten (flip mapAttrsToList cfg.users (user: config:
             |                    ^
          111|         flip map config.assertions (assertion: {

       … while calling 'flatten'

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/lists.nix:431:13:

          430|   */
          431|   flatten = x:
             |             ^
          432|     if isList x

       … while calling anonymous lambda

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/lists.nix:433:21:

          432|     if isList x
          433|     then concatMap (y: flatten y) x
             |                     ^
          434|     else [x];

       … from call site

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/lists.nix:433:24:

          432|     if isList x
          433|     then concatMap (y: flatten y) x
             |                        ^
          434|     else [x];

       … while calling 'flatten'

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/lists.nix:431:13:

          430|   */
          431|   flatten = x:
             |             ^
          432|     if isList x

       … while calling anonymous lambda

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/attrsets.nix:1096:10:

         1095|     attrs:
         1096|     map (name: f name attrs.${name}) (attrNames attrs);
             |          ^
         1097|

       … from call site

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/attrsets.nix:1096:16:

         1095|     attrs:
         1096|     map (name: f name attrs.${name}) (attrNames attrs);
             |                ^
         1097|

       … while calling anonymous lambda

         at /nix/store/q1ss75nhmjiydyqw8lbzwbx7cqk8z0qq-source/nixos/common.nix:110:66:

          109|
          110|       assertions = flatten (flip mapAttrsToList cfg.users (user: config:
             |                                                                  ^
          111|         flip map config.assertions (assertion: {

       … from call site

         at /nix/store/q1ss75nhmjiydyqw8lbzwbx7cqk8z0qq-source/nixos/common.nix:111:9:

          110|       assertions = flatten (flip mapAttrsToList cfg.users (user: config:
          111|         flip map config.assertions (assertion: {
             |         ^
          112|           inherit (assertion) assertion;

       … while calling 'flip'

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/trivial.nix:314:16:

          313|   */
          314|   flip = f: a: b: f b a;
             |                ^
          315|

       … while calling anonymous lambda

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/types.nix:584:22:

          583|       merge = loc: defs:
          584|         mapAttrs (n: v: v.value) (filterAttrs (n: v: v ? value) (zipAttrsWith (name: defs:
             |                      ^
          585|             (mergeDefinitions (loc ++ [name]) elemType defs).optionalValue

       … from call site

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/modules.nix:846:59:

          845|       if isDefined then
          846|         if all (def: type.check def.value) defsFinal then type.merge loc defsFinal
             |                                                           ^
          847|         else let allInvalid = filter (def: ! type.check def.value) defsFinal;

       … while calling 'merge'

         at /nix/store/25wr1mdhyil8icqpkx5326shnlf4245l-source/lib/types.nix:888:22:

          887|         check = x: isAttrs x || isFunction x || path.check x;
          888|         merge = loc: defs:
             |                      ^
          889|           (base.extendModules {

       error: The option `home-manager.users.mainuser.programs.zsh.autosuggestions' does not exist. Definition values:
       - In `/nix/store/6r5w9vqv0dhd4pdjmx7rk820ghxx28s5-source/sh/sh.nix':
           {
             enable = true;
           }

interesting, this looks like a typo in the deprecation warning, though in the link I sent you, the typo doesn’t exist.

And I went back until nixos-22.05s tip, and it doesn’t seem that typo doesn’t exist.

I can not explain that output to myself.

JFYI, I have updated my system from 24.5 → 24.11 and now it expects as per docs/source programs.zsh.autosuggestions.enable and not autosuggestion.enable(which gave the same error as earlier)