Skip to content

Commit

Permalink
Merge master into staging-next
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Dec 9, 2024
2 parents 2ed552b + f602946 commit ceb6272
Show file tree
Hide file tree
Showing 92 changed files with 2,163 additions and 12,660 deletions.
6 changes: 3 additions & 3 deletions doc/build-helpers/images/dockertools.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ dockerTools.pullImage {
imageDigest = "sha256:b8ea88f763f33dfda2317b55eeda3b1a4006692ee29e60ee54ccf6d07348c598";
finalImageName = "nix";
finalImageTag = "2.19.3";
sha256 = "zRwlQs1FiKrvHPaf8vWOR/Tlp1C5eLn1d9pE4BZg3oA=";
hash = "sha256-zRwlQs1FiKrvHPaf8vWOR/Tlp1C5eLn1d9pE4BZg3oA=";
}
```
:::
Expand All @@ -898,7 +898,7 @@ dockerTools.pullImage {
imageDigest = "sha256:24a23053f29266fb2731ebea27f915bb0fb2ae1ea87d42d890fe4e44f2e27c5d";
finalImageName = "etcd";
finalImageTag = "v3.5.11";
sha256 = "Myw+85f2/EVRyMB3axECdmQ5eh9p1q77FWYKy8YpRWU=";
hash = "sha256-Myw+85f2/EVRyMB3axECdmQ5eh9p1q77FWYKy8YpRWU=";
}
```
:::
Expand All @@ -922,7 +922,7 @@ Writing manifest to image destination
{
imageName = "nixos/nix";
imageDigest = "sha256:498fa2d7f2b5cb3891a4edf20f3a8f8496e70865099ba72540494cd3e2942634";
sha256 = "1q6cf2pdrasa34zz0jw7pbs6lvv52rq2aibgxccbwcagwkg2qj1q";
hash = "sha256-OEgs3uRPMb4Y629FJXAWZW9q9LqHS/A/GUqr3K5wzOA=";
finalImageName = "nixos/nix";
finalImageTag = "latest";
}
Expand Down
19 changes: 8 additions & 11 deletions lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -420,20 +420,17 @@ rec {
Placeholders will not be quoted as they are not actual values:
(showOption ["foo" "*" "bar"]) == "foo.*.bar"
(showOption ["foo" "<name>" "bar"]) == "foo.<name>.bar"
(showOption ["foo" "<myPlaceholder>" "bar"]) == "foo.<myPlaceholder>.bar"
*/
showOption = parts: let
# If the part is a named placeholder of the form "<...>" don't escape it.
# It may cause misleading escaping if somebody uses literally "<...>" in their option names.
# This is the trade-off to allow for placeholders in option names.
isNamedPlaceholder = builtins.match "\<(.*)\>";
escapeOptionPart = part:
let
# We assume that these are "special values" and not real configuration data.
# If it is real configuration data, it is rendered incorrectly.
specialIdentifiers = [
"<name>" # attrsOf (submodule {})
"*" # listOf (submodule {})
"<function body>" # functionTo
];
in if builtins.elem part specialIdentifiers
then part
else lib.strings.escapeNixIdentifier part;
if part == "*" || isNamedPlaceholder part != null
then part
else lib.strings.escapeNixIdentifier part;
in (concatStringsSep ".") (map escapeOptionPart parts);
showFiles = files: concatStringsSep " and " (map (f: "`${f}'") files);

Expand Down
38 changes: 38 additions & 0 deletions lib/tests/misc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,44 @@ runTests {
expected = [ [ "_module" "args" ] [ "foo" ] [ "foo" "<name>" "bar" ] [ "foo" "bar" ] ];
};

testAttrsWithName = {
expr = let
eval = evalModules {
modules = [
{
options = {
foo = lib.mkOption {
type = lib.types.attrsWith {
placeholder = "MyCustomPlaceholder";
elemType = lib.types.submodule {
options.bar = lib.mkOption {
type = lib.types.int;
default = 42;
};
};
};
};
};
}
];
};
opt = eval.options.foo;
in
(opt.type.getSubOptions opt.loc).bar.loc;
expected = [
"foo"
"<MyCustomPlaceholder>"
"bar"
];
};

testShowOptionWithPlaceholder = {
# <name>, *, should not be escaped. It is used as a placeholder by convention.
# Other symbols should be escaped. `{}`
expr = lib.showOption ["<name>" "<myName>" "*" "{foo}"];
expected = "<name>.<myName>.*.\"{foo}\"";
};

testCartesianProductOfEmptySet = {
expr = cartesianProduct {};
expected = [ {} ];
Expand Down
7 changes: 7 additions & 0 deletions lib/tests/modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ checkConfigOutput '^420$' config.bare-submodule.deep ./declare-bare-submodule.ni
checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./define-shorthandOnlyDefinesConfig-true.nix
checkConfigError 'The option .bare-submodule.deep. in .*/declare-bare-submodule-deep-option.nix. is already declared in .*/declare-bare-submodule-deep-option-duplicate.nix' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./declare-bare-submodule-deep-option-duplicate.nix

# Check that strMatching can be merged
checkConfigOutput '^"strMatching.*"$' options.sm.type.name ./strMatching-merge.nix

# Check integer types.
# unsigned
checkConfigOutput '^42$' config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix
Expand Down Expand Up @@ -391,6 +394,10 @@ checkConfigError 'The option `mergedLazyNonLazy'\'' in `.*'\'' is already declar
checkConfigOutput '^11$' config.lazyResult ./lazy-attrsWith.nix
checkConfigError 'infinite recursion encountered' config.nonLazyResult ./lazy-attrsWith.nix

# AttrsWith placeholder tests
checkConfigOutput '^"mergedName.<id>.nested"$' config.result ./name-merge-attrsWith-1.nix
checkConfigError 'The option .mergedName. in .*\.nix. is already declared in .*\.nix' config.mergedName ./name-merge-attrsWith-2.nix

# Even with multiple assignments, a type error should be thrown if any of them aren't valid
checkConfigError 'A definition for option .* is not of type .*' \
config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix
Expand Down
51 changes: 51 additions & 0 deletions lib/tests/modules/name-merge-attrsWith-1.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{ lib, ... }:
let
inherit (lib) types mkOption;
in
{
imports = [
# Module A
(
{ ... }:
{
options.mergedName = mkOption {
default = { };
type = types.attrsWith {
placeholder = "id"; # <- This is beeing tested
elemType = types.submodule {
options.nested = mkOption {
type = types.int;
default = 1;
};
};
};
};
}
)
# Module B
(
{ ... }:
{
# defines the default placeholder "name"
# type merging should resolve to "id"
options.mergedName = mkOption {
type = types.attrsOf (types.submodule { });
};
}
)

# Output
(
{
options,
...
}:
{
options.result = mkOption {
default = lib.concatStringsSep "." (options.mergedName.type.getSubOptions options.mergedName.loc)
.nested.loc;
};
}
)
];
}
38 changes: 38 additions & 0 deletions lib/tests/modules/name-merge-attrsWith-2.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{ lib, ... }:
let
inherit (lib) types mkOption;
in
{
imports = [
# Module A
(
{ ... }:
{
options.mergedName = mkOption {
default = { };
type = types.attrsWith {
placeholder = "id"; # <- this is beeing tested
elemType = types.submodule {
options.nested = mkOption {
type = types.int;
default = 1;
};
};
};
};
}
)
# Module B
(
{ ... }:
{
options.mergedName = mkOption {
type = types.attrsWith {
placeholder = "other"; # <- define placeholder = "other" (conflict)
elemType = types.submodule { };
};
};
}
)
];
}
15 changes: 15 additions & 0 deletions lib/tests/modules/strMatching-merge.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ lib, ... }:
{
imports = [
{
options.sm = lib.mkOption {
type = lib.types.strMatching "\(.*\)";
};
}
{
options.sm = lib.mkOption {
type = lib.types.strMatching "\(.*\)";
};
}
];
}
38 changes: 29 additions & 9 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ rec {
descriptionClass = "noun";
check = x: str.check x && builtins.match pattern x != null;
inherit (str) merge;
functor = defaultFunctor "strMatching" // {
type = payload: strMatching payload.pattern;
payload = { inherit pattern; };
binOp = lhs: rhs: if lhs == rhs then lhs else null;
};
};

# Merge multiple definitions by concatenating them (with the given
Expand All @@ -475,9 +480,10 @@ rec {
check = isString;
merge = loc: defs: concatStringsSep sep (getValues defs);
functor = (defaultFunctor name) // {
payload = sep;
binOp = sepLhs: sepRhs:
if sepLhs == sepRhs then sepLhs
payload = { inherit sep; };
type = payload: types.separatedString payload.sep;
binOp = lhs: rhs:
if lhs.sep == rhs.sep then { inherit (lhs) sep; }
else null;
};
};
Expand Down Expand Up @@ -608,17 +614,27 @@ rec {
lhs.lazy
else
null;
placeholder =
if lhs.placeholder == rhs.placeholder then
lhs.placeholder
else if lhs.placeholder == "name" then
rhs.placeholder
else if rhs.placeholder == "name" then
lhs.placeholder
else
null;
in
if elemType == null || lazy == null then
if elemType == null || lazy == null || placeholder == null then
null
else
{
inherit elemType lazy;
inherit elemType lazy placeholder;
};
in
{
elemType,
lazy ? false,
placeholder ? "name",
}:
mkOptionType {
name = if lazy then "lazyAttrsOf" else "attrsOf";
Expand All @@ -645,16 +661,16 @@ rec {
(pushPositions defs)))
);
emptyValue = { value = {}; };
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name>"]);
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<${placeholder}>"]);
getSubModules = elemType.getSubModules;
substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit lazy; };
substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit lazy placeholder; };
functor = defaultFunctor "attrsWith" // {
wrappedDeprecationMessage = { loc }: lib.warn ''
The deprecated `type.functor.wrapped` attribute of the option `${showOption loc}` is accessed, use `type.nestedTypes.elemType` instead.
'' elemType;
payload = {
# Important!: Add new function attributes here in case of future changes
inherit elemType lazy;
inherit elemType lazy placeholder;
};
inherit binOp;
};
Expand Down Expand Up @@ -1014,7 +1030,11 @@ rec {
else "conjunction";
check = flip elem values;
merge = mergeEqualOption;
functor = (defaultFunctor name) // { payload = values; binOp = a: b: unique (a ++ b); };
functor = (defaultFunctor name) // {
payload = { inherit values; };
type = payload: types.enum payload.values;
binOp = a: b: { values = unique (a.values ++ b.values); };
};
};

# Either value of type `t1` or `t2`.
Expand Down
13 changes: 12 additions & 1 deletion maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7335,6 +7335,17 @@
githubId = 1633361;
name = "Iztok Fister Jr.";
};
FirelightFlagboy = {
email = "[email protected]";
github = "FirelightFlagboy";
githubId = 30697622;
name = "Firelight Flagboy";
keys = [
{
fingerprint = "D6E2 4BD5 680C 609D D146 99B4 4304 CE0B A5E8 67D1";
}
];
};
FireyFly = {
email = "[email protected]";
github = "FireyFly";
Expand Down Expand Up @@ -10263,7 +10274,7 @@
name = "jdev082";
};
jdreaver = {
email = "johndreaver@gmail.com";
email = "me@davidreaver.com";
github = "jdreaver";
githubId = 1253071;
name = "David Reaver";
Expand Down
10 changes: 9 additions & 1 deletion nixos/doc/manual/development/option-types.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ Composed types are types that take a type as parameter. `listOf
returned instead for the same `mkIf false` definition.
:::

`types.attrsWith` { *`elemType`*, *`lazy`* ? false }
`types.attrsWith` { *`elemType`*, *`lazy`* ? false, *`placeholder`* ? "name" }

: An attribute set of where all the values are of *`elemType`* type.

Expand All @@ -411,10 +411,18 @@ Composed types are types that take a type as parameter. `listOf
`lazy`
: Determines whether the attribute set is lazily evaluated. See: `types.lazyAttrsOf`

`placeholder` (`String`, default: `name` )
: Placeholder string in documentation for the attribute names.
The default value `name` results in the placeholder `<name>`

**Behavior**

- `attrsWith { elemType = t; }` is equivalent to `attrsOf t`
- `attrsWith { lazy = true; elemType = t; }` is equivalent to `lazyAttrsOf t`
- `attrsWith { placeholder = "id"; elemType = t; }`

Displays the option as `foo.<id>` in the manual.


`types.uniq` *`t`*

Expand Down
6 changes: 6 additions & 0 deletions nixos/doc/manual/redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,12 @@
"sec-release-25.05-notable-changes": [
"release-notes.html#sec-release-25.05-notable-changes"
],
"sec-release-25.05-lib": [
"release-notes.html#sec-release-25.05-lib"
],
"sec-release-25.05-lib-breaking": [
"release-notes.html#sec-release-25.05-lib-breaking"
],
"sec-release-24.11": [
"release-notes.html#sec-release-24.11"
],
Expand Down
8 changes: 8 additions & 0 deletions nixos/doc/manual/release-notes/rl-2505.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,11 @@
- `bind.cacheNetworks` now only controls access for recursive queries, where it previously controlled access for all queries.

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->

## Nixpkgs Library {#sec-release-25.05-lib}

### Breaking changes {#sec-release-25.05-lib-breaking}

- Structure of the `functor` of some types has changed. `functor` is an implementation detail and should not be relied upon. If you did rely on it let us know in this [PR](https://github.com/NixOS/nixpkgs/pull/363565).
- [`lib.types.enum`](https://nixos.org/manual/nixos/unstable/#sec-option-types-basic): Previously the `functor.payload` was the list of enum values directly. Now it is an attribute set containing the values in the `values` attribute.
- [`lib.types.separatedString`](https://nixos.org/manual/nixos/unstable/#sec-option-types-string): Previously the `functor.payload` was the seperator directly. Now it is an attribute set containing the seperator in the `sep` attribute.
Loading

0 comments on commit ceb6272

Please sign in to comment.