!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

82 Members
21 Servers

Load older messages


SenderMessageTime
5 Jan 2024
@admin:nixos.org@admin:nixos.org left the room.14:19:19
6 Jan 2024
@infinisil:matrix.orginfinisil joined the room.20:39:04
8 Jan 2024
@ss:someonex.netSomeoneSerge (utc+3) changed their display name from SomeoneSerge (UTC+2) to SomeoneSerge (hash-versioned python modules when).04:51:34
22 Jan 2024
@djacu:matrix.org@djacu:matrix.org joined the room.21:58:53
25 Jan 2024
@fgaz:matrix.orgfgaz joined the room.07:01:32
29 Jan 2024
@djacu:matrix.org@djacu:matrix.org

Hey all

I am creating some new modules and want to generate documentation for them but I get errors like this. error: The option content' is used but not defined.`

This is because I create the option content but don't assign a default value to it. I did this because I want the user to define it every time. Any recommendations?

02:00:59
@djacu:matrix.org@djacu:matrix.org *

Hey all

I am creating some new modules and want to generate documentation for them but I get errors like this. error: The option 'content' is used but not defined.\

This is because I create the option content but don't assign a default value to it. I did this because I want the user to define it every time. Any recommendations?

02:01:09
@djacu:matrix.org@djacu:matrix.org *

Hey all

I am creating some new modules and want to generate documentation for them but I get errors like this. error: The option 'content' is used but not defined.

This is because I create the option content but don't assign a default value to it. I did this because I want the user to define it every time. Any recommendations?

02:01:14
@lehmanator:tchncs.deSam Lehman joined the room.11:08:22
@infinisil:matrix.orginfinisil djacu That means you're evaluating the option somehow, but generating docs shouldn't require that 12:11:50
@djacu:matrix.org@djacu:matrix.org
In reply to @infinisil:matrix.org
djacu That means you're evaluating the option somehow, but generating docs shouldn't require that
Not sure what I changed but it's working now... Maybe I was passing the whole output of evalModules to optionAttrSetToDocList instead of just the options value.
20:04:11
31 Jan 2024
@djacu:matrix.org@djacu:matrix.org Is it possible to override the parameters of an option after creation? If that isn't clear let me explain my situation. I have a module that defines several options that are generic definitions and is imported by several other modules. E.g. I have a format.nix that defines content and order that are both visible to the user. Now in some cases, I want to hide order. So my thought was that I could override the visibility in the modules that import format.nix. But I can't seem to figure out how to do that. Possible? 05:38:47
@djacu:matrix.org@djacu:matrix.org * Is it possible to override the parameters of an option after creation? If that isn't clear let me explain my situation. I have a module that defines several options that are generic definitions and is imported by several other modules. E.g. I have a format.nix that defines content and order that are both visible to the user. In certain cases where I import format.nix into another module, I want to hide order. So my thought was that I could override the visibility in those modules. But I can't seem to figure out how to do that. Possible? 05:42:19
@infinisil:matrix.orginfinisil djacu: Yeah that's not possible, probably best to have a function with that parameter that returns a new option, like lib.mkPackageOption 16:03:53
@djacu:matrix.org@djacu:matrix.org
In reply to @infinisil:matrix.org
djacu: Yeah that's not possible, probably best to have a function with that parameter that returns a new option, like lib.mkPackageOption
Yeah I figured. Thank infinisil !
17:37:10
1 Feb 2024
@djacu:matrix.org@djacu:matrix.org

Hi all. I have a question about merging user defined options with default options. I am trying to design a module with the following attributes.

  1. It has a user and default options that are attrs of something. user defaults to {} and default defaults to some non-empty set.
  2. There is a useDefault option that will control whether or not the default values get used.
  3. There is an out option that merges the user and default options.
  4. (where i have trouble) The user can enable the defaults but also override them.

I have a working example below. default is set to {a = 1; b = 2}. With useDefault = true;, I can set some other key-value like c=3 and ever override it with mkOverride or mkForce. However, I cannot override anything that was set by default. You can see in userOptions all the things I tried to get the config to evaluate properly but nothing worked.

Have I missed something or is this not possible? Thanks

let
  pkgs = import <nixpkgs> {};
  inherit (pkgs) lib;
  inherit (lib) types;

  testDefaults = {
    lib,
    config,
    ...
  }: {
    options = {
      user = lib.mkOption {
        description = "Test default things.";
        type = types.attrsOf types.int;
        default = {};
      };

      useDefault = lib.mkEnableOption "Enables default.";

      default = lib.mkOption {
        description = "The defaults";
        type = types.attrsOf types.int;
        default = {
          a = 1;
          b = 2;
        };
      };

      out = lib.mkOption {
        description = "The output.";
        type = types.attrsOf types.int;
        default = {};
      };
    };

    config = lib.mkMerge [
      (
        lib.mkIf config.useDefault {
          out = config.default;
        }
      )
      {
        out = config.user;
      }
    ];
  };

  userOptions = [
    ({...}: {useDefault = true;})

    # NONE OF THESE WORK; conflicting definitions
    # ({...}: {user = {b = 3;};})
    # ({...}: {user = {b = lib.mkOverride 1 3;};})
    # ({...}: {user = {b = lib.mkDefault 3;};})
    # ({...}: {user = {b = lib.mkForce 3;};})
    # ({...}: {user = lib.mkForce {b = 3;};})

    # I can set an option not in default.
    ({...}: {user = {c = 3;};})
    # And I can override my own option using mkOVerride (<100).
    ({...}: {user = {c = lib.mkOverride 99 4;};})
    # Or just mkForce which is mkOverride 50.
    # ({...}: {user = {c = lib.mkForce 4;};})
  ];
in (
  (lib.evalModules {
    modules =
      [
        testDefaults
      ]
      ++ userOptions;
  })
  .config
)
19:45:53
@gtrunsec:matrix.orgguangtao

is it possible to solve your problem through the apply option? I mean you can set the defualt to be {}, use apply instead

        apply = cfg: lib.recursiveUpdate {<default>} cfg;

20:12:04
@gtrunsec:matrix.orgguangtao *

is it possible to solve your problem through the apply option? I mean you can set the defualt to be {}, use apply instead


20:12:13
@gtrunsec:matrix.orgguangtao *

is it possible to solve your problem through the apply option? I mean you can set the defualt to be {}, use apply instead

apply = cfg: lib.recursiveUpdate {<default>} cfg;
20:12:42
@gtrunsec:matrix.orgguangtaoYeah, if I understand your problem correctly.20:13:50
@infinisil:matrix.orginfinisil Oh don't use apply, that's generally an anti-pattern 20:14:12
@infinisil:matrix.orginfinisilI'll take a closer look at the code20:14:22
@djacu:matrix.org@djacu:matrix.org apply also generally wouldn't work because this module wouldn't necessarily be at the top level. I mean it could work but would be messy. Also, it breaks out of the module ecosystem and isn't very user friendly. 20:16:08
@infinisil:matrix.orginfinisilOh so it doesn't work because to the module system, all definitions have the same priority20:16:57
@infinisil:matrix.orginfinisil You set them both with out = <attrset>, no mkDefault or so 20:17:16
@infinisil:matrix.orginfinisil But out = mkDefault config.default wouldn't work because then the entire attribute set gets overridden by the users one, therefore not using any defaults 20:18:00
@infinisil:matrix.orginfinisil What you need is out = mapAttrs (name: mkDefault) config.default 20:18:26
@djacu:matrix.org@djacu:matrix.org

I'm a little lost. Which line would I inject this:

out = mapAttrs (name: mkDefault) config.default

Also doesn't mapAttrs a function of 2 variables?

20:21:09
@infinisil:matrix.orginfinisil The line out = config.default; 20:21:48
@djacu:matrix.org@djacu:matrix.org *

I'm a little lost. Which line would I inject this:

out = mapAttrs (name: mkDefault) config.default

Also isn't mapAttrs a function of 2 variables?

20:22:09

Show newer messages


Back to Room ListRoom Version: 10