Emit integer keys with `pkgs.formats.yaml`

Hi, I’m trying to emit integer keys with pkgs.formats.yaml. Does anyone know how to do it?

I’m trying to turn my LACT configuration to nix with services.lact.settings.

I attempted to directly translate my current config file into a nix struct:

...
          curve:
            50: 0.0
            63: 0.25
            71: 0.50
            77: 0.75
            82: 1.0
...
        gpu_vf_curve:
          2:
            voltage: 945
            clockspeed: 1905
...

My LACT config file has integer keys which I can’t directly express in nix (attribute set keys can’t be numbers)

I tried turning the integer keys into strings:

curve = {
  "50" = 0.0;
  "63" = 0.25;
  "71" = 0.5;
  "77" = 0.75;
  "82" = 1.0;
};

But it generated an invalid config file:

          curve:
            '50': 0.0
            '63': 0.25
            '71': 0.5
            '77': 0.75
            '82': 1.0

which prevented lactd from starting:

Error: Could not deserialize config
Caused by:
    profiles.Steam.gpus.{...}.fan_control_settings.curve: invalid type: string "50", expected i32 at line 16 column 13
lactd.service: Main process exited, code=exited, status=1/FAILURE
1 Like

Can’t be done. The formatter uses JSON as an intermediate format, and JSON only has string keys, so the final json2yaml invocation always ensures that the output keys are strings too.

One solution is to add to lact a configFile option, similar to this PR

In case there is a misunderstanding:

The above PR is for a different package (glance). You’ll need to make your own modifications to lact (in a fork of nixpkgs), in a similar fashion to the glance modification, to achieve the desired functionality in lact.

If you want I can do it for you, just give me a shout.