Attribute 'set' missing in home-manager module

I’m writting a module for tint2 since it a program i use, i’m very new to nix lenguage but i really would like to contribute to the source code, here is my module:

{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.programs.tint2;

  buildConfig = config:
    concatStringsSep "\n" (mapAttrsToList renderConfig config);

  renderConfig = name: value: "${name}=${renderValue value}";

  renderValue = option:
    {
      int = toString option;
      bool = if option then "yes" else "no";
      string = option;
    }.${builtins.typeOf option};

  valueType = with types; oneOf [ bool int str ];

in

{
  options.programs.tint2 = {
    enable = mkEnableOption "tint2, a simple, unobtrusive and light panel for Xorg";

    config = mkOption {
      type = types.attrsOf valueType;
      default = { };
      example = { rounded=0; border_with=2; background_color="#282828 100"; };
      description = ''
        tint2 configuration file.
      '';
    };
  };

  config = mkIf cfg.enable {
    home.packages = [ pkgs.tint2 ];

    xdg.configFile = {
      "tint2/tint2rc" = mkIf (cfg.config != { }) {
        text = buildConfig config + "\n";
      };
    };
  };
}

when trying to run home-manager switch it complains:

error: attribute 'set' missing

       at /home/MyUser/dev/home-manager/modules/programs/tint2.nix:15:5:

           14|   renderValue = option:
           15|     {
             |     ^
           16|       int = toString option;

i’ve no idea what i’m doing wrong here. Any idea?

Have you tried adding an entry for set to the renderValue attrset? Looks like that function ends up being called with a set rather than any of the defined types.

Can’t spot immediately why, but if you print it (maybe with traceVal) it should be easy to figure out why.

Are you sure that’s the correct code for the error?

They don’t line up very well…

Turns out i was missing

    xdg.configFile = {
      "tint2/tint2rc" = mkIf (cfg.config != { }) {
-        text = buildConfig config + "\n";
+        text = buildConfig cfg.config + "\n";
      };
1 Like