From 02a696bccd681ae5ea5538f300d6fca493b99d02 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 21 Aug 2025 11:04:15 +0200 Subject: [PATCH] ci,modules: Backport additions of #431450 Reason: keep ci directory in sync - https://github.com/NixOS/nixpkgs/pull/431450#issuecomment-3209546418 This requires that we have a modules directory, in which case the easy and robust solution is to only port the addition parts of the refactor. It's about as easy as a .keep file, but more useful. This means that some duplication is created, but we avoid backporting the changes to the documentation generation, which is a somewhat complex component I'd rather not touch until these changes have been proven out on unstable. --- ci/eval/default.nix | 1 + modules/README.md | 9 ++++ modules/generic/meta-maintainers.nix | 63 +++++++++++++++++++++++ modules/generic/meta-maintainers/test.nix | 34 ++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 modules/README.md create mode 100644 modules/generic/meta-maintainers.nix create mode 100644 modules/generic/meta-maintainers/test.nix diff --git a/ci/eval/default.nix b/ci/eval/default.nix index 2b7f59ae6b43..363804cce716 100644 --- a/ci/eval/default.nix +++ b/ci/eval/default.nix @@ -30,6 +30,7 @@ let "doc" "lib" "maintainers" + "modules" "nixos" "pkgs" ".version" diff --git a/modules/README.md b/modules/README.md new file mode 100644 index 000000000000..777ab9839949 --- /dev/null +++ b/modules/README.md @@ -0,0 +1,9 @@ +# `/modules` + +This directory hosts subdirectories representing each module [class](https://nixos.org/manual/nixpkgs/stable/#module-system-lib-evalModules-param-class) for which the `nixpkgs` repository has user-importable modules. + +Exceptions: +- `_class = "nixos";` modules go in the `/nixos/modules` tree +- modules whose only purpose is to test code in this repository + +The emphasis is on _importable_ modules, i.e. ones that aren't inherent to and built into the Module System application. diff --git a/modules/generic/meta-maintainers.nix b/modules/generic/meta-maintainers.nix new file mode 100644 index 000000000000..fb66174cf621 --- /dev/null +++ b/modules/generic/meta-maintainers.nix @@ -0,0 +1,63 @@ +# Test: +# ./meta-maintainers/test.nix +{ lib, ... }: +let + inherit (lib) + mkOption + mkOptionType + types + ; + + maintainer = mkOptionType { + name = "maintainer"; + check = email: lib.elem email (lib.attrValues lib.maintainers); + merge = loc: defs: { + # lib.last: Perhaps this could be merged instead, if "at most once per module" + # is a problem (see option description). + ${(lib.last defs).file} = (lib.last defs).value; + }; + }; + + listOfMaintainers = types.listOf maintainer // { + merge = + loc: defs: + lib.zipAttrs ( + lib.flatten ( + lib.imap1 ( + n: def: + lib.imap1 ( + m: def': + maintainer.merge (loc ++ [ "[${toString n}-${toString m}]" ]) [ + { + inherit (def) file; + value = def'; + } + ] + ) def.value + ) defs + ) + ); + }; +in +{ + _class = null; # not specific to NixOS + options = { + meta = { + maintainers = mkOption { + type = listOfMaintainers; + default = [ ]; + example = lib.literalExpression ''[ lib.maintainers.alice lib.maintainers.bob ]''; + description = '' + List of maintainers of each module. + This option should be defined at most once per module. + + The option value is not a list of maintainers, but an attribute set that maps module file names to lists of maintainers. + ''; + }; + }; + }; + meta.maintainers = with lib.maintainers; [ + pierron + roberth + ]; +} diff --git a/modules/generic/meta-maintainers/test.nix b/modules/generic/meta-maintainers/test.nix new file mode 100644 index 000000000000..73a431c34327 --- /dev/null +++ b/modules/generic/meta-maintainers/test.nix @@ -0,0 +1,34 @@ +# Run: +# $ nix-instantiate --eval 'modules/generic/meta-maintainers/test.nix' +# +# Expected output: +# { } +# +# Debugging: +# drop .test from the end of this file, then use nix repl on it +rec { + lib = import ../../../lib; + + example = lib.evalModules { + modules = [ + ../meta-maintainers.nix + { + _file = "eelco.nix"; + meta.maintainers = [ lib.maintainers.eelco ]; + } + ]; + }; + + test = + assert + example.config.meta.maintainers == { + ${toString ../meta-maintainers.nix} = [ + lib.maintainers.pierron + lib.maintainers.roberth + ]; + "eelco.nix" = [ lib.maintainers.eelco ]; + }; + { }; + +} +.test