How to do more complicated examples for options

I am currently writing a module with some options.

One of the options will, most likely, contain values like these

 example = {
        "oreo_red_cursors" = pkgs.fetchzip {
          name = "oreo_red_cursors";
          url = "https://files06.pling.com/api/files/download/j/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTY2MTA1Mzk2NiwibyI6IjEiLCJzIjoiZTQ4MzE1MmU2MzQwYTEzODA1YjY1ZjY2NjZiMjdmM2JiYTdkNzZkM2QyZDE2NTI5OWQ1MWY5YTYwYzU4YTAyNjBiZDI2ODFhMWI0MjE3N2NkZTk4ZGJlMmJhYTY1M2FkZTE0ZmU1YWYzZjY2MWUzMzZmZGQ1NTcxYzZlZWU3MmYiLCJ0IjoxNzY2MTg5Njg3LCJzdGZwIjpudWxsLCJzdGlwIjoiOTIuMjA2LjUuMjIxIn0.6r_mq5Ftfprj8xtrkJuv-6RFVCxE2eN53fdjlXb9irM/oreo-red-cursors.tar.gz";
          hash = "sha256-Zr6Yvij/VGh0OjdrZHM4GN0G/ZjZkf4qLAyS3edSMzU=";
        };
      };

Most notably, this uses pkgs inside an example value.

On nix flake check . I get the following result:

❯ nix flake check .

path '/home/asqiir/projects/plasma-manager/modules' does not contain a 'flake.nix', searching up

warning: unknown flake output 'homeModules'

trace: evaluation warning: plasma-manager: homeManagerModules has been renamed to homeModules



warning: unknown flake output 'homeManagerModules'

error:

       … while checking flake output 'packages'

         at /nix/store/ww63h6fxq7hkpizfwyzfgz24lw7z8cap-source/flake.nix:38:7:

           37|

           38|       packages = forAllSystems (

             |       ^

           39|         system:



       … while checking the derivation 'packages.x86_64-linux.docs-html'

         at /nix/store/ww63h6fxq7hkpizfwyzfgz24lw7z8cap-source/flake.nix:62:11:

           61|

           62|           docs-html = docs.html;

             |           ^

           63|           docs-json = docs.json;



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



       error: attribute 'pkgs' missing

       at /nix/store/8ly89qdcjh6pb5xamvq4vrzqnifwshn3-source/lib/modules.nix:685:33:

          684|             "noting that argument `${name}` is not externally provided, so querying `_module.args` in
stead, requiring `config`"

          685|             config._module.args.${name}

             |                                 ^

          686|           )

How can I fix this without omitting the example?

Perhaps using lib.literalExpression prefix ?

2 Likes

this does sadly not fix the issue :frowning:

It does. But you have to pass a string literal to it (which is the actual fix, literalExpression just fixes the formatting to make the markdown treat it as nix code strings).

There’s a million examples of usage in nixpkgs, but basically… put two single-quotes before and after the expression, and escape chars like $ and ' as needed.

2 Likes

thx, I missunderstood your first comment

First reply wasn’t my comment :slight_smile: In any case, let us know if you’re still having issues.

1 Like