···11{ lib }:
22let
3344- inherit (builtins) attrNames isFunction;
44+ inherit (builtins) attrNames;
5566in
77···7272 makeOverridable = f: origArgs:
7373 let
7474 ff = f origArgs;
7575- overrideWith = newArgs: origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs);
7575+ overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs);
7676 in
7777 if builtins.isAttrs ff then (ff // {
7878 override = newArgs: makeOverridable f (overrideWith newArgs);
···8181 ${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv:
8282 makeOverridable (args: (f args).overrideAttrs fdrv) origArgs;
8383 })
8484- else if builtins.isFunction ff then {
8484+ else if lib.isFunction ff then {
8585 override = newArgs: makeOverridable f (overrideWith newArgs);
8686 __functor = self: ff;
8787 overrideDerivation = throw "overrideDerivation not yet supported for functors";
···112112 */
113113 callPackageWith = autoArgs: fn: args:
114114 let
115115- f = if builtins.isFunction fn then fn else import fn;
116116- auto = builtins.intersectAttrs (builtins.functionArgs f) autoArgs;
115115+ f = if lib.isFunction fn then fn else import fn;
116116+ auto = builtins.intersectAttrs (lib.functionArgs f) autoArgs;
117117 in makeOverridable f (auto // args);
118118119119···122122 individual attributes. */
123123 callPackagesWith = autoArgs: fn: args:
124124 let
125125- f = if builtins.isFunction fn then fn else import fn;
126126- auto = builtins.intersectAttrs (builtins.functionArgs f) autoArgs;
125125+ f = if lib.isFunction fn then fn else import fn;
126126+ auto = builtins.intersectAttrs (lib.functionArgs f) autoArgs;
127127 origArgs = auto // args;
128128 pkgs = f origArgs;
129129 mkAttrOverridable = name: pkg: makeOverridable (newArgs: (f newArgs).${name}) origArgs;
+2-2
lib/debug.nix
···2233let
4455-inherit (builtins) trace attrNamesToStr isAttrs isFunction isList isInt
55+inherit (builtins) trace attrNamesToStr isAttrs isList isInt
66 isString isBool head substring attrNames;
7788-inherit (lib) all id mapAttrsFlatten elem;
88+inherit (lib) all id mapAttrsFlatten elem isFunction;
991010in
1111
+2-2
lib/default.nix
···51515252 inherit (builtins) add addErrorContext attrNames
5353 concatLists deepSeq elem elemAt filter genericClosure genList
5454- getAttr hasAttr head isAttrs isBool isFunction isInt isList
5454+ getAttr hasAttr head isAttrs isBool isInt isList
5555 isString length lessThan listToAttrs pathExists readFile
5656 replaceStrings seq stringLength sub substring tail;
5757 inherit (trivial) id const concat or and boolToString mergeAttrs
5858 flip mapNullable inNixShell min max importJSON warn info
5959- nixpkgsVersion mod;
5959+ nixpkgsVersion mod functionArgs setFunctionArgs isFunction;
60606161 inherit (fixedPoints) fix fix' extends composeExtensions
6262 makeExtensible makeExtensibleWithCustomName;
+4-4
lib/deprecated.nix
···11{ lib }:
22let
33- inherit (builtins) isFunction head tail isList isAttrs isInt attrNames;
33+ inherit (builtins) head tail isList isAttrs isInt attrNames;
4455in
66···5353 f: # the function applied to the arguments
5454 initial: # you pass attrs, the functions below are passing a function taking the fix argument
5555 let
5656- takeFixed = if isFunction initial then initial else (fixed : initial); # transform initial to an expression always taking the fixed argument
5656+ takeFixed = if lib.isFunction initial then initial else (fixed : initial); # transform initial to an expression always taking the fixed argument
5757 tidy = args:
5858 let # apply all functions given in "applyPreTidy" in sequence
5959 applyPreTidyFun = fold ( n: a: x: n ( a x ) ) lib.id (maybeAttr "applyPreTidy" [] args);
···6363 let args = takeFixed fixed;
6464 mergeFun = args.${n};
6565 in if isAttrs x then (mergeFun args x)
6666- else assert isFunction x;
6666+ else assert lib.isFunction x;
6767 mergeFun args (x ( args // { inherit fixed; }));
6868 in overridableDelayableArgs f newArgs;
6969 in
···374374 if isAttrs x then
375375 if x ? outPath then "derivation"
376376 else "attrs"
377377- else if isFunction x then "function"
377377+ else if lib.isFunction x then "function"
378378 else if isList x then "list"
379379 else if x == true then "bool"
380380 else if x == false then "bool"
+3-1
lib/generators.nix
···1414 libAttr = lib.attrsets;
15151616 flipMapAttrs = flip libAttr.mapAttrs;
1717+1818+ inherit (lib) isFunction;
1719in
18201921rec {
···110112 else if isString v then "\"" + v + "\""
111113 else if null == v then "null"
112114 else if isFunction v then
113113- let fna = functionArgs v;
115115+ let fna = lib.functionArgs v;
114116 showFnas = concatStringsSep "," (libAttr.mapAttrsToList
115117 (name: hasDefVal: if hasDefVal then "(${name})" else name)
116118 fna);
···155155 # a module will resolve strictly the attributes used as argument but
156156 # not their values. The values are forwarding the result of the
157157 # evaluation of the option.
158158- requiredArgs = builtins.attrNames (builtins.functionArgs f);
158158+ requiredArgs = builtins.attrNames (lib.functionArgs f);
159159 context = name: ''while evaluating the module argument `${name}' in "${key}":'';
160160 extraArgs = builtins.listToAttrs (map (name: {
161161 inherit name;
+26-1
lib/trivial.nix
···52525353 # Pull in some builtins not included elsewhere.
5454 inherit (builtins)
5555- pathExists readFile isBool isFunction
5555+ pathExists readFile isBool
5656 isInt add sub lessThan
5757 seq deepSeq genericClosure;
5858···9999 */
100100 warn = msg: builtins.trace "WARNING: ${msg}";
101101 info = msg: builtins.trace "INFO: ${msg}";
102102+103103+ # | Add metadata about expected function arguments to a function.
104104+ # The metadata should match the format given by
105105+ # builtins.functionArgs, i.e. a set from expected argument to a bool
106106+ # representing whether that argument has a default or not.
107107+ # setFunctionArgs : (a → b) → Map String Bool → (a → b)
108108+ #
109109+ # This function is necessary because you can't dynamically create a
110110+ # function of the { a, b ? foo, ... }: format, but some facilities
111111+ # like callPackage expect to be able to query expected arguments.
112112+ setFunctionArgs = f: args:
113113+ { # TODO: Should we add call-time "type" checking like built in?
114114+ __functor = self: f;
115115+ __functionArgs = args;
116116+ };
117117+118118+ # | Extract the expected function arguments from a function.
119119+ # This works both with nix-native { a, b ? foo, ... }: style
120120+ # functions and functions with args set with 'setFunctionArgs'. It
121121+ # has the same return type and semantics as builtins.functionArgs.
122122+ # setFunctionArgs : (a → b) → Map String Bool.
123123+ functionArgs = f: f.__functionArgs or (builtins.functionArgs f);
124124+125125+ isFunction = f: builtins.isFunction f ||
126126+ (f ? __functor && isFunction (f.__functor f));
102127}
+1-1
nixos/doc/manual/default.nix
···1212 substFunction = x:
1313 if builtins.isAttrs x then lib.mapAttrs (name: substFunction) x
1414 else if builtins.isList x then map substFunction x
1515- else if builtins.isFunction x then "<function>"
1515+ else if lib.isFunction x then "<function>"
1616 else x;
17171818 # Clean up declaration sites to not refer to the NixOS source tree.
+22
nixos/doc/manual/release-notes/rl-1803.xml
···9090 </listitem>
9191 <listitem>
9292 <para>
9393+ Package attributes starting with a digit have been prefixed with an
9494+ underscore sign. This is to avoid quoting in the configuration and
9595+ other issues with command-line tools like <literal>nix-env</literal>.
9696+ The change affects the following packages:
9797+ <itemizedlist>
9898+ <listitem>
9999+ <para><literal>2048-in-terminal</literal> → <literal>_2048-in-terminal</literal></para>
100100+ </listitem>
101101+ <listitem>
102102+ <para><literal>90secondportraits</literal> → <literal>_90secondportraits</literal></para>
103103+ </listitem>
104104+ <listitem>
105105+ <para><literal>2bwm</literal> → <literal>_2bwm</literal></para>
106106+ </listitem>
107107+ <listitem>
108108+ <para><literal>389-ds-base</literal> → <literal>_389-ds-base</literal></para>
109109+ </listitem>
110110+ </itemizedlist>
111111+ </para>
112112+ </listitem>
113113+ <listitem>
114114+ <para>
93115 <emphasis role="strong">
94116 The OpenSSH service no longer enables support for DSA keys by default,
95117 which could cause a system lock out. Update your keys or, unfavorably,
+1-1
nixos/lib/testing.nix
···85858686 testScript' =
8787 # Call the test script with the computed nodes.
8888- if builtins.isFunction testScript
8888+ if lib.isFunction testScript
8989 then testScript { inherit nodes; }
9090 else testScript;
9191
+2
nixos/modules/misc/ids.nix
···302302 kodi = 283;
303303 restya-board = 284;
304304 mighttpd2 = 285;
305305+ hass = 286;
305306306307 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
307308···572573 kodi = 283;
573574 restya-board = 284;
574575 mighttpd2 = 285;
576576+ hass = 286;
575577576578 # When adding a gid, make sure it doesn't match an existing
577579 # uid. Users and groups with the same name should have equal
+3-3
nixos/modules/misc/nixpkgs.nix
···4455let
66 isConfig = x:
77- builtins.isAttrs x || builtins.isFunction x;
77+ builtins.isAttrs x || lib.isFunction x;
8899 optCall = f: x:
1010- if builtins.isFunction f
1010+ if lib.isFunction f
1111 then f x
1212 else f;
1313···3838 overlayType = mkOptionType {
3939 name = "nixpkgs-overlay";
4040 description = "nixpkgs overlay";
4141- check = builtins.isFunction;
4141+ check = lib.isFunction;
4242 merge = lib.mergeOneOption;
4343 };
4444
···1717 # you should use files).
1818 moduleFiles =
1919 # FIXME: use typeOf (Nix 1.6.1).
2020- filter (x: !isAttrs x && !builtins.isFunction x) modules;
2020+ filter (x: !isAttrs x && !lib.isFunction x) modules;
21212222 # Partition module files because between NixOS and non-NixOS files. NixOS
2323 # files may change if the repository is updated.
+90
nixos/modules/services/misc/home-assistant.nix
···11+{ config, lib, pkgs, ... }:
22+33+with lib;
44+55+let
66+ cfg = config.services.home-assistant;
77+88+ configFile = pkgs.writeText "configuration.yaml" (builtins.toJSON cfg.config);
99+in {
1010+ meta.maintainers = with maintainers; [ dotlambda ];
1111+1212+ options.services.home-assistant = {
1313+ enable = mkEnableOption "Home Assistant";
1414+1515+ configDir = mkOption {
1616+ default = "/var/lib/hass";
1717+ type = types.path;
1818+ description = "The config directory, where your <filename>configuration.yaml</filename> is located.";
1919+ };
2020+2121+ config = mkOption {
2222+ default = null;
2323+ type = with types; nullOr attrs;
2424+ example = literalExample ''
2525+ {
2626+ homeassistant = {
2727+ name = "Home";
2828+ time_zone = "UTC";
2929+ };
3030+ frontend = { };
3131+ http = { };
3232+ }
3333+ '';
3434+ description = ''
3535+ Your <filename>configuration.yaml</filename> as a Nix attribute set.
3636+ Beware that setting this option will delete your previous <filename>configuration.yaml</filename>.
3737+ '';
3838+ };
3939+4040+ package = mkOption {
4141+ default = pkgs.home-assistant;
4242+ defaultText = "pkgs.home-assistant";
4343+ type = types.package;
4444+ example = literalExample ''
4545+ pkgs.home-assistant.override {
4646+ extraPackages = ps: with ps; [ colorlog ];
4747+ }
4848+ '';
4949+ description = ''
5050+ Home Assistant package to use.
5151+ Most Home Assistant components require additional dependencies,
5252+ which are best specified by overriding <literal>pkgs.home-assistant</literal>.
5353+ You can find the dependencies by searching for failed imports in your log or by looking at this list:
5454+ <link xlink:href="https://github.com/home-assistant/home-assistant/blob/master/requirements_all.txt"/>
5555+ '';
5656+ };
5757+ };
5858+5959+ config = mkIf cfg.enable {
6060+ systemd.services.home-assistant = {
6161+ description = "Home Assistant";
6262+ wantedBy = [ "multi-user.target" ];
6363+ after = [ "network.target" ];
6464+ preStart = lib.optionalString (cfg.config != null) ''
6565+ rm -f ${cfg.configDir}/configuration.yaml
6666+ ln -s ${configFile} ${cfg.configDir}/configuration.yaml
6767+ '';
6868+ serviceConfig = {
6969+ ExecStart = ''
7070+ ${cfg.package}/bin/hass --config "${cfg.configDir}"
7171+ '';
7272+ User = "hass";
7373+ Group = "hass";
7474+ Restart = "on-failure";
7575+ ProtectSystem = "strict";
7676+ ReadWritePaths = "${cfg.configDir}";
7777+ PrivateTmp = true;
7878+ };
7979+ };
8080+8181+ users.extraUsers.hass = {
8282+ home = cfg.configDir;
8383+ createHome = true;
8484+ group = "hass";
8585+ uid = config.ids.uids.hass;
8686+ };
8787+8888+ users.extraGroups.hass.gid = config.ids.gids.hass;
8989+ };
9090+}
+3-3
nixos/modules/services/networking/kresd.nix
···4343 type = with types; listOf str;
4444 default = [ "::1" "127.0.0.1" ];
4545 description = ''
4646- What addresses the server should listen on.
4646+ What addresses the server should listen on. (UDP+TCP 53)
4747 '';
4848 };
4949 # TODO: perhaps options for more common stuff like cache size or forwarding
···9999 Restart = "on-failure";
100100 };
101101102102+ # Trust anchor goes from dns-root-data by default.
102103 script = ''
103103- exec '${package}/bin/kresd' --config '${configFile}' \
104104- -k '${pkgs.dns-root-data}/root.key'
104104+ exec '${package}/bin/kresd' --config '${configFile}' --forks=1
105105 '';
106106107107 requires = [ "kresd.socket" ];
···273273 };
274274275275 virtualType = mkOption {
276276- default = null;
277277- type = with types; nullOr (enum [ "tun" "tap" ]);
276276+ default = if hasPrefix "tun" name then "tun" else "tap";
277277+ defaultText = literalExample ''if hasPrefix "tun" name then "tun" else "tap"'';
278278+ type = with types; enum [ "tun" "tap" ];
278279 description = ''
279279- The explicit type of interface to create. Accepts tun or tap strings.
280280- Also accepts null to implicitly detect the type of device.
280280+ The type of interface to create.
281281+ The default is TUN for an interface name starting
282282+ with "tun", otherwise TAP.
281283 '';
282284 };
283285
···38383939## other
40404141-# If you want the resulting program to call itself
4242-# "Firefox"/"Torbrowser" instead of "Nightly" or whatever, enable this
4343-# option. However, in Firefox's case, those binaries may not be
4444-# distributed without permission from the Mozilla Foundation, see
4545-# http://www.mozilla.org/foundation/trademarks/.
4646-, enableOfficialBranding ? isTorBrowserLike
4141+# As stated by Sylvestre Ledru (@sylvestre) on Nov 22, 2017 at
4242+# https://github.com/NixOS/nixpkgs/issues/31843#issuecomment-346372756 we
4343+# have permission to use the official firefox branding.
4444+#
4545+# Fur purposes of documentation the statement of @sylvestre:
4646+# > As the person who did part of the work described in the LWN article
4747+# > and release manager working for Mozilla, I can confirm the statement
4848+# > that I made in
4949+# > https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=815006
5050+# >
5151+# > @garbas shared with me the list of patches applied for the Nix package.
5252+# > As they are just for portability and tiny modifications, they don't
5353+# > alter the experience of the product. In parallel, Rok also shared the
5454+# > build options. They seem good (even if I cannot judge the quality of the
5555+# > packaging of the underlying dependencies like sqlite, png, etc).
5656+# > Therefor, as long as you keep the patch queue sane and you don't alter
5757+# > the experience of Firefox users, you won't have any issues using the
5858+# > official branding.
5959+, enableOfficialBranding ? true
4760}:
48614962assert stdenv.cc ? libc && stdenv.cc.libc != null;
···91104 '' + lib.optionalString (stdenv.lib.versionAtLeast version "58.0.0") ''
92105 cat >.mozconfig <<END_MOZCONFIG
93106 ${lib.concatStringsSep "\n" (map (flag: "ac_add_options ${flag}") configureFlags)}
107107+ ${lib.optionalString googleAPISupport "ac_add_options --with-google-api-keyfile=$TMPDIR/ga"}
94108 END_MOZCONFIG
95109 '' + lib.optionalString googleAPISupport ''
96110 # Google API key used by Chromium and Firefox.
97111 # Note: These are for NixOS/nixpkgs use ONLY. For your own distribution,
98112 # please get your own set of keys.
99113 echo "AIzaSyDGi15Zwl11UNe6Y-5XW_upsfyw31qwZPI" > $TMPDIR/ga
114114+ configureFlagsArray+=("--with-google-api-keyfile=$TMPDIR/ga")
100115 '' + ''
101116 # this will run autoconf213
102117 ${if (stdenv.lib.versionAtLeast version "58.0.0") then "./mach configure" else "make -f client.mk configure-files"}
···171186 ++ flag gssSupport "negotiateauth"
172187 ++ lib.optional (!ffmpegSupport) "--disable-gstreamer"
173188 ++ flag webrtcSupport "webrtc"
174174- ++ lib.optional googleAPISupport "--with-google-api-keyfile=$TMPDIR/ga"
175189 ++ flag crashreporterSupport "crashreporter"
176190 ++ lib.optional drmSupport "--enable-eme=widevine"
177191
···8181 # lost on `.override`) but determine the auto-args based on `drv` (the problem here
8282 # is that nix has no way to "passthrough" args while preserving the reflection
8383 # info that callPackage uses to determine the arguments).
8484- drv = if builtins.isFunction fn then fn else import fn;
8585- auto = builtins.intersectAttrs (builtins.functionArgs drv) scope;
8484+ drv = if stdenv.lib.isFunction fn then fn else import fn;
8585+ auto = builtins.intersectAttrs (stdenv.lib.functionArgs drv) scope;
86868787 # this wraps the `drv` function to add a `overrideScope` function to the result.
8888 drvScope = allArgs: drv allArgs // {
···186186 # There should be an IOVideo here, but they haven't released it :(
187187 };
188188189189- IOKitSrcs = stdenv.lib.mapAttrs (name: value: if builtins.isFunction value then value name else value) IOKitSpecs;
189189+ IOKitSrcs = stdenv.lib.mapAttrs (name: value: if stdenv.lib.isFunction value then value name else value) IOKitSpecs;
190190191191 adv_cmds = applePackage "adv_cmds" "osx-10.5.8" "102ssayxbg9wb35mdmhswbnw0bg7js3pfd8fcbic83c5q3bqa6c6" {};
192192