treewide: format all inactive Nix files

After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
This commit is contained in:
Silvan Mosberger
2024-12-10 20:26:33 +01:00
parent b32a094368
commit 4f0dadbf38
21293 changed files with 701276 additions and 428232 deletions
@@ -1,5 +1,9 @@
{ lib, ... }: {
options.dummy = lib.mkOption { type = lib.types.anything; default = {}; };
{ lib, ... }:
{
options.dummy = lib.mkOption {
type = lib.types.anything;
default = { };
};
freeformType =
let
a = lib.types.attrsOf (lib.types.submodule { options.bar = lib.mkOption { }; });
@@ -7,7 +11,8 @@
# modifying types like this breaks type merging.
# This test makes sure that type merging is not performed when only a single declaration exists.
# Don't modify types in practice!
a // {
a
// {
merge = loc: defs: { freeformItems = a.merge loc defs; };
};
config.foo.bar = "ok";
@@ -30,7 +30,7 @@ in
# mkAliasOptionModule sets warnings, so this has to be defined.
warnings = mkOption {
internal = true;
default = [];
default = [ ];
type = types.listOf types.str;
example = [ "The `foo' service is deprecated and will go away soon!" ];
description = ''
@@ -46,14 +46,16 @@ in
# Disable the aliased option with a high priority so it
# should override the next import.
( { config, lib, ... }:
(
{ config, lib, ... }:
{
enableAlias = mkForce false;
}
)
# Enable the normal (non-aliased) option.
( { config, lib, ... }:
(
{ config, lib, ... }:
{
enable = true;
}
+5 -3
View File
@@ -30,7 +30,7 @@ in
# mkAliasOptionModule sets warnings, so this has to be defined.
warnings = mkOption {
internal = true;
default = [];
default = [ ];
type = types.listOf types.str;
example = [ "The `foo' service is deprecated and will go away soon!" ];
description = ''
@@ -46,14 +46,16 @@ in
# Disable the aliased option, but with a default (low) priority so it
# should be able to be overridden by the next import.
( { config, lib, ... }:
(
{ config, lib, ... }:
{
enableAlias = mkDefault false;
}
)
# Enable the normal (non-aliased) option.
( { config, lib, ... }:
(
{ config, lib, ... }:
{
enable = true;
}
@@ -1,6 +1,7 @@
{ lib, config, ... }: {
{ lib, config, ... }:
{
options.conditionalWorks = lib.mkOption {
default = ! config.value ? foo;
default = !config.value ? foo;
};
config.value.foo = lib.mkIf false "should not be defined";
+3 -2
View File
@@ -1,6 +1,7 @@
{ lib, config, ... }: {
{ lib, config, ... }:
{
options.isLazy = lib.mkOption {
default = ! config.value ? foo;
default = !config.value ? foo;
};
config.value.bar = throw "is not lazy";
+18 -6
View File
@@ -1,14 +1,26 @@
{ lib, ... }: {
{ lib, ... }:
{
options.value = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.boolByOr;
};
config.value = {
falseFalse = lib.mkMerge [ false false ];
trueFalse = lib.mkMerge [ true false ];
falseTrue = lib.mkMerge [ false true ];
trueTrue = lib.mkMerge [ true true ];
falseFalse = lib.mkMerge [
false
false
];
trueFalse = lib.mkMerge [
true
false
];
falseTrue = lib.mkMerge [
false
true
];
trueTrue = lib.mkMerge [
true
true
];
};
}
+33 -30
View File
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options = {
sub = {
nixosOk = lib.mkOption {
@@ -40,37 +41,39 @@
];
config = {
_module.freeformType = lib.types.anything;
ok =
lib.evalModules {
class = "nixos";
modules = [
./module-class-is-nixos.nix
];
};
ok = lib.evalModules {
class = "nixos";
modules = [
./module-class-is-nixos.nix
];
};
fail =
lib.evalModules {
class = "nixos";
modules = [
./module-class-is-nixos.nix
./module-class-is-darwin.nix
];
};
fail = lib.evalModules {
class = "nixos";
modules = [
./module-class-is-nixos.nix
./module-class-is-darwin.nix
];
};
fail-anon =
lib.evalModules {
class = "nixos";
modules = [
./module-class-is-nixos.nix
{ _file = "foo.nix#darwinModules.default";
_class = "darwin";
config = {};
imports = [];
}
];
};
fail-anon = lib.evalModules {
class = "nixos";
modules = [
./module-class-is-nixos.nix
{
_file = "foo.nix#darwinModules.default";
_class = "darwin";
config = { };
imports = [ ];
}
];
};
sub.nixosOk = { _class = "nixos"; };
sub.nixosFail = { imports = [ ./module-class-is-darwin.nix ]; };
sub.nixosOk = {
_class = "nixos";
};
sub.nixosFail = {
imports = [ ./module-class-is-darwin.nix ];
};
};
}
+4 -4
View File
@@ -1,13 +1,13 @@
{ lib, ... }:
let
deathtrapArgs = lib.mapAttrs
(k: _: throw "The module system is too strict, accessing an unused option's ${k} mkOption-attribute.")
(lib.functionArgs lib.mkOption);
deathtrapArgs = lib.mapAttrs (
k: _: throw "The module system is too strict, accessing an unused option's ${k} mkOption-attribute."
) (lib.functionArgs lib.mkOption);
in
{
options.value = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
default = {};
default = { };
};
options.testing-laziness-so-don't-read-me = lib.mkOption deathtrapArgs;
}
@@ -1,25 +1,27 @@
{ lib, ... }:
let
submod = { ... }: {
options = {
enable = lib.mkOption {
default = false;
example = true;
type = lib.types.bool;
description = ''
Some descriptive text
'';
submod =
{ ... }:
{
options = {
enable = lib.mkOption {
default = false;
example = true;
type = lib.types.bool;
description = ''
Some descriptive text
'';
};
};
};
};
in
{
options = {
attrsOfSub = lib.mkOption {
default = {};
example = {};
default = { };
example = { };
type = lib.types.attrsOf (lib.types.submodule [ submod ]);
description = ''
Some descriptive text
+1 -1
View File
@@ -8,7 +8,7 @@ in
modules = [ ];
shorthandOnlyDefinesConfig = config.shorthandOnlyDefinesConfig;
};
default = {};
default = { };
};
# config-dependent options: won't recommend, but useful for making this test parameterized
+2 -1
View File
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options.value = lib.mkOption {
type = lib.types.either lib.types.int lib.types.str;
};
+3 -2
View File
@@ -1,6 +1,7 @@
{ lib, ... }: {
{ lib, ... }:
{
options.value = lib.mkOption {
type = lib.types.lazyAttrsOf (lib.types.str // { emptyValue.value = "empty"; });
default = {};
default = { };
};
}
+13 -5
View File
@@ -1,9 +1,11 @@
{ lib, ... }: let
{ lib, ... }:
let
pkgs.hello = {
type = "derivation";
pname = "hello";
};
in {
in
{
options = {
package = lib.mkPackageOption pkgs "hello" { };
@@ -46,8 +48,14 @@ in {
pkgsText = "myPkgs";
};
packageFromOtherSet = let myPkgs = {
hello = pkgs.hello // { pname = "hello-other"; };
}; in lib.mkPackageOption myPkgs "hello" { };
packageFromOtherSet =
let
myPkgs = {
hello = pkgs.hello // {
pname = "hello-other";
};
};
in
lib.mkPackageOption myPkgs "hello" { };
};
}
+2 -1
View File
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options.value = lib.mkOption {
type = lib.types.oneOf [
lib.types.int
+3 -1
View File
@@ -3,7 +3,9 @@
{
options.set = lib.mkOption {
default = { };
example = { a = 1; };
example = {
a = 1;
};
type = lib.types.attrsOf lib.types.int;
description = ''
Some descriptive text
@@ -1,25 +1,32 @@
{ lib, ... }: {
{ lib, ... }:
{
options.submodule = lib.mkOption {
inherit (lib.evalModules {
modules = [
{
options.inner = lib.mkOption {
type = lib.types.bool;
default = false;
};
}
];
}) type;
default = {};
inherit
(lib.evalModules {
modules = [
{
options.inner = lib.mkOption {
type = lib.types.bool;
default = false;
};
}
];
})
type
;
default = { };
};
config.submodule = lib.mkMerge [
({ lib, ... }: {
options.outer = lib.mkOption {
type = lib.types.bool;
default = false;
};
})
(
{ lib, ... }:
{
options.outer = lib.mkOption {
type = lib.types.bool;
default = false;
};
}
)
{
inner = true;
outer = true;
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options.submodule = lib.mkOption {
type = lib.types.submoduleWith {
modules = [
@@ -10,16 +11,19 @@
}
];
};
default = {};
default = { };
};
config.submodule = lib.mkMerge [
({ lib, ... }: {
options.outer = lib.mkOption {
type = lib.types.bool;
default = false;
};
})
(
{ lib, ... }:
{
options.outer = lib.mkOption {
type = lib.types.bool;
default = false;
};
}
)
{
inner = true;
outer = true;
@@ -1,13 +1,15 @@
{ lib, ... }: let
{ lib, ... }:
let
sub.options.config = lib.mkOption {
type = lib.types.bool;
default = false;
};
in {
in
{
options.submodule = lib.mkOption {
type = lib.types.submoduleWith {
modules = [ sub ];
};
default = {};
default = { };
};
}
@@ -1,11 +1,12 @@
{ lib, ... }: {
{ lib, ... }:
{
options.submodule = lib.mkOption {
type = lib.types.submoduleWith {
modules = [
./declare-enable.nix
];
};
default = {};
default = { };
};
config.submodule = ./define-enable.nix;
@@ -1,14 +1,16 @@
{ lib, ... }: let
{ lib, ... }:
let
sub.options.config = lib.mkOption {
type = lib.types.bool;
default = false;
};
in {
in
{
options.submodule = lib.mkOption {
type = lib.types.submoduleWith {
modules = [ sub ];
shorthandOnlyDefinesConfig = true;
};
default = {};
default = { };
};
}
@@ -1,17 +1,21 @@
{ lib, ... }: {
{ lib, ... }:
{
options.submodule = lib.mkOption {
type = lib.types.submoduleWith {
modules = [
({ lib, ... }: {
options.foo = lib.mkOption {
default = lib.foo;
};
})
(
{ lib, ... }:
{
options.foo = lib.mkOption {
default = lib.foo;
};
}
)
];
specialArgs.lib = lib // {
foo = "foo";
};
};
default = {};
default = { };
};
}
+3 -2
View File
@@ -1,9 +1,10 @@
{ lib, moduleType, ... }:
let inherit (lib) mkOption types;
let
inherit (lib) mkOption types;
in
{
options.variants = mkOption {
type = types.lazyAttrsOf moduleType;
default = {};
default = { };
};
}
+12 -5
View File
@@ -1,8 +1,15 @@
{ lib ? import ../.., modules ? [] }:
{
lib ? import ../..,
modules ? [ ],
}:
{
inherit (lib.evalModules {
inherit modules;
specialArgs.modulesPath = ./.;
}) config options;
inherit
(lib.evalModules {
inherit modules;
specialArgs.modulesPath = ./.;
})
config
options
;
}
+16 -3
View File
@@ -1,7 +1,19 @@
{ config, lib, ... }:
let
inherit (lib) types mkOption setDefaultModuleLocation evalModules;
inherit (types) deferredModule lazyAttrsOf submodule str raw enum;
inherit (lib)
types
mkOption
setDefaultModuleLocation
evalModules
;
inherit (types)
deferredModule
lazyAttrsOf
submodule
str
raw
enum
;
in
{
options = {
@@ -13,7 +25,8 @@ in
};
};
config = {
deferred = { ... }:
deferred =
{ ... }:
# this should be an attrset, so this fails
true;
};
+41 -22
View File
@@ -1,7 +1,14 @@
{ lib, ... }:
let
inherit (lib) types mkOption setDefaultModuleLocation;
inherit (types) deferredModule lazyAttrsOf submodule str raw enum;
inherit (types)
deferredModule
lazyAttrsOf
submodule
str
raw
enum
;
in
{
imports = [
@@ -9,27 +16,37 @@ in
# - nodes.<name>
# - default
# where all nodes include the default
({ config, ... }: {
_file = "generic.nix";
options.nodes = mkOption {
type = lazyAttrsOf (submodule { imports = [ config.default ]; });
default = {};
};
options.default = mkOption {
type = deferredModule;
default = { };
description = ''
Module that is included in all nodes.
'';
};
})
(
{ config, ... }:
{
_file = "generic.nix";
options.nodes = mkOption {
type = lazyAttrsOf (submodule {
imports = [ config.default ];
});
default = { };
};
options.default = mkOption {
type = deferredModule;
default = { };
description = ''
Module that is included in all nodes.
'';
};
}
)
{
_file = "default-1.nix";
default = { config, ... }: {
options.settingsDict = lib.mkOption { type = lazyAttrsOf str; default = {}; };
options.bottom = lib.mkOption { type = enum []; };
};
default =
{ config, ... }:
{
options.settingsDict = lib.mkOption {
type = lazyAttrsOf str;
default = { };
};
options.bottom = lib.mkOption { type = enum [ ]; };
};
}
{
@@ -49,9 +66,11 @@ in
{
_file = "nodes-foo-c-is-a.nix";
nodes.foo = { config, ... }: {
settingsDict.c = config.settingsDict.a;
};
nodes.foo =
{ config, ... }:
{
settingsDict.c = config.settingsDict.a;
};
}
];
+1 -1
View File
@@ -1,3 +1,3 @@
{
attrsOfSub.bar = {};
attrsOfSub.bar = { };
}
+1 -1
View File
@@ -1,3 +1,3 @@
{
attrsOfSub.foo = {};
attrsOfSub.foo = { };
}
@@ -1,15 +1,24 @@
{ config, ... }: {
class = { "just" = "data"; };
{ config, ... }:
{
class = {
"just" = "data";
};
a = "one";
b = "two";
meta = "meta";
_module.args.result =
let r = builtins.removeAttrs config [ "_module" ];
in builtins.trace (builtins.deepSeq r r) (r == {
a = "one";
b = "two";
class = { "just" = "data"; };
meta = "meta";
});
let
r = builtins.removeAttrs config [ "_module" ];
in
builtins.trace (builtins.deepSeq r r) (
r == {
a = "one";
b = "two";
class = {
"just" = "data";
};
meta = "meta";
}
);
}
@@ -5,12 +5,13 @@
{
# Always defined, but the value depends on the presence of an option.
config.set = {
value = if options ? set.enable then 360 else 7;
}
# Only define if possible.
// lib.optionalAttrs (options ? set.enable) {
enable = true;
};
config.set =
{
value = if options ? set.enable then 360 else 7;
}
# Only define if possible.
// lib.optionalAttrs (options ? set.enable) {
enable = true;
};
}
@@ -5,12 +5,13 @@
{
# Always defined, but the value depends on the presence of an option.
config = {
value = if options ? enable then 360 else 7;
}
# Only define if possible.
// lib.optionalAttrs (options ? enable) {
enable = true;
};
config =
{
value = if options ? enable then 360 else 7;
}
# Only define if possible.
// lib.optionalAttrs (options ? enable) {
enable = true;
};
}
@@ -1,3 +1,4 @@
{ config, ... }: {
{ config, ... }:
{
settingsDict.a = config.settingsDict.b;
}
+1 -1
View File
@@ -1,3 +1,3 @@
{
value = [];
value = [ ];
}
@@ -1,8 +1,11 @@
{ lib, ... }: {
{ lib, ... }:
{
imports = [{
value = lib.mkDefault "def";
}];
imports = [
{
value = lib.mkDefault "def";
}
];
value = lib.mkMerge [
(lib.mkIf false "nope")
+8 -3
View File
@@ -1,5 +1,6 @@
{ config, lib, ... }:
let inherit (lib) types mkOption attrNames;
let
inherit (lib) types mkOption attrNames;
in
{
options = {
@@ -16,7 +17,11 @@ in
variants.foo.variants.bar.attrs.z = 1;
variants.foo.variants.foo.attrs.c = 3;
resultFoo = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.attrs);
resultFooBar = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.variants.bar.attrs);
resultFooFoo = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.variants.foo.attrs);
resultFooBar = lib.concatMapStringsSep " " toString (
attrNames config.variants.foo.variants.bar.attrs
);
resultFooFoo = lib.concatMapStringsSep " " toString (
attrNames config.variants.foo.variants.foo.attrs
);
};
}
+4 -1
View File
@@ -1,5 +1,8 @@
{ ... }:
{
disabledModules = [ "define-enable.nix" "declare-enable.nix" ];
disabledModules = [
"define-enable.nix"
"declare-enable.nix"
];
}
+6 -4
View File
@@ -2,11 +2,13 @@
let
inherit (lib) mkOption types;
moduleWithKey = { config, ... }: {
config = {
enable = true;
moduleWithKey =
{ config, ... }:
{
config = {
enable = true;
};
};
};
in
{
imports = [
@@ -18,7 +18,7 @@ in
moduleWithKey
];
};
default = {};
default = { };
};
negative = mkOption {
type = types.submodule {
@@ -28,7 +28,7 @@ in
];
disabledModules = [ moduleWithKey ];
};
default = {};
default = { };
};
};
}
@@ -18,7 +18,7 @@ in
moduleWithKey
];
};
default = {};
default = { };
};
negative = mkOption {
type = types.submodule {
@@ -28,7 +28,7 @@ in
];
disabledModules = [ 123 ];
};
default = {};
default = { };
};
};
}
+17 -3
View File
@@ -1,9 +1,23 @@
{ lib, ... }: {
{ lib, ... }:
{
imports = [
(lib.doRename { from = ["a" "b"]; to = ["c" "d" "e"]; warn = true; use = x: x; visible = true; })
(lib.doRename {
from = [
"a"
"b"
];
to = [
"c"
"d"
"e"
];
warn = true;
use = x: x;
visible = true;
})
];
options = {
c.d.e = lib.mkOption {};
c.d.e = lib.mkOption { };
};
config = {
a.b = 1234;
@@ -4,7 +4,12 @@
services.foo.enable = true;
services.foo.bar = "baz";
result =
assert config.services.foos == { "" = { bar = "baz"; }; };
assert
config.services.foos == {
"" = {
bar = "baz";
};
};
true;
};
}
@@ -3,7 +3,12 @@
config = {
services.foos."".bar = "baz";
result =
assert config.services.foos == { "" = { bar = "baz"; }; };
assert
config.services.foos == {
"" = {
bar = "baz";
};
};
assert config.services.foo.bar == "baz";
true;
};
@@ -3,7 +3,7 @@
config = {
result =
assert config.services.foos == { };
assert ! options.services.foo.bar.isDefined;
assert !options.services.foo.bar.isDefined;
true;
};
}
+25 -9
View File
@@ -13,25 +13,41 @@
*/
{ config, lib, ... }:
let
inherit (lib) mkOption mkEnableOption types doRename;
inherit (lib)
mkOption
mkEnableOption
types
doRename
;
in
{
options = {
services.foo.enable = mkEnableOption "foo";
services.foos = mkOption {
type = types.attrsOf (types.submodule {
options = {
bar = mkOption { type = types.str; };
};
});
type = types.attrsOf (
types.submodule {
options = {
bar = mkOption { type = types.str; };
};
}
);
default = { };
};
result = mkOption {};
result = mkOption { };
};
imports = [
(doRename {
from = [ "services" "foo" "bar" ];
to = [ "services" "foos" "" "bar" ];
from = [
"services"
"foo"
"bar"
];
to = [
"services"
"foos"
""
"bar"
];
visible = true;
warn = false;
use = x: x;
+18 -4
View File
@@ -1,11 +1,25 @@
{ lib, config, ... }: {
{ lib, config, ... }:
{
imports = [
(lib.doRename { from = ["a" "b"]; to = ["c" "d" "e"]; warn = true; use = x: x; visible = true; })
(lib.doRename {
from = [
"a"
"b"
];
to = [
"c"
"d"
"e"
];
warn = true;
use = x: x;
visible = true;
})
];
options = {
warnings = lib.mkOption { type = lib.types.listOf lib.types.str; };
c.d.e = lib.mkOption {};
result = lib.mkOption {};
c.d.e = lib.mkOption { };
result = lib.mkOption { };
};
config = {
a.b = 1234;
+10 -16
View File
@@ -2,7 +2,7 @@
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
@@ -11,7 +11,7 @@ let
length
mkOption
types
;
;
traceListSeq = l: v: lib.foldl' (a: b: lib.traceSeq b a) v l;
@@ -24,18 +24,12 @@ in
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)
);
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));
}
+3 -2
View File
@@ -1,7 +1,8 @@
{ lib, ... }:
let
inherit (lib) types;
in {
in
{
options = {
int = lib.mkOption {
@@ -20,7 +21,7 @@ in {
type = types.lazyAttrsOf (types.nullOr types.int);
};
submodule = lib.mkOption {
type = types.lazyAttrsOf (types.submodule {});
type = types.lazyAttrsOf (types.submodule { });
};
};
@@ -5,8 +5,8 @@ in
{
options.sub = lib.mkOption {
type = lib.types.submodule {
wrong2 = mkOption {};
wrong2 = mkOption { };
};
default = {};
default = { };
};
}
@@ -1,6 +1,7 @@
{ lib
, extendModules
, ...
{
lib,
extendModules,
...
}:
let
@@ -17,9 +18,10 @@ in
options.sub = mkOption {
default = { };
type = types.submodule (
{ config
, extendModules
, ...
{
config,
extendModules,
...
}:
{
options.value = mkOption {
@@ -30,11 +32,14 @@ in
default = { };
inherit
(extendModules {
modules = [{
specialisation = mkOverride 0 { };
}];
modules = [
{
specialisation = mkOverride 0 { };
}
];
})
type;
type
;
};
}
);
@@ -43,6 +48,5 @@ in
{ config.sub.value = 1; }
];
}
+2 -1
View File
@@ -1,3 +1,4 @@
{ lib, ... }: {
{ lib, ... }:
{
freeformType = with lib.types; attrsOf (either str (attrsOf str));
}
+2 -1
View File
@@ -1,3 +1,4 @@
{ lib, ... }: {
{ lib, ... }:
{
freeformType = with lib.types; lazyAttrsOf (either str (lazyAttrsOf str));
}
+3 -3
View File
@@ -1,8 +1,8 @@
{ lib, ... }:
let
deathtrapArgs = lib.mapAttrs
(k: _: throw "The module system is too strict, accessing an unused option's ${k} mkOption-attribute.")
(lib.functionArgs lib.mkOption);
deathtrapArgs = lib.mapAttrs (
k: _: throw "The module system is too strict, accessing an unused option's ${k} mkOption-attribute."
) (lib.functionArgs lib.mkOption);
in
{
options.nest.foo = lib.mkOption {
+2 -1
View File
@@ -1,4 +1,5 @@
{ lib, config, ... }: {
{ lib, config, ... }:
{
options.foo = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
+6 -4
View File
@@ -1,17 +1,19 @@
{ lib, options, ... }: with lib.types; {
{ lib, options, ... }:
with lib.types;
{
options.fooDeclarations = lib.mkOption {
default = (options.free.type.getSubOptions [])._freeformOptions.foo.declarations;
default = (options.free.type.getSubOptions [ ])._freeformOptions.foo.declarations;
};
options.free = lib.mkOption {
type = submodule {
config._module.freeformType = lib.mkMerge [
(attrsOf (submodule {
options.foo = lib.mkOption {};
options.foo = lib.mkOption { };
}))
(attrsOf (submodule {
options.bar = lib.mkOption {};
options.bar = lib.mkOption { };
}))
];
};
+2 -1
View File
@@ -1,4 +1,5 @@
{ lib, config, ... }: {
{ lib, config, ... }:
{
options.value = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
+9 -7
View File
@@ -1,8 +1,8 @@
{ lib, config, ... }:
let
inherit (lib) types;
in {
in
{
options = {
fun = lib.mkOption {
type = types.functionTo (types.listOf types.str);
@@ -10,11 +10,13 @@ in {
result = lib.mkOption {
type = types.str;
default = toString (config.fun {
a = "a";
b = "b";
c = "c";
});
default = toString (
config.fun {
a = "a";
b = "b";
c = "c";
}
);
};
};
+11 -6
View File
@@ -1,7 +1,8 @@
{ lib, config, ... }:
let
inherit (lib) types;
in {
in
{
options = {
fun = lib.mkOption {
type = types.functionTo (types.attrsOf types.str);
@@ -9,11 +10,15 @@ in {
result = lib.mkOption {
type = types.str;
default = toString (lib.attrValues (config.fun {
a = "a";
b = "b";
c = "c";
}));
default = toString (
lib.attrValues (
config.fun {
a = "a";
b = "b";
c = "c";
}
)
);
};
};
@@ -1,7 +1,8 @@
{ lib, config, ... }:
let
inherit (lib) types;
in {
in
{
options = {
fun = lib.mkOption {
type = types.functionTo (types.listOf types.str);
@@ -9,11 +10,13 @@ in {
result = lib.mkOption {
type = types.str;
default = toString (config.fun {
a = "a";
b = "b";
c = "c";
});
default = toString (
config.fun {
a = "a";
b = "b";
c = "c";
}
);
};
};
@@ -1,4 +1,9 @@
{ lib, config, options, ... }:
{
lib,
config,
options,
...
}:
let
inherit (lib) types;
in
@@ -6,56 +11,59 @@ in
imports = [
# fun.<function-body>.a
({ ... }: {
options = {
fun = lib.mkOption {
type = types.functionTo (types.submodule {
options.a = lib.mkOption { default = "a"; };
});
(
{ ... }:
{
options = {
fun = lib.mkOption {
type = types.functionTo (
types.submodule {
options.a = lib.mkOption { default = "a"; };
}
);
};
};
};
})
}
)
# fun.<function-body>.b
({ ... }: {
options = {
fun = lib.mkOption {
type = types.functionTo (types.submodule {
options.b = lib.mkOption { default = "b"; };
});
(
{ ... }:
{
options = {
fun = lib.mkOption {
type = types.functionTo (
types.submodule {
options.b = lib.mkOption { default = "b"; };
}
);
};
};
};
})
}
)
];
options = {
result = lib.mkOption
{
type = types.str;
default = lib.concatStringsSep " " (lib.attrValues (config.fun (throw "shouldn't use input param")));
};
result = lib.mkOption {
type = types.str;
default = lib.concatStringsSep " " (
lib.attrValues (config.fun (throw "shouldn't use input param"))
);
};
optionsResult = lib.mkOption
{
type = types.str;
default = lib.concatStringsSep " "
(lib.concatLists
(lib.mapAttrsToList
(k: v:
if k == "_module"
then [ ]
else [ (lib.showOption v.loc) ]
)
(
(options.fun.type.getSubOptions [ "fun" ])
)
)
);
};
optionsResult = lib.mkOption {
type = types.str;
default = lib.concatStringsSep " " (
lib.concatLists (
lib.mapAttrsToList (k: v: if k == "_module" then [ ] else [ (lib.showOption v.loc) ]) (
(options.fun.type.getSubOptions [ "fun" ])
)
)
);
};
};
config.fun = lib.mkMerge
[
(input: { b = "bee"; })
];
config.fun = lib.mkMerge [
(input: { b = "bee"; })
];
}
+2 -1
View File
@@ -1,7 +1,8 @@
{ lib, config, ... }:
let
inherit (lib) types;
in {
in
{
options = {
fun = lib.mkOption {
type = types.functionTo types.str;
+2 -2
View File
@@ -1,8 +1,8 @@
{ lib, config, ... }:
let
inherit (lib) types;
in {
in
{
options = {
fun = lib.mkOption {
type = types.functionTo types.str;
+5 -2
View File
@@ -10,7 +10,7 @@
examples = with lib.gvariant; {
bool = true;
float = 3.14;
int32 = mkInt32 (- 42);
int32 = mkInt32 (-42);
uint32 = mkUint32 42;
int16 = mkInt16 (-42);
uint16 = mkUint16 42;
@@ -24,7 +24,10 @@
escapedString = ''
'\
'';
tuple = mkTuple [ (mkInt32 1) [ "foo" ] ];
tuple = mkTuple [
(mkInt32 1)
[ "foo" ]
];
maybe1 = mkNothing type.string;
maybe2 = mkJust (mkUint32 4);
variant = mkVariant "foo";
+1 -2
View File
@@ -1,6 +1,5 @@
{ lib, custom, ... }:
{
imports = []
++ lib.optional custom ./define-enable-force.nix;
imports = [ ] ++ lib.optional custom ./define-enable-force.nix;
}
-1
View File
@@ -8,4 +8,3 @@
];
}
+2 -2
View File
@@ -33,7 +33,7 @@ in
moduleWithKey
];
};
default = {};
default = { };
};
twice = mkOption {
type = types.submodule {
@@ -43,7 +43,7 @@ in
moduleWithoutKey
];
};
default = {};
default = { };
};
};
}
@@ -1,6 +1,11 @@
{ a ? false, lib, ... }: {
{
a ? false,
lib,
...
}:
{
options = {
result = lib.mkOption {};
result = lib.mkOption { };
};
config = {
_module.args.a = true;
+1 -1
View File
@@ -1,4 +1,4 @@
{
_class = "darwin";
config = {};
config = { };
}
+1 -1
View File
@@ -1,4 +1,4 @@
{
_class = "nixos";
config = {};
config = { };
}
+3 -2
View File
@@ -1,4 +1,5 @@
{ config, lib, ... }: {
{ config, lib, ... }:
{
_file = "optionTypeFile.nix";
@@ -8,7 +9,7 @@
options.theOption = lib.mkOption {
type = config.theType;
default = {};
default = { };
};
config.theType = lib.mkMerge [
+2 -1
View File
@@ -1,4 +1,5 @@
{ config, lib, ... }: {
{ config, lib, ... }:
{
options.theType = lib.mkOption {
type = lib.types.optionType;
@@ -1,6 +1,7 @@
{ lib, ... }: {
{ lib, ... }:
{
options = {
# unlikely mistake, but we can catch any attrset with _type
result = lib.evalModules { modules = []; };
result = lib.evalModules { modules = [ ]; };
};
}
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options = {
result.here = lib.types.str;
};
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options = {
result = lib.types.str;
};
+2 -1
View File
@@ -1,4 +1,5 @@
{ lib, config, ... }: {
{ lib, config, ... }:
{
options = {
processedToplevel = lib.mkOption {
+14 -8
View File
@@ -4,16 +4,22 @@ let
in
{
imports = [
({ config, ... }: {
options = {
meta.foo = mkOption {
type = types.listOf types.str;
(
{ config, ... }:
{
options = {
meta.foo = mkOption {
type = types.listOf types.str;
};
result = mkOption { default = lib.concatStringsSep " " config.meta.foo; };
};
result = mkOption { default = lib.concatStringsSep " " config.meta.foo; };
};
})
}
)
{
meta.foo = [ "one" "two" ];
meta.foo = [
"one"
"two"
];
}
];
}
+10 -7
View File
@@ -15,13 +15,16 @@
};
};
};
config.weird = args@{ ... /* note the lack of a `lib` argument */ }:
assert args.lib == { };
assert args.specialArgs == { lib = { }; };
{
options.foo = lib.mkOption { };
config.foo = lib.mkIf true "alright";
};
config.weird =
args@{
... # note the lack of a `lib` argument
}:
assert args.lib == { };
assert args.specialArgs == { lib = { }; };
{
options.foo = lib.mkOption { };
config.foo = lib.mkIf true "alright";
};
config.result =
assert config.weird.foo == "alright";
"ok";
+14 -8
View File
@@ -1,14 +1,20 @@
{ lib, ... }: {
{ lib, ... }:
{
options.submodule = lib.mkOption {
default = {};
default = { };
type = lib.types.submoduleWith {
modules = [ ({ options, ... }: {
options.value = lib.mkOption {};
modules = [
(
{ options, ... }:
{
options.value = lib.mkOption { };
options.internalFiles = lib.mkOption {
default = options.value.files;
};
})];
options.internalFiles = lib.mkOption {
default = options.value.files;
};
}
)
];
};
};
@@ -2,7 +2,9 @@
let
defs = lib.modules.mergeAttrDefinitionsWithPrio options._module.args;
assertLazy = pos: throw "${pos.file}:${toString pos.line}:${toString pos.column}: The test must not evaluate this the assertLazy thunk, but it did. Unexpected strictness leads to unexpected errors and performance problems.";
assertLazy =
pos:
throw "${pos.file}:${toString pos.line}:${toString pos.column}: The test must not evaluate this the assertLazy thunk, but it did. Unexpected strictness leads to unexpected errors and performance problems.";
in
{
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options.value = lib.mkOption {
type = lib.types.anything;
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options.value = lib.mkOption {
type = lib.types.anything;
@@ -12,7 +13,11 @@
value.path = ./.;
value.null = null;
value.float = 0.1;
value.list = [1 "a" {x=null;}];
value.list = [
1
"a"
{ x = null; }
];
}
{
value.int = 0;
@@ -21,7 +26,11 @@
value.path = ./.;
value.null = null;
value.float = 0.1;
value.list = [1 "a" {x=null;}];
value.list = [
1
"a"
{ x = null; }
];
}
];
@@ -1,4 +1,5 @@
{ lib, config, ... }: {
{ lib, config, ... }:
{
options.valueIsFunction = lib.mkOption {
default = lib.mapAttrs (name: lib.isFunction) config.value;
+2 -1
View File
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options.value = lib.mkOption {
type = lib.types.anything;
+5 -4
View File
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options.value = lib.mkOption {
type = lib.types.anything;
@@ -6,10 +7,10 @@
config = lib.mkMerge [
{
value.mkiffalse = lib.mkIf false {};
value.mkiffalse = lib.mkIf false { };
}
{
value.mkiftrue = lib.mkIf true {};
value.mkiftrue = lib.mkIf true { };
}
{
value.mkdefault = lib.mkDefault 0;
@@ -19,7 +20,7 @@
}
{
value.mkmerge = lib.mkMerge [
{}
{ }
];
}
{
@@ -1,4 +1,5 @@
{ lib, ... }: {
{ lib, ... }:
{
options.value = lib.mkOption {
type = lib.types.anything;
@@ -8,7 +8,9 @@ in
type = types.attrTag {
int = types.int;
};
default = { int = 1; };
default = {
int = 1;
};
};
};
}
+48 -15
View File
@@ -1,4 +1,9 @@
{ lib, config, options, ... }:
{
lib,
config,
options,
...
}:
let
inherit (lib) mkOption types;
forceDeep = x: builtins.deepSeq x x;
@@ -7,15 +12,16 @@ in
{
options = {
intStrings = mkOption {
type = types.attrsOf
(types.attrTag {
type = types.attrsOf (
types.attrTag {
left = mkOption {
type = types.int;
};
right = mkOption {
type = types.str;
};
});
}
);
};
nested = mkOption {
type = types.attrTag {
@@ -65,7 +71,7 @@ in
}
);
};
okChecks = mkOption {};
okChecks = mkOption { };
};
imports = [
./docs.nix
@@ -86,10 +92,19 @@ in
];
config = {
intStrings.syntaxError = 1;
intStrings.syntaxError2 = {};
intStrings.syntaxError3 = { a = true; b = true; };
intStrings.syntaxError4 = lib.mkMerge [ { a = true; } { b = true; } ];
intStrings.mergeError = lib.mkMerge [ { int = throw "do not eval"; } { string = throw "do not eval"; } ];
intStrings.syntaxError2 = { };
intStrings.syntaxError3 = {
a = true;
b = true;
};
intStrings.syntaxError4 = lib.mkMerge [
{ a = true; }
{ b = true; }
];
intStrings.mergeError = lib.mkMerge [
{ int = throw "do not eval"; }
{ string = throw "do not eval"; }
];
intStrings.badTagError.rite = throw "do not eval";
intStrings.badTagTypeError.left = "bad";
intStrings.numberOne.left = 1;
@@ -109,7 +124,12 @@ in
assert config.docs."submodules.<name>.foo.bar".type == "signed integer";
assert config.docs."submodules.<name>.qux".type == "string";
assert config.docs."submodules.<name>.qux".declarations == [ __curPos.file ];
assert config.docs."submodules.<name>.qux".loc == [ "submodules" "<name>" "qux" ];
assert
config.docs."submodules.<name>.qux".loc == [
"submodules"
"<name>"
"qux"
];
assert config.docs."submodules.<name>.qux".name == "submodules.<name>.qux";
assert config.docs."submodules.<name>.qux".description == "A qux for when you don't want a foo";
assert config.docs."submodules.<name>.qux".readOnly == false;
@@ -119,17 +139,30 @@ in
assert options.submodules.declarations == [ __curPos.file ];
assert lib.length options.submodules.declarationPositions == 1;
assert (lib.head options.submodules.declarationPositions).file == __curPos.file;
assert options.merged.declarations == [ __curPos.file __curPos.file ];
assert
options.merged.declarations == [
__curPos.file
__curPos.file
];
assert lib.length options.merged.declarationPositions == 2;
assert (lib.elemAt options.merged.declarationPositions 0).file == __curPos.file;
assert (lib.elemAt options.merged.declarationPositions 1).file == __curPos.file;
assert (lib.elemAt options.merged.declarationPositions 0).line != (lib.elemAt options.merged.declarationPositions 1).line;
assert mergedSubOption.declarations == [ __curPos.file __curPos.file ];
assert
(lib.elemAt options.merged.declarationPositions 0).line
!= (lib.elemAt options.merged.declarationPositions 1).line;
assert
mergedSubOption.declarations == [
__curPos.file
__curPos.file
];
assert lib.length mergedSubOption.declarationPositions == 2;
assert (lib.elemAt mergedSubOption.declarationPositions 0).file == __curPos.file;
assert (lib.elemAt mergedSubOption.declarationPositions 1).file == __curPos.file;
assert (lib.elemAt mergedSubOption.declarationPositions 0).line != (lib.elemAt mergedSubOption.declarationPositions 1).line;
assert
(lib.elemAt mergedSubOption.declarationPositions 0).line
!= (lib.elemAt mergedSubOption.declarationPositions 1).line;
assert lib.length config.docs."merged.<name>.extensible".declarations == 2;
true);
true
);
};
}
+10 -5
View File
@@ -4,13 +4,18 @@ let
in
{
options.examples = mkOption {
type = types.lazyAttrsOf
(types.unique
{ message = "We require a single definition, because seeing the whole value at once helps us maintain critical invariants of our system."; }
(types.attrsOf types.str));
type = types.lazyAttrsOf (
types.unique {
message = "We require a single definition, because seeing the whole value at once helps us maintain critical invariants of our system.";
} (types.attrsOf types.str)
);
};
imports = [
{ examples.merged = { b = "bee"; }; }
{
examples.merged = {
b = "bee";
};
}
{ examples.override = lib.mkForce { b = "bee"; }; }
];
config.examples = {