!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

149 Members
30 Servers

Load older messages


SenderMessageTime
30 Sep 2024
@mattsturg:matrix.orgMatt Sturgeon *

My MRE attempt is producing the expected behavior:

nix-repl> (lib.modules.mergeDefinitions [] result.list-type' [ { file = "."; value = ["a"]; } { file = "."; value = ["b"]; } ]).mergedValue
[ "a'" "b'" ]

nix-repl> (lib.modules.mergeDefinitions [] result.configuration.options.list'.type [ { file = "."; value = ["a"]; } { file = "."; value = ["b"]; } ]).mergedValue
[ "a'" "b'" ]

nix-repl> (lib.modules.mergeDefinitions [] result.attrs-type' [ { file = "."; value = { a = "a"; }; } { file = "."; value = { b = "b"; }; } ]).mergedValue
{ a = "a'"; b = "b'"; }

nix-repl> (lib.modules.mergeDefinitions [] result.configuration.options.attrs'.type [ { file = "."; value = { a = "a"; }; } { file = "."; value = { b = "b"; }; } ]).mergedValue
{ a = "a'"; b = "b'"; }

So I'm struggling to understand why in #2342 I have issues where the the type behaves differently after being used in evalModules and/or listOf:

nix-repl> (lib.modules.mergeDefinitions [] lib.nixvim.keymaps.deprecatedMapOptionSubmodule  [ { file = "."; value = {key = "a"; action = "b";}; } ]).mergedValue
{ action = "b"; key = "a"; mode = ""; options = { ... }; }

nix-repl> (lib.modules.mergeDefinitions [] legacyPackages.x86_64-linux.nixvimConfiguration.options.keymaps.type.nestedTypes.elemType  [ { file = "."; value ={ action = "b"; key = "a"; lua = «error: error:
       … while evaluating the attribute 'value'

         at /nix/store/fpivx4sjcp2vk4rp9nhliln5cwcp3kc6-source/lib/modules.nix:821:9:

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

       … while calling the 'addErrorContext' builtin

         at /nix/store/fpivx4sjcp2vk4rp9nhliln5cwcp3kc6-source/lib/modules.nix:821:17:

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

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

       error: The option `lua' was accessed but has no value defined. Try setting the option.»; mode = ""; options = { ... }; }

nix-repl> builtins.head (lib.modules.mergeDefinitions [] legacyPackages.x86_64-linux.nixvimConfiguration.options.keymaps.type  [ { file = "."; value = [{key = "a"; action = "b";}]; } { file = "."; value = [{ key = "c"; action = "d";}]; } ]).mergedValue
{ action = "b"; key = "a"; lua = «error: error:
       … while evaluating the attribute 'value'

         at /nix/store/fpivx4sjcp2vk4rp9nhliln5cwcp3kc6-source/lib/modules.nix:821:9:

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

       … while calling the 'addErrorContext' builtin

         at /nix/store/fpivx4sjcp2vk4rp9nhliln5cwcp3kc6-source/lib/modules.nix:821:17:

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

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

       error: The option `"[definition 1-entry 1]".lua' was accessed but has no value defined. Try setting the option.»; mode = ""; options = { ... }; }

NOTE: legacyPackages.x86_64-linux.nixvimConfiguration.options.keymaps.type.nestedTypes.elemType and lib.nixvim.keymaps.deprecatedMapOptionSubmodule should be the same thing, but one works correctly while the other does not.

The keymaps option is literally defined as:

keymaps = lib.mkOption {
  type = lib.types.listOf helpers.keymaps.deprecatedMapOptionSubmodule;
  # ...
}

EDIT: Accessing lib via special args also does not produce the issue (i.e. works correctly):

nix-repl> (lib.modules.mergeDefinitions [] legacyPackages.x86_64-linux.nixvimConfiguration._module.specialArgs.lib.nixvim.keymaps.deprecatedMapOptionSubmodule  [ { file = "."; value = {key = "a"; action = "b";}; } ]).mergedValue
{ action = "b"; key = "a"; mode = ""; options = { ... }; }

07:49:22
@mattsturg:matrix.orgMatt Sturgeon *

My MRE attempt is producing the expected behavior:

nix-repl> (lib.modules.mergeDefinitions [] result.list-type' [ { file = "."; value = ["a"]; } { file = "."; value = ["b"]; } ]).mergedValue
[ "a'" "b'" ]

nix-repl> (lib.modules.mergeDefinitions [] result.configuration.options.list'.type [ { file = "."; value = ["a"]; } { file = "."; value = ["b"]; } ]).mergedValue
[ "a'" "b'" ]

nix-repl> (lib.modules.mergeDefinitions [] result.attrs-type' [ { file = "."; value = { a = "a"; }; } { file = "."; value = { b = "b"; }; } ]).mergedValue
{ a = "a'"; b = "b'"; }

nix-repl> (lib.modules.mergeDefinitions [] result.configuration.options.attrs'.type [ { file = "."; value = { a = "a"; }; } { file = "."; value = { b = "b"; }; } ]).mergedValue
{ a = "a'"; b = "b'"; }

So I'm struggling to understand why in #2342 I have issues where the the type behaves differently after being used in evalModules and/or listOf:

nix-repl> (lib.modules.mergeDefinitions [] lib.nixvim.keymaps.deprecatedMapOptionSubmodule  [ { file = "."; value = {key = "a"; action = "b";}; } ]).mergedValue
{ action = "b"; key = "a"; mode = ""; options = { ... }; }

nix-repl> (lib.modules.mergeDefinitions [] legacyPackages.x86_64-linux.nixvimConfiguration.options.keymaps.type.nestedTypes.elemType  [ { file = "."; value ={ action = "b"; key = "a"; lua = «error: error:
       … while evaluating the attribute 'value'

         at /nix/store/fpivx4sjcp2vk4rp9nhliln5cwcp3kc6-source/lib/modules.nix:821:9:

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

       … while calling the 'addErrorContext' builtin

         at /nix/store/fpivx4sjcp2vk4rp9nhliln5cwcp3kc6-source/lib/modules.nix:821:17:

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

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

       error: The option `lua' was accessed but has no value defined. Try setting the option.»; mode = ""; options = { ... }; }

nix-repl> builtins.head (lib.modules.mergeDefinitions [] legacyPackages.x86_64-linux.nixvimConfiguration.options.keymaps.type  [ { file = "."; value = [{key = "a"; action = "b";}]; } { file = "."; value = [{ key = "c"; action = "d";}]; } ]).mergedValue
{ action = "b"; key = "a"; lua = «error: error:
       … while evaluating the attribute 'value'

         at /nix/store/fpivx4sjcp2vk4rp9nhliln5cwcp3kc6-source/lib/modules.nix:821:9:

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

       … while calling the 'addErrorContext' builtin

         at /nix/store/fpivx4sjcp2vk4rp9nhliln5cwcp3kc6-source/lib/modules.nix:821:17:

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

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

       error: The option `"[definition 1-entry 1]".lua' was accessed but has no value defined. Try setting the option.»; mode = ""; options = { ... }; }

NOTE: legacyPackages.x86_64-linux.nixvimConfiguration.options.keymaps.type.nestedTypes.elemType and lib.nixvim.keymaps.deprecatedMapOptionSubmodule should be the same thing, but one works correctly while the other does not.

The keymaps option is literally defined as:

keymaps = lib.mkOption {
  type = lib.types.listOf lib.nixvim.keymaps.deprecatedMapOptionSubmodule;
  # ...
}

EDIT: Accessing lib via special args also does not produce the issue (i.e. works correctly):

nix-repl> (lib.modules.mergeDefinitions [] legacyPackages.x86_64-linux.nixvimConfiguration._module.specialArgs.lib.nixvim.keymaps.deprecatedMapOptionSubmodule  [ { file = "."; value = {key = "a"; action = "b";}; } ]).mergedValue
{ action = "b"; key = "a"; mode = ""; options = { ... }; }

07:49:46
1 Oct 2024
@-_o:matrix.org-_o joined the room.21:03:34
2 Oct 2024
@cafkafk:fem.ggcafkafk 🏳️‍⚧️ joined the room.12:19:06
4 Oct 2024
@terrorjack:matrix.terrorjack.comterrorjack joined the room.17:38:04
7 Oct 2024
@thunder:kotiboksi.xyzThunder joined the room.08:26:57
@lehmanator:tchncs.deSam Lehman changed their profile picture.14:24:14
10 Oct 2024
@p4cmanus3r:matrix.orgp4cmanus3r joined the room.13:24:45
11 Oct 2024
@lehmanator:tchncs.deSam Lehman

Are there any good writeups on using lib.types?

I've gone through the manual, the nix.dev deep dive, and a bunch of other Nix module related posts, but nothing seems to cover the more advanced use cases of lib.types and submodules.

15:12:19
@artturin:matrix.orgArtturin joined the room.19:28:40
15 Oct 2024
@pyrox:pyrox.devdish [Fox/It/She] joined the room.03:21:06
19 Oct 2024
@jwillikers:matrix.orgjwillikers joined the room.12:07:59
21 Oct 2024
@artur:glasgow.socialmoved to @amadaluzia:tchncs.de changed their display name from (lambda (f l) (format nil "~a ~a")) "Artur" "Manuel" to (artur 'manuel).20:04:44
23 Oct 2024
@luna-null:matrix.orgluna-null changed their display name from Autumn to luna-null.09:49:21
24 Oct 2024
@jopejoe1:matrix.orgjopejoe1 (4094@eh22) set a profile picture.07:35:14
@pyrox:pyrox.devdish [Fox/It/She] left the room.08:18:07
25 Oct 2024
@lholh:matrix.orglholh joined the room.03:54:51
29 Oct 2024
@nam3l33ss:matrix.org·☽•Nameless☆•777 · ± joined the room.17:36:30
3 Nov 2024
@samrose:matrix.orgsamrose joined the room.11:51:10
6 Nov 2024
@seapat:matrix.orgseapat joined the room.13:48:07
8 Nov 2024
@jschvz:matrix.orgjschvz joined the room.02:57:20
@artur:glasgow.socialmoved to @amadaluzia:tchncs.de changed their display name from (artur 'manuel) to moved to @amadaluzia:tchncs.de.14:29:46
10 Nov 2024
@sbc64:matrix.orgsbc64 left the room.20:02:18
@ibizaman:matrix.orgibizaman

I have an option whose default depends on a value defined in the config.

options.shb.restic.databases = mkOption {
  type = attrsOf (submodule ({ name, config, ... }: {
    result = mkOption { type = submodule { options = {
      default = {
        restoreScript = config.settings.repository;
      };
    };};};
  };
};

(I'm skipping a few details in the type here, not sure what is important or not).
Everything works well AFAICT (at least the NixOS tests work fine) until I try to build the documentation of my project. And then I get:

The option `shb.restic.databases.<name>.settings' was accessed but has no value defined. Try setting the option.

Here is where the documentation code is evaluating the modules.

So I tried changing the default to use options instead of config like so: restoreScript = options.settings.value.repository;. The NixOS tests still work fine but I get the same error as above.

I also tried adding a dummy module inside the individualModuleOptionsDocs call that does something like so:

{
  config = {
    shb.restic.databases."<name>".settings = {
      repository = "...";
    };
  };
}

But that's not working either 😅 What's working is if I use a hardcoded string for the default value of the options.

Here is the PR introducing the changes leading to that error. This Github action shows the error. More specifically, here's the type definition and default setting that causes an issue.
Any idea what I should do to keep this computed default value while being able to generate the documentation?

On a totally different topic, this PR introduces 2 contracts in the form of structural typing for backing up files and backing up databases. They are both implemented by Restic. The correct implementation of both contracts is enforced by 2 generic NixOS tests (here and here) and then the Restic implementation is verified here and here.

23:28:04
@ibizaman:matrix.orgibizaman *

I have an option whose default depends on a value defined in the config.

options.shb.restic.databases = mkOption {
  type = attrsOf (submodule ({ name, config, ... }: {
    result = mkOption { type = submodule { options = {
      default = {
        restoreScript = config.settings.repository;
      };
    };};};
  };
};

(I'm skipping a few details in the type here, not sure what is important or not. There's a link to the PR with the full code further down).
Everything works well AFAICT (at least the NixOS tests work fine) until I try to build the documentation of my project. And then I get:

The option `shb.restic.databases.<name>.settings' was accessed but has no value defined. Try setting the option.

Here is where the documentation code is evaluating the modules.

So I tried changing the default to use options instead of config like so: restoreScript = options.settings.value.repository;. The NixOS tests still work fine but I get the same error as above.

I also tried adding a dummy module inside the individualModuleOptionsDocs call that does something like so:

{
  config = {
    shb.restic.databases."<name>".settings = {
      repository = "...";
    };
  };
}

But that's not working either 😅 What's working is if I use a hardcoded string for the default value of the options.

Here is the PR introducing the changes leading to that error. This Github action shows the error. More specifically, here's the type definition and default setting that causes an issue.
Any idea what I should do to keep this computed default value while being able to generate the documentation?

On a totally different topic, this PR introduces 2 contracts in the form of structural typing for backing up files and backing up databases. They are both implemented by Restic. The correct implementation of both contracts is enforced by 2 generic NixOS tests (here and here) and then the Restic implementation is verified here and here.

23:28:39
@ibizaman:matrix.orgibizaman *

I have an option whose default depends on a value defined in the config.

options.shb.restic.databases = mkOption {
  type = attrsOf (submodule ({ name, config, ... }: {
    result = mkOption { type = submodule { options = {
      default = {
        restoreScript = config.settings.repository;
      };
    };};};
  };
};

(I'm skipping a few details in the type here, not sure what is important or not. There's a link to the PR with the full code further down).
Everything works well AFAICT (at least the NixOS tests work fine) until I try to build the documentation of my project. And then I get:

The option `shb.restic.databases.<name>.settings' was accessed but has no value defined. Try setting the option.

Here is where the documentation code is evaluating the modules.

So I tried changing the default to use options instead of config like so: restoreScript = options.settings.value.repository;. The NixOS tests still work fine but I get the same error as above.

I also tried adding a dummy module inside the individualModuleOptionsDocs call that does something like so:

{
  config = {
    shb.restic.databases."<name>".settings = {
      repository = "...";
    };
  };
}

But that's not working either 😅 What's working is if I use a hardcoded string for the default value of the options.

Here is the PR introducing the changes leading to that error. This Github action shows the error. More specifically, here's the type definition and default setting that causes an issue.
Any idea what I should do to keep this computed default value while being able to generate the documentation?

On a totally different topic, this PR introduces 2 contracts in the form of structural typing for backing up files and backing up databases. They are both implemented by Restic. The correct implementation of both contracts is enforced by 2 generic NixOS tests (here and here) and then the Restic implementation is verified here and here.

23:32:16
@h7x4:nani.wtfh7x4 I've usually set defaultText to reflect where it's pulling it's default from. Would that work for you? 23:32:48
@ibizaman:matrix.orgibizamanYessssssssss that worked!!23:36:06
@ibizaman:matrix.orgibizamanI'm happy to go to bed on a positive note, I'll post the update tomorrow :) Thanks!!23:36:53
@h7x4:nani.wtfh7x4Great!23:37:30

Show newer messages


Back to Room ListRoom Version: 10