Skip to content

Check project types#1003

Merged
fricklerhandwerk merged 11 commits intongi-nix:mainfrom
eljamm:examples-check-types
May 20, 2025
Merged

Check project types#1003
fricklerhandwerk merged 11 commits intongi-nix:mainfrom
eljamm:examples-check-types

Conversation

@eljamm
Copy link
Contributor

@eljamm eljamm commented May 6, 2025

Ideally, we'd only evaluate the modules without building anything.

Continuation of #991

module = mkOption {
description = "the example must be a NixOS module in a file";
type = pathInStore;
type = deferredModule;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be a path, since we need to render it in documentation. Can't render an expression

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With pathInStore:

nix-repl> :p evaluated-modules.config.projects.Omnom.nixos.services.omnom.examples.base.module
error:
       … while evaluating the attribute 'value'
         at /nix/store/qmm7hgw60vp7vj9lma95hl329d0j3n6n-source/lib/modules.nix:1084:7:
         1083|     // {
         1084|       value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |       ^
         1085|       inherit (res.defsFinal') highestPrio;while calling the 'addErrorContext' builtin
         at /nix/store/qmm7hgw60vp7vj9lma95hl329d0j3n6n-source/lib/modules.nix:1084:15:
         1083|     // {
         1084|       value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |               ^
         1085|       inherit (res.defsFinal') highestPrio;

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

       error: A definition for option `projects.Omnom.nixos.services.omnom.examples.base.module' is not of type `path in the Nix store'. Definition values:
       - In `<unknown-file>': /home/user/ngipkgs/projects/Omnom/example.nix

with deferredModule:

nix-repl> :p evaluated-modules.config.projects.Omnom.nixos.services.omnom.examples.base.module
{
  imports = [
    {
      _file = "<unknown-file>, via option projects.Omnom.nixos.services.omnom.examples.base.module";
      imports = [ /home/user/ngipkgs/projects/Omnom/example.nix ];
    }
  ];
}

Still, the module isn't being rendered in the overview in both cases, AFAIK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just path then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just path then?

That works, but it means we can't do something like this anymore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm but that link shows an actual module, not an example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that by using path all modules will need to be stored in files and we won't be able to declare them like that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah and that's alright. We require them as a string in a file for documentation, that's how it is.

@eljamm eljamm force-pushed the examples-check-types branch 2 times, most recently from 01d7f80 to ccfa1be Compare May 7, 2025 10:56
@eljamm eljamm marked this pull request as ready for review May 7, 2025 11:01
@eljamm eljamm changed the title Check module system types with examples Check project types May 7, 2025
@eljamm
Copy link
Contributor Author

eljamm commented May 7, 2025

To check the module types for a project, run:

nix build .#checks.x86_64-linux.projects/<PROJECT_NAME>/nixos/check

For example:

nix build .#checks.x86_64-linux.projects/Omnom/nixos/check
Wrong types

  metadata = {
    summary = "Omnom is a webpage bookmarking and snapshotting service.";
    subgrants = [
      "omnom"
      "omnom-ActivityPub"
      123123 # <----
    ];
  };
 error: A definition for option `projects.Omnom.metadata.subgrants."[definition 1-entry 3]"' is not of type `string'. Definition values:
 - In `<unknown-file>': 123123
  examples.base = {
    module = ""; # <----
    description = "Basic Omnom configuration, mainly used for testing purposes";
    tests.basic = null;
  };
 error: A definition for option `projects.Omnom.nixos.services.omnom.examples.base.module' is not of type `module'. Definition values:
 - In `<unknown-file>': ""

Missing attributes

  examples.base = {
    module = ./example.nix;
    description = "Basic Omnom configuration, mainly used for testing purposes";
    # tests.basic = null; # <----
  };
 error: The option `projects.Omnom.nixos.services.omnom.examples.base.tests' was accessed but has no value defined. Try setting the option.

Extra/Undefined attributes

  examples.base = {
    module = ./example.nix;
    description = "Basic Omnom configuration, mainly used for testing purposes";
    tests.basic = null;
    hello = "world"; # <----
  };
 error: The option `projects.Omnom.nixos.services.omnom.examples.base.hello' does not exist. Definition values:
 - In `<unknown-file>': "world"

@eljamm eljamm force-pushed the examples-check-types branch 3 times, most recently from 7718b9a to be32e22 Compare May 16, 2025 08:44
@eljamm eljamm force-pushed the examples-check-types branch from be32e22 to b5aaf94 Compare May 16, 2025 09:13
@eljamm eljamm force-pushed the examples-check-types branch from b5aaf94 to d853be2 Compare May 16, 2025 09:18
@eljamm
Copy link
Contributor Author

eljamm commented May 16, 2025

I've split off a few fixes to a separate PR and dropped the treewide renaming of nixos.modules.{services,projects} to nixos.{services,projects} as that was breaking a few things. I think it would be better to look into doing that properly, later.

@fricklerhandwerk fricklerhandwerk merged commit f9aa86b into ngi-nix:main May 20, 2025
8 checks passed
@github-project-automation github-project-automation bot moved this to Done in Nix@NGI May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants