diff --git a/docs/default.nix b/docs/default.nix index 67f410f6..b9b83312 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -4,7 +4,6 @@ stdenv, lib, }: -with lib; stdenv.mkDerivation { name = "devshell-docs"; buildInputs = [ mdbook ]; diff --git a/extra/git/hooks.nix b/extra/git/hooks.nix index aff8ed4d..8196e33f 100644 --- a/extra/git/hooks.nix +++ b/extra/git/hooks.nix @@ -4,24 +4,23 @@ pkgs, ... }: -with lib; let cfg = config.git.hooks; # These are all the options available for a git hook. hookOptions = desc: { - text = mkOption { + text = lib.mkOption { description = "Text of the script to install"; default = ""; - type = types.str; + type = lib.types.str; }; }; # All of the hook types supported by this module. - allHooks = filterAttrs (k: v: k != "enable") cfg; + allHooks = lib.filterAttrs (k: v: k != "enable") cfg; # Only keep all the hooks that have a value set. - hooksWithData = filterAttrs (k: v: v.text != "") allHooks; + hooksWithData = lib.filterAttrs (k: v: v.text != "") allHooks; # Shims for all the hooks that this module supports. The shims cause git # hooks to be ignored: @@ -70,7 +69,7 @@ let in pkgs.buildEnv { name = "git.hooks"; - paths = mapAttrsToList mkHookScript hooksWithData; + paths = lib.mapAttrsToList mkHookScript hooksWithData; }; # Execute this script to update the project's git hooks @@ -116,7 +115,7 @@ let mkdir -pv "$target_hook_dir" # Iterate over all the hooks enabled for this environment - for name in ${toString (attrNames hooksWithData)}; do + for name in ${toString (lib.attrNames hooksWithData)}; do # Resolve all the symlinks src_hook=$(readlink -f "$source_hook_dir/$name" || true) dst_hook=$(readlink -f "$target_hook_dir/$name" || true) @@ -137,7 +136,7 @@ let in { options.git.hooks = { - enable = mkEnableOption "install .git/hooks on shell entry"; + enable = lib.mkEnableOption "install .git/hooks on shell entry"; # TODO: add proper description for each hook. applypatch-msg = hookOptions ""; @@ -157,7 +156,7 @@ in # update = hookOptions ""; }; - config.devshell = optionalAttrs cfg.enable { + config.devshell = lib.optionalAttrs cfg.enable { packages = [ install-git-hooks ]; startup.install-git-hooks.text = " @@ -165,7 +164,7 @@ in "; }; - config.env = optional cfg.enable { + config.env = lib.optional cfg.enable { name = "DEVSHELL_GIT_HOOKS_DIR"; value = hooksDir; }; diff --git a/extra/language/c.nix b/extra/language/c.nix index 079cb289..f50bd2e8 100644 --- a/extra/language/c.nix +++ b/extra/language/c.nix @@ -11,9 +11,8 @@ let hasLibraries = lib.length cfg.libraries > 0; hasIncludes = lib.length cfg.includes > 0; in -with lib; { - options.language.c = { + options.language.c = with lib; { libraries = mkOption { type = types.listOf strOrPackage; default = [ ]; diff --git a/extra/language/go.nix b/extra/language/go.nix index d04fa7eb..67c2d2e7 100644 --- a/extra/language/go.nix +++ b/extra/language/go.nix @@ -8,9 +8,8 @@ let cfg = config.language.go; strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; in -with lib; { - options.language.go = { + options.language.go = with lib; { GO111MODULE = mkOption { type = types.enum [ "on" diff --git a/extra/language/hare.nix b/extra/language/hare.nix index 5a30de1e..28347db6 100644 --- a/extra/language/hare.nix +++ b/extra/language/hare.nix @@ -19,9 +19,8 @@ let in lib.makeSearchPath "src/hare/third-party" (userHareLibs ++ propagatedLibs); in -with lib; { - options.language.hare = { + options.language.hare = with lib; { thirdPartyLibs = mkOption { type = types.listOf strOrPackage; default = [ ]; @@ -48,13 +47,13 @@ with lib; name = "HAREPATH"; value = lib.makeSearchPath "src/hare/stdlib" [ cfg.package ]; } - (mkIf (cfg.thirdPartyLibs != [ ]) { + (lib.mkIf (cfg.thirdPartyLibs != [ ]) { name = "HAREPATH"; prefix = makeHareFullPath cfg.thirdPartyLibs; }) - (mkIf (cfg.vendoredLibs != [ ]) { + (lib.mkIf (cfg.vendoredLibs != [ ]) { name = "HAREPATH"; - prefix = concatStringsSep ":" cfg.vendoredLibs; + prefix = lib.concatStringsSep ":" cfg.vendoredLibs; }) ]; devshell.packages = [ cfg.package ]; diff --git a/extra/language/perl.nix b/extra/language/perl.nix index 8a9f6126..c5cae4a3 100644 --- a/extra/language/perl.nix +++ b/extra/language/perl.nix @@ -8,11 +8,9 @@ let cfg = config.language.perl; strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; - in -with lib; { - options.language.perl = { + options.language.perl = with lib; { extraPackages = mkOption { type = types.listOf strOrPackage; default = [ ]; @@ -35,13 +33,13 @@ with lib; config = { env = [ - (mkIf (cfg.extraPackages != [ ]) { + (lib.mkIf (cfg.extraPackages != [ ]) { name = "PERL5LIB"; prefix = pkgs.perlPackages.makeFullPerlPath cfg.extraPackages; }) - (mkIf (cfg.libraryPaths != [ ]) { + (lib.mkIf (cfg.libraryPaths != [ ]) { name = "PERL5LIB"; - prefix = concatStringsSep ":" cfg.libraryPaths; + prefix = lib.concatStringsSep ":" cfg.libraryPaths; }) ]; devshell.packages = [ cfg.package ] ++ cfg.extraPackages; diff --git a/extra/language/ruby.nix b/extra/language/ruby.nix index 36bc8727..9f6f53a5 100644 --- a/extra/language/ruby.nix +++ b/extra/language/ruby.nix @@ -8,10 +8,9 @@ let cfg = config.language.ruby; strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; in -with lib; { imports = [ ./c.nix ]; - options.language.ruby = { + options.language.ruby = with lib; { nativeDeps = mkOption { type = types.listOf strOrPackage; default = [ ]; diff --git a/extra/language/rust.nix b/extra/language/rust.nix index ab86dc69..6e6472f2 100644 --- a/extra/language/rust.nix +++ b/extra/language/rust.nix @@ -7,9 +7,8 @@ let cfg = config.language.rust; in -with lib; { - options.language.rust = { + options.language.rust = with lib; { packageSet = mkOption { # FIXME: how to make the selection possible in TOML? type = types.attrs; diff --git a/extra/locale.nix b/extra/locale.nix index e8bc8efa..1d80c8e9 100644 --- a/extra/locale.nix +++ b/extra/locale.nix @@ -4,12 +4,11 @@ config, ... }: -with lib; let cfg = config.extra.locale; in { - options.extra.locale = { + options.extra.locale = with lib; { lang = mkOption { type = types.nullOr types.str; default = null; diff --git a/extra/services/postgres.nix b/extra/services/postgres.nix index 8151e73b..484367e1 100644 --- a/extra/services/postgres.nix +++ b/extra/services/postgres.nix @@ -9,14 +9,19 @@ config, ... }: -with lib; let + inherit (lib) + mkOption + types + mkEnableOption + ; + # Because we want to be able to push pure JSON-like data into the # environment. strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; }; cfg = config.services.postgres; - createDB = optionalString cfg.createUserDB '' + createDB = lib.optionalString cfg.createUserDB '' echo "CREATE DATABASE ''${USER:-$(id -nu)};" | postgres --single -E postgres ''; @@ -27,7 +32,7 @@ let # Abort if the data dir already exists [[ ! -d "$PGDATA" ]] || exit 0 - initdb ${concatStringsSep " " cfg.initdbArgs} + initdb ${lib.concatStringsSep " " cfg.initdbArgs} cat >> "$PGDATA/postgresql.conf" < max then v else max) 0 commandLengths; commandCategories = lib.unique ( - (zipAttrsWithNames [ "category" ] (name: vs: vs) commands).category + (lib.zipAttrsWithNames [ "category" ] (name: vs: vs) commands).category ); commandByCategoriesSorted = builtins.attrValues ( @@ -93,6 +92,12 @@ let in builtins.concatStringsSep "\n" (map opCat commandByCategoriesSorted) + "\n"; + inherit (lib) + types + mkOption + literalExpression + ; + # These are all the options available for the commands. commandOptions = { name = mkOption { diff --git a/modules/devshell.nix b/modules/devshell.nix index 083efc3f..2da36ef6 100644 --- a/modules/devshell.nix +++ b/modules/devshell.nix @@ -5,10 +5,9 @@ options, ... }: -with lib; let cfg = config.devshell; - sanitizedName = strings.sanitizeDerivationName cfg.name; + sanitizedName = lib.strings.sanitizeDerivationName cfg.name; ansi = import ../nix/ansi.nix; @@ -41,7 +40,7 @@ let addAttributeName = prefix: - mapAttrs ( + lib.mapAttrs ( k: v: v // { @@ -52,6 +51,17 @@ let } ); + inherit (lib) + mkOption + mkEnableOption + attrNames + attrValues + textClosureMap + replaceStrings + types + id + ; + entryOptions = { text = mkOption { type = types.str; @@ -228,7 +238,7 @@ let # Returns a list of all the input derivation ... for a derivation. inputsOf = drv: - filter lib.isDerivation ( + lib.filter lib.isDerivation ( (drv.buildInputs or [ ]) ++ (drv.nativeBuildInputs or [ ]) ++ (drv.propagatedBuildInputs or [ ]) @@ -381,11 +391,11 @@ in config.devshell = { package = devshell_dir; - packages = foldl' (sum: drv: sum ++ (inputsOf drv)) [ ] cfg.packagesFrom; + packages = lib.foldl' (sum: drv: sum ++ (inputsOf drv)) [ ] cfg.packagesFrom; startup = { - motd = noDepEntry '' + motd = lib.noDepEntry '' __devshell-motd() { cat < 0 + (lib.length vals) > 0 ) "[[environ]]: ${name} expected one of (value|eval|prefix|unset) to be set."; - assert assertMsg ((length vals) < 2) + assert assertMsg ((lib.length vals) < 2) "[[environ]]: ${name} expected only one of (value|eval|prefix|unset) to be set. Not ${toString vals}"; assert assertMsg ( !(name == "PATH" && valType == "value") ) "[[environ]]: ${name} should not override the value. Use 'prefix' instead."; if valType == "value" then - "export ${name}=${escapeShellArg (toString value)}" + "export ${name}=${lib.escapeShellArg (toString value)}" else if valType == "eval" then "export ${name}=${eval}" else if valType == "prefix" then @@ -102,7 +109,7 @@ in description = '' Add environment variables to the shell. ''; - example = literalExpression '' + example = lib.literalExpression '' [ { name = "HTTP_PORT"; @@ -146,6 +153,6 @@ in } ]; - devshell.startup_env = concatStringsSep "\n" config.env; + devshell.startup_env = lib.concatStringsSep "\n" config.env; }; } diff --git a/modules/modules-docs.nix b/modules/modules-docs.nix index 56700d2f..6076d4d5 100644 --- a/modules/modules-docs.nix +++ b/modules/modules-docs.nix @@ -9,10 +9,21 @@ modulesPath, ... }: -with lib; let cfg = config.modules-docs; + inherit (lib) + mkOption + isFunction + isString + isList + concatStringsSep + optionalAttrs + removePrefix + removeSuffix + types + ; + # Generate some meta data for a list of packages. This is what # `relatedPackages` option of `mkOption` lib/options.nix influences. # @@ -42,7 +53,7 @@ let let bail = throw "Invalid package attribute path '${toString path}'"; in - attrByPath path bail pkgs + lib.attrByPath path bail pkgs ); in { @@ -85,16 +96,16 @@ let let isEnable = lib.hasPrefix "enable"; isPackage = lib.hasPrefix "package"; - compareWithPrio = pred: cmp: splitByAndCompare pred compare cmp; - moduleCmp = compareWithPrio isEnable (compareWithPrio isPackage compare); + compareWithPrio = pred: cmp: lib.splitByAndCompare pred lib.compare cmp; + moduleCmp = compareWithPrio isEnable (compareWithPrio isPackage lib.compare); in - compareLists moduleCmp a.loc b.loc < 0; + lib.compareLists moduleCmp a.loc b.loc < 0; # Replace functions by the string substFunction = x: if builtins.isAttrs x then - mapAttrs (name: substFunction) x + lib.mapAttrs (name: substFunction) x else if builtins.isList x then map substFunction x else if isFunction x then @@ -105,7 +116,7 @@ let cleanUpOption = opt: let - applyOnAttr = n: f: optionalAttrs (hasAttr n opt) { ${n} = f opt.${n}; }; + applyOnAttr = n: f: optionalAttrs (lib.hasAttr n opt) { ${n} = f opt.${n}; }; in opt // applyOnAttr "declarations" (map mkDeclaration) @@ -115,14 +126,16 @@ let // applyOnAttr "relatedPackages" mkRelatedPackages; optionsDocs = map cleanUpOption ( - sort moduleDocCompare (filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options)) + lib.sort moduleDocCompare ( + lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList options) + ) ); # TODO: display values like TOML instead. toMarkdown = optionsDocs: let - optionsDocsPartitioned = partition (opt: head opt.loc != "_module") optionsDocs; + optionsDocsPartitioned = lib.partition (opt: lib.head opt.loc != "_module") optionsDocs; # TODO: handle opt.relatedPackages. What is it for? optToMd = diff --git a/modules/services.nix b/modules/services.nix index b630baef..d1ed298e 100644 --- a/modules/services.nix +++ b/modules/services.nix @@ -4,8 +4,12 @@ pkgs, ... }: -with lib; let + inherit (lib) + mkOption + types + ; + serviceOptions = { name = mkOption { type = types.nullOr types.str; @@ -47,8 +51,10 @@ let groupToProcfile = name: g: pkgs.writeText "Procfile.${name}" ( - concatLines ( - mapAttrsToList (sName: s: "${if s.name == null then sName else s.name}: ${s.command}") g.services + lib.concatLines ( + lib.mapAttrsToList ( + sName: s: "${if s.name == null then sName else s.name}: ${s.command}" + ) g.services ) ); groupToCommands = @@ -107,8 +113,8 @@ in ''; }; - config.commands = foldl (l: r: l ++ r) [ ] ( - mapAttrsToList ( + config.commands = lib.foldl (l: r: l ++ r) [ ] ( + lib.mapAttrsToList ( gName: g: groupToCommands (if g.name == null then gName else g.name) g ) config.serviceGroups ); diff --git a/nix/strOrPackage.nix b/nix/strOrPackage.nix index f0794021..f0479f93 100644 --- a/nix/strOrPackage.nix +++ b/nix/strOrPackage.nix @@ -1,5 +1,4 @@ { lib, pkgs }: -with lib; let resolveKey = key: @@ -10,4 +9,4 @@ let builtins.foldl' op pkgs attrs; in # Because we want to be able to push pure JSON-like data into the environment. -types.coercedTo types.str resolveKey types.package +lib.types.coercedTo lib.types.str resolveKey lib.types.package