Unverified Commit 4f1d724b authored by Silvan Mosberger's avatar Silvan Mosberger Committed by GitHub
Browse files

Merge pull request #284551 from hercules-ci/types-attrTag

Add `types.attrTag`
parents 40d82296 35fe5383
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ let
      canCleanSource pathIsGitRepo;
    inherit (self.modules) evalModules setDefaultModuleLocation
      unifyModuleSyntax applyModuleArgsIfFunction mergeModules
      mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions
      mergeModules' mergeOptionDecls mergeDefinitions
      pushDownProperties dischargeProperties filterOverrides
      sortProperties fixupOptionType mkIf mkAssert mkMerge mkOverride
      mkOptionDefault mkDefault mkImageMediaOverride mkForce mkVMOverride
@@ -138,6 +138,7 @@ let
      mkMergedOptionModule mkChangedOptionModule
      mkAliasOptionModule mkDerivedConfig doRename
      mkAliasOptionModuleMD;
    evalOptionValue = lib.warn "External use of `lib.evalOptionValue` is deprecated. If your use case isn't covered by non-deprecated functions, we'd like to know more and perhaps support your use case well, instead of providing access to these low level functions. In this case please open an issue in https://github.com/nixos/nixpkgs/issues/." self.modules.evalOptionValue;
    inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions
      mergeDefaultOption mergeOneOption mergeEqualOption mergeUniqueOption
      getValues getFiles
+1 −1
Original line number Diff line number Diff line
@@ -1378,7 +1378,6 @@ let
      inherit
        applyModuleArgsIfFunction
        dischargeProperties
        evalOptionValue
        mergeModules
        mergeModules'
        pushDownProperties
@@ -1399,6 +1398,7 @@ private //
    defaultPriority
    doRename
    evalModules
    evalOptionValue  # for use by lib.types
    filterOverrides
    filterOverrides'
    fixMergeModules
+12 −0
Original line number Diff line number Diff line
@@ -103,6 +103,18 @@ checkConfigError 'The option .sub.wrong2. does not exist. Definition values:' co
checkConfigError '.*This can happen if you e.g. declared your options in .types.submodule.' config.sub ./error-mkOption-in-submodule-config.nix
checkConfigError '.*A definition for option .bad. is not of type .non-empty .list of .submodule...\.' config.bad ./error-nonEmptyListOf-submodule.nix

# types.attrTag
checkConfigOutput '^true$' config.okChecks ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.syntaxError. is not of type .attribute-tagged union' config.intStrings.syntaxError ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.syntaxError2. is not of type .attribute-tagged union' config.intStrings.syntaxError2 ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.syntaxError3. is not of type .attribute-tagged union' config.intStrings.syntaxError3 ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.syntaxError4. is not of type .attribute-tagged union' config.intStrings.syntaxError4 ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.mergeError. is not of type .attribute-tagged union' config.intStrings.mergeError ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.badTagError. is not of type .attribute-tagged union' config.intStrings.badTagError ./types-attrTag.nix
checkConfigError 'A definition for option .intStrings\.badTagTypeError\.left. is not of type .signed integer.' config.intStrings.badTagTypeError.left ./types-attrTag.nix
checkConfigError 'A definition for option .nested\.right\.left. is not of type .signed integer.' config.nested.right.left ./types-attrTag.nix
checkConfigError 'In attrTag, each tag value must be an option, but tag int was a bare type, not wrapped in mkOption.' config.opt.int ./types-attrTag-wrong-decl.nix

# types.pathInStore
checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./types.nix
checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15"' config.pathInStore.ok2 ./types.nix
+41 −0
Original line number Diff line number Diff line
/*
  A basic documentation generating module.
  Declares and defines a `docs` option, suitable for making assertions about
  the extraction "phase" of documentation generation.
 */
{ lib, options, ... }:

let
  inherit (lib)
    head
    length
    mkOption
    types
  ;

  traceListSeq = l: v: lib.foldl' (a: b: lib.traceSeq b a) v l;

in

{
  options.docs = mkOption {
    type = types.lazyAttrsOf types.raw;
    description = ''
      All options to be rendered, without any visibility filtering applied.
    '';
  };
  config.docs =
    lib.zipAttrsWith
      (name: values:
        if length values > 1 then
          traceListSeq values
          abort "Multiple options with the same name: ${name}"
        else
          assert length values == 1;
          head values
      )
      (map
        (opt: { ${opt.name} = opt; })
        (lib.optionAttrSetToDocList options)
      );
}
+14 −0
Original line number Diff line number Diff line
{ lib, ... }:
let
  inherit (lib) types mkOption;
in
{
  options = {
    opt = mkOption {
      type = types.attrTag {
        int = types.int;
      };
      default = { int = 1; };
    };
  };
}
Loading