Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treewide: remove with lib in meta, will be dismembered later #371665

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
32 changes: 16 additions & 16 deletions lib/tests/misc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2425,67 +2425,67 @@ runTests {
};

testTypeDescriptionInt = {
expr = (with types; int).description;
expr = (with lib.types; int).description;
expected = "signed integer";
};
testTypeDescriptionIntsPositive = {
expr = (with types; ints.positive).description;
expr = (with lib.types; ints.positive).description;
expected = "positive integer, meaning >0";
};
testTypeDescriptionIntsPositiveOrEnumAuto = {
expr = (with types; either ints.positive (enum ["auto"])).description;
expr = (with lib.types; either ints.positive (enum ["auto"])).description;
expected = ''positive integer, meaning >0, or value "auto" (singular enum)'';
};
testTypeDescriptionListOfPositive = {
expr = (with types; listOf ints.positive).description;
expr = (with lib.types; listOf ints.positive).description;
expected = "list of (positive integer, meaning >0)";
};
testTypeDescriptionListOfInt = {
expr = (with types; listOf int).description;
expr = (with lib.types; listOf int).description;
expected = "list of signed integer";
};
testTypeDescriptionListOfListOfInt = {
expr = (with types; listOf (listOf int)).description;
expr = (with lib.types; listOf (listOf int)).description;
expected = "list of list of signed integer";
};
testTypeDescriptionListOfEitherStrOrBool = {
expr = (with types; listOf (either str bool)).description;
expr = (with lib.types; listOf (either str bool)).description;
expected = "list of (string or boolean)";
};
testTypeDescriptionEitherListOfStrOrBool = {
expr = (with types; either (listOf bool) str).description;
expr = (with lib.types; either (listOf bool) str).description;
expected = "(list of boolean) or string";
};
testTypeDescriptionEitherStrOrListOfBool = {
expr = (with types; either str (listOf bool)).description;
expr = (with lib.types; either str (listOf bool)).description;
expected = "string or list of boolean";
};
testTypeDescriptionOneOfListOfStrOrBool = {
expr = (with types; oneOf [ (listOf bool) str ]).description;
expr = (with lib.types; oneOf [ (listOf bool) str ]).description;
expected = "(list of boolean) or string";
};
testTypeDescriptionOneOfListOfStrOrBoolOrNumber = {
expr = (with types; oneOf [ (listOf bool) str number ]).description;
expr = (with lib.types; oneOf [ (listOf bool) str number ]).description;
expected = "(list of boolean) or string or signed integer or floating point number";
};
testTypeDescriptionEitherListOfBoolOrEitherStringOrNumber = {
expr = (with types; either (listOf bool) (either str number)).description;
expr = (with lib.types; either (listOf bool) (either str number)).description;
expected = "(list of boolean) or string or signed integer or floating point number";
};
testTypeDescriptionEitherEitherListOfBoolOrStringOrNumber = {
expr = (with types; either (either (listOf bool) str) number).description;
expr = (with lib.types; either (either (listOf bool) str) number).description;
expected = "(list of boolean) or string or signed integer or floating point number";
};
testTypeDescriptionEitherNullOrBoolOrString = {
expr = (with types; either (nullOr bool) str).description;
expr = (with lib.types; either (nullOr bool) str).description;
expected = "null or boolean or string";
};
testTypeDescriptionEitherListOfEitherBoolOrStrOrInt = {
expr = (with types; either (listOf (either bool str)) int).description;
expr = (with lib.types; either (listOf (either bool str)) int).description;
expected = "(list of (boolean or string)) or signed integer";
};
testTypeDescriptionEitherIntOrListOrEitherBoolOrStr = {
expr = (with types; either int (listOf (either bool str))).description;
expr = (with lib.types; either int (listOf (either bool str))).description;
expected = "signed integer or list of (boolean or string)";
};

Expand Down
14 changes: 6 additions & 8 deletions lib/tests/modules/merge-module-with-key.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{ lib, ... }:
let
inherit (lib) mkOption types;

moduleWithoutKey = {
config = {
raw = "pear";
Expand All @@ -17,16 +15,16 @@ let

decl = {
options = {
raw = mkOption {
type = types.lines;
raw = lib.mkOption {
type = lib.types.lines;
};
};
};
in
{
options = {
once = mkOption {
type = types.submodule {
once = lib.mkOption {
type = lib.types.submodule {
imports = [
decl
moduleWithKey
Expand All @@ -35,8 +33,8 @@ in
};
default = { };
};
twice = mkOption {
type = types.submodule {
twice = lib.mkOption {
type = lib.types.submodule {
imports = [
decl
moduleWithoutKey
Expand Down
32 changes: 10 additions & 22 deletions nixos/doc/manual/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@
}:

let
inherit (pkgs) buildPackages runCommand docbook_xsl_ns;

inherit (pkgs.lib)
hasPrefix
removePrefix
flip
foldr
types
mkOption
escapeShellArg
concatMapStringsSep
sourceFilesBySuffices
;
inherit (pkgs) buildPackages runCommand docbook_xsl_ns lib;

common = import ./common.nix;

Expand All @@ -35,7 +23,7 @@ let
# E.g. if some `options` came from modules in ${pkgs.customModules}/nix,
# you'd need to include `extraSources = [ pkgs.customModules ]`
prefixesToStrip = map (p: "${toString p}/") ([ prefix ] ++ extraSources);
stripAnyPrefixes = flip (foldr removePrefix) prefixesToStrip;
stripAnyPrefixes = lib.flip (lib.foldr lib.removePrefix) prefixesToStrip;

optionsDoc = buildPackages.nixosOptionsDoc {
inherit options revision baseOptionsJSON warningsAreErrors;
Expand All @@ -50,8 +38,8 @@ let
testOptionsDoc = let
eval = nixos-lib.evalTest {
# Avoid evaluating a NixOS config prototype.
config.node.type = types.deferredModule;
options._module.args = mkOption { internal = true; };
config.node.type = lib.types.deferredModule;
options._module.args = lib.mkOption { internal = true; };
};
in buildPackages.nixosOptionsDoc {
inherit (eval) options;
Expand All @@ -61,9 +49,9 @@ let
declarations =
map
(decl:
if hasPrefix (toString ../../..) (toString decl)
if lib.hasPrefix (toString ../../..) (toString decl)
then
let subpath = removePrefix "/" (removePrefix (toString ../../..) (toString decl));
let subpath = lib.removePrefix "/" (lib.removePrefix (toString ../../..) (toString decl));
in { url = "https://github.com/NixOS/nixpkgs/blob/master/${subpath}"; name = subpath; }
else decl)
opt.declarations;
Expand All @@ -86,7 +74,7 @@ let
substituteInPlace ./configuration/configuration.md \
--replace-fail \
'@MODULE_CHAPTERS@' \
${escapeShellArg (concatMapStringsSep "\n" (p: "${p.value}") config.meta.doc)}
${lib.escapeShellArg (lib.concatMapStringsSep "\n" (p: "${p.value}") config.meta.doc)}
substituteInPlace ./nixos-options.md \
--replace-fail \
'@NIXOS_OPTIONS_JSON@' \
Expand All @@ -105,7 +93,7 @@ in rec {
# Generate the NixOS manual.
manualHTML = runCommand "nixos-manual-html"
{ nativeBuildInputs = [ buildPackages.nixos-render-docs ];
inputs = sourceFilesBySuffices ./. [ ".md" ];
inputs = lib.sourceFilesBySuffices ./. [ ".md" ];
meta.description = "The NixOS manual in HTML format";
allowedReferences = ["out"];
}
Expand All @@ -125,7 +113,7 @@ in rec {
nixos-render-docs -j $NIX_BUILD_CORES manual html \
--manpage-urls ${manpageUrls} \
--redirects ${./redirects.json} \
--revision ${escapeShellArg revision} \
--revision ${lib.escapeShellArg revision} \
--generator "nixos-render-docs ${pkgs.lib.version}" \
--stylesheet style.css \
--stylesheet highlightjs/mono-blue.css \
Expand Down Expand Up @@ -210,7 +198,7 @@ in rec {
# Generate manpages.
mkdir -p $out/share/man/man5
nixos-render-docs -j $NIX_BUILD_CORES options manpage \
--revision ${escapeShellArg revision} \
--revision ${lib.escapeShellArg revision} \
${optionsJSON}/${common.outputPath}/options.json \
$out/share/man/man5/configuration.nix.5
'';
Expand Down
6 changes: 2 additions & 4 deletions nixos/lib/eval-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ evalConfigArgs@
}:

let
inherit (lib) optional;

evalModulesMinimal = (import ./default.nix {
inherit lib;
# Implicit use of feature is noted in implementation.
Expand All @@ -68,15 +66,15 @@ let
_file = ./eval-config.nix;
key = _file;
config = lib.mkMerge (
(optional (system != null) {
(lib.optional (system != null) {
# Explicit `nixpkgs.system` or `nixpkgs.localSystem` should override
# this. Since the latter defaults to the former, the former should
# default to the argument. That way this new default could propagate all
# they way through, but has the last priority behind everything else.
nixpkgs.system = lib.mkDefault system;
})
++
(optional (pkgs != null) {
(lib.optional (pkgs != null) {
# This should be default priority, so it conflicts with any user-defined pkgs.
nixpkgs.pkgs = pkgs;
})
Expand Down
2 changes: 1 addition & 1 deletion nixos/lib/make-disk-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ To solve this, you can run `fdisk -l $image` and generate `dd if=$image of=$imag
# grafted in the file system at path `target', `mode' is a string containing
# the permissions that will be set (ex. "755"), `user' and `group' are the
# user and group name that will be set as owner of the files.
# `mode', `user', and `group' are optional.
# `mode', `user', and `group' are lib.optional.
# When setting one of `user' or `group', the other needs to be set too.
contents ? []

Expand Down
2 changes: 1 addition & 1 deletion nixos/lib/make-options-doc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ let
# - a list: that will be interpreted as an attribute path from `pkgs` and turned into a link
# to search.nixos.org,
# - an attrset: that can specify `name`, `path`, `comment`
# (either of `name`, `path` is required, the rest are optional).
# (either of `name`, `path` is required, the rest are lib.optional).
#
# NOTE: No checks against `pkgs` are made to ensure that the referenced package actually exists.
# Such checks are not compatible with option docs caching.
Expand Down
Loading
Loading