-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib.types.attrsWith: add some more unit tests
- Loading branch information
Showing
5 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Check that AttrsWith { lazy = true; } is lazy | ||
{ lib, ... }: | ||
let | ||
inherit (lib) types mkOption; | ||
in | ||
{ | ||
imports = [ | ||
# Module A | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedLazy = mkOption { | ||
# Same as lazyAttrsOf | ||
type = types.attrsWith { | ||
lazy = true; | ||
elemType = types.int; | ||
}; | ||
}; | ||
} | ||
) | ||
# Module B | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedLazy = lib.mkOption { | ||
# Same as lazyAttrsOf | ||
type = types.attrsWith { | ||
lazy = true; | ||
elemType = types.int; | ||
}; | ||
}; | ||
} | ||
) | ||
# Result | ||
( | ||
{ config, ... }: | ||
{ | ||
# Can only evaluate if lazy | ||
config.mergedLazy.bar = config.mergedLazy.baz + 1; | ||
config.mergedLazy.baz = 10; | ||
options.result = mkOption { default = config.mergedLazy.bar; }; | ||
} | ||
) | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Check that AttrsWith { lazy = true; } is lazy | ||
{ lib, ... }: | ||
let | ||
inherit (lib) types mkOption; | ||
in | ||
{ | ||
imports = [ | ||
# Module A | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedName = mkOption { | ||
default = { }; | ||
type = types.attrsWith { | ||
# Declare <name> = "id" | ||
name = "id"; | ||
elemType = types.submodule { | ||
options.nested = mkOption { | ||
type = types.int; | ||
default = 1; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} | ||
) | ||
# Module B | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedName = mkOption { | ||
# default: "<name>" | ||
type = types.attrsOf (types.submodule { }); | ||
# default = {}; | ||
}; | ||
} | ||
) | ||
|
||
# Output | ||
( | ||
{ | ||
options, | ||
... | ||
}: | ||
{ | ||
options.result = mkOption { | ||
default = lib.concatStringsSep "." (options.mergedName.type.getSubOptions options.mergedName.loc) | ||
.nested.loc; | ||
}; | ||
} | ||
) | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Non mergable attrsWith | ||
{ lib, ... }: | ||
let | ||
inherit (lib) types mkOption; | ||
in | ||
{ | ||
imports = [ | ||
# Module A | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedName = mkOption { | ||
default = { }; | ||
type = types.attrsWith { | ||
name = "id"; | ||
elemType = types.submodule { | ||
options.nested = mkOption { | ||
type = types.int; | ||
default = 1; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} | ||
) | ||
# Module B | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedName = mkOption { | ||
type = types.attrsWith { | ||
name = "other"; | ||
elemType = types.submodule { }; | ||
}; | ||
}; | ||
} | ||
) | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters