aboutsummaryrefslogtreecommitdiff
path: root/lib/options.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2020-10-20 13:47:24 +0200
committerRobert Hensing <robert@roberthensing.nl>2020-10-22 13:46:47 +0200
commitafa6c51f27fb86fda71f91a51b093a5fc3de797d (patch)
tree99dc279dd61c53c85643f66a1c0c83e7004a9c3b /lib/options.nix
parent5aa2a98dfa0b54fef1b5cc7059ac8c4b1248a739 (diff)
lib: Use Nix's static scope checking, fix error message, optimize
Nix can perform static scope checking, but whenever code is inside a `with` expression, the analysis breaks down, because it can't know statically what's in the attribute set whose attributes were brought into scope. In those cases, Nix has to assume that everything works out. Except it doesnt. Removing `with` from lib/ revealed an undefined variable in an error message. If that doesn't convince you that we're better off without `with`, I can tell you that this PR results in a 3% evaluation performance improvement because Nix can look up local variables by index. This adds up with applications like the module system. Furthermore, removing `with` makes the binding site of each variable obvious, which helps with comprehension.
Diffstat (limited to '')
-rw-r--r--lib/options.nix14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/options.nix b/lib/options.nix
index 9e0ea010bda7..97bb2e77176c 100644
--- a/lib/options.nix
+++ b/lib/options.nix
@@ -1,11 +1,15 @@
# Nixpkgs/NixOS option handling.
{ lib }:
-with lib.trivial;
-with lib.lists;
-with lib.attrsets;
-with lib.strings;
-
+let
+ inherit (lib)
+ isAttrs isBool isDerivation isFunction isInt isList isString
+ all collect concatMap concatLists elemAt filter foldl' head length mapAttrs optionals optional take
+ ;
+ inherit (lib.attrsets) optionalAttrs;
+ inherit (lib.strings) concatMapStrings concatStringsSep;
+ inherit (lib.types) mkOptionType;
+in
rec {
/* Returns true when the given argument is an option