jakehamilton / config

One Nix flake to rule them all.
Other
360 stars 21 forks source link

Modules cannot be sets #10

Closed NomisIV closed 4 months ago

NomisIV commented 11 months ago

I had a module in ./modules/home/xdg-dirs/default.nix with the following contents:

{
  xdg = {
    userDirs = {
      enable = true;
      desktop = "$HOME/.desktop";
      documents = "$HOME/documents";
      download = "$HOME/downloads";
      music = "$HOME/music";
      pictures = "$HOME/pictures";
    };
  };
}

Note the lack of an import set. This would be a valid nixos/home-manager module, but snowfall-lib blows up with a cryptic (but reasonable) error message:

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

         at /nix/store/9incrwprw2s90minyy0gpmwbxmrkcx1v-source/lib/attrsets.nix:820:11:

          819|         || pred here (elemAt values 1) (head values) then
          820|           head values
             |           ^
          821|         else

       … while evaluating the attribute 'value'

         at /nix/store/9incrwprw2s90minyy0gpmwbxmrkcx1v-source/lib/modules.nix:800:9:

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

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

       error: attempt to call something which is not a function but a set

       at /nix/store/2d4jq687zrkvl17fgrhx9kh5fif0jpy1-f0rx1fjmr59ndcpbl309kpbijlrjhq2v-source/snowfall-lib/module/default.nix:76:31:

           75|                 };
           76|                 user-module = import metadata.path modified-args;
             |                               ^
           77|               in

While it's obviously easy to add an import set, the error is confusing and a bad user experience, unless you know exactly what's wrong. So I mean that the solution doesn't have to be to support this, but to at least have a nice error message explaining what's wrong.

jakehamilton commented 11 months ago

Ah I thought I had replied to this. Sorry about that!

Thank you for filing this issue! I agree this is something that should be fixed in Snowfall Lib. It shouldn't be too bad to import the file and check to see whether the value is a function or not :+1:

jakehamilton commented 4 months ago

This should now be fixed on dev via this PR: https://github.com/snowfallorg/lib/pull/71