From 69920dafbffcd757acff23f659263ec4b952a017 Mon Sep 17 00:00:00 2001 From: danbst Date: Sun, 14 Jul 2019 13:17:49 +0300 Subject: lib: introduce `foreach` = flip map The main purpose is to bring attention to `flip map`, which improves code readablity. It is useful when ad-hoc anonymous function grows two or more lines in `map` application: ``` map (lcfg: let port = lcfg.port; portStr = if port != defaultPort then ":${toString port}" else ""; scheme = if cfg.enableSSL then "https" else "http"; in "${scheme}://cfg.hostName${portStr}" ) (getListen cfg); ``` Compare this to `foreach`-style: ``` foreach (getListen cfg) (lcfg: let port = lcfg.port; portStr = if port != defaultPort then ":${toString port}" else ""; scheme = if cfg.enableSSL then "https" else "http"; in "${scheme}://cfg.hostName${portStr}" ); ``` This is similar to Haskell's `for` (http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Traversable.html#v:for) --- lib/default.nix | 2 +- lib/lists.nix | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/default.nix b/lib/default.nix index 3efaaf0f8f9..f876c57e25c 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -71,7 +71,7 @@ let zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil recursiveUpdate matchAttrs overrideExisting getOutput getBin getLib getDev chooseDevOutputs zipWithNames zip; - inherit (lists) singleton foldr fold foldl foldl' imap0 imap1 + inherit (lists) singleton foreach foldr fold foldl foldl' imap0 imap1 concatMap flatten remove findSingle findFirst any all count optional optionals toList range partition zipListsWith zipLists reverseList listDfs toposort sort naturalSort compareLists take diff --git a/lib/lists.nix b/lib/lists.nix index 30d87ece664..f9953720ee1 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -21,6 +21,19 @@ rec { */ singleton = x: [x]; + /* Apply the function to each element in the list. Same as `map`, but arguments + flipped. + + Type: foreach :: [a] -> (a -> b) -> [b] + + Example: + foreach [ 1 2 ] (x: + toString x + ) + => [ "1" "2" ] + */ + foreach = xs: f: map f xs; + /* “right fold” a binary function `op` between successive elements of `list` with `nul' as the starting value, i.e., `foldr op nul [x_1 x_2 ... x_n] == op x_1 (op x_2 ... (op x_n nul))`. -- cgit 1.4.1 From 3b0534310c89d04fc3a9c5714b5a4d0f9fb0efca Mon Sep 17 00:00:00 2001 From: danbst Date: Sun, 14 Jul 2019 13:46:10 +0300 Subject: mass replace "flip map -> foreach" See `foreach`-introduction commit. ``` rg 'flip map ' --files-with-matches | xargs sed -i 's/flip map /foreach /g' ``` --- nixos/doc/manual/default.nix | 2 +- nixos/lib/build-vms.nix | 6 +++--- nixos/maintainers/option-usages.nix | 2 +- nixos/modules/rename.nix | 2 +- nixos/modules/services/monitoring/ups.nix | 2 +- nixos/modules/services/networking/consul.nix | 2 +- nixos/modules/services/networking/hylafax/systemd.nix | 2 +- nixos/modules/services/networking/ssh/sshd.nix | 2 +- nixos/modules/services/x11/xautolock.nix | 2 +- nixos/modules/services/x11/xserver.nix | 2 +- nixos/modules/system/boot/loader/grub/grub.nix | 2 +- nixos/modules/tasks/network-interfaces-systemd.nix | 8 ++++---- nixos/modules/tasks/network-interfaces.nix | 12 ++++++------ nixos/tests/networking.nix | 2 +- pkgs/applications/networking/irc/weechat/wrapper.nix | 2 +- .../networking/remote/citrix-receiver/default.nix | 2 +- .../networking/remote/citrix-workspace/default.nix | 2 +- .../ibus-engines/ibus-typing-booster/wrapper.nix | 2 +- 18 files changed, 28 insertions(+), 28 deletions(-) diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix index 7fc0ad702f8..02dfeeefe3e 100644 --- a/nixos/doc/manual/default.nix +++ b/nixos/doc/manual/default.nix @@ -45,7 +45,7 @@ let + ""; in "${lib.concatStringsSep "\n" (map (p: describe (unpack p)) packages)}"; - optionsListDesc = lib.flip map optionsListVisible (opt: opt // { + optionsListDesc = lib.foreach optionsListVisible (opt: opt // { # Clean up declaration sites to not refer to the NixOS source tree. declarations = map stripAnyPrefixes opt.declarations; } diff --git a/nixos/lib/build-vms.nix b/nixos/lib/build-vms.nix index 6c92aa1ffa2..2ecceb82fbe 100644 --- a/nixos/lib/build-vms.nix +++ b/nixos/lib/build-vms.nix @@ -54,11 +54,11 @@ rec { machinesNumbered = zipLists machines (range 1 254); - nodes_ = flip map machinesNumbered (m: nameValuePair m.fst + nodes_ = foreach machinesNumbered (m: nameValuePair m.fst [ ( { config, nodes, ... }: let interfacesNumbered = zipLists config.virtualisation.vlans (range 1 255); - interfaces = flip map interfacesNumbered ({ fst, snd }: + interfaces = foreach interfacesNumbered ({ fst, snd }: nameValuePair "eth${toString snd}" { ipv4.addresses = [ { address = "192.168.${toString fst}.${toString m.snd}"; prefixLength = 24; @@ -88,7 +88,7 @@ rec { "${config.networking.hostName}\n")); virtualisation.qemu.options = - flip map interfacesNumbered + foreach interfacesNumbered ({ fst, snd }: qemuNICFlags snd fst m.snd); }; } diff --git a/nixos/maintainers/option-usages.nix b/nixos/maintainers/option-usages.nix index a67a0ab960e..b207eaded41 100644 --- a/nixos/maintainers/option-usages.nix +++ b/nixos/maintainers/option-usages.nix @@ -102,7 +102,7 @@ let # builtins multiply by 4 the memory usage and the time used to compute # each options. tryCollectOptions = moduleResult: - flip map (excludeOptions (collect isOption moduleResult)) (opt: + foreach (excludeOptions (collect isOption moduleResult)) (opt: { name = showOption opt.loc; } // builtins.tryEval (strict opt.value)); in keepNames ( diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index e127782e85f..218b1d9339a 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -248,7 +248,7 @@ with lib; # KSM (mkRenamedOptionModule [ "hardware" "enableKSM" ] [ "hardware" "ksm" "enable" ]) - ] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter" + ] ++ (foreach [ "blackboxExporter" "collectdExporter" "fritzboxExporter" "jsonExporter" "minioExporter" "nginxExporter" "nodeExporter" "snmpExporter" "unifiExporter" "varnishExporter" ] (opt: mkRemovedOptionModule [ "services" "prometheus" "${opt}" ] '' diff --git a/nixos/modules/services/monitoring/ups.nix b/nixos/modules/services/monitoring/ups.nix index bc755612fd9..57f0bfec574 100644 --- a/nixos/modules/services/monitoring/ups.nix +++ b/nixos/modules/services/monitoring/ups.nix @@ -225,7 +225,7 @@ in '' maxstartdelay = ${toString cfg.maxStartDelay} - ${flip concatStringsSep (flip map (attrValues cfg.ups) (ups: ups.summary)) " + ${flip concatStringsSep (foreach (attrValues cfg.ups) (ups: ups.summary)) " "} ''; diff --git a/nixos/modules/services/networking/consul.nix b/nixos/modules/services/networking/consul.nix index 3a92a883fbf..78fca9326d3 100644 --- a/nixos/modules/services/networking/consul.nix +++ b/nixos/modules/services/networking/consul.nix @@ -15,7 +15,7 @@ let ++ cfg.extraConfigFiles; devices = attrValues (filterAttrs (_: i: i != null) cfg.interface); - systemdDevices = flip map devices + systemdDevices = foreach devices (i: "sys-subsystem-net-devices-${utils.escapeSystemdPath i}.device"); in { diff --git a/nixos/modules/services/networking/hylafax/systemd.nix b/nixos/modules/services/networking/hylafax/systemd.nix index ef177e4be34..527026c0076 100644 --- a/nixos/modules/services/networking/hylafax/systemd.nix +++ b/nixos/modules/services/networking/hylafax/systemd.nix @@ -7,7 +7,7 @@ let inherit (lib) concatStringsSep optionalString; cfg = config.services.hylafax; - mapModems = lib.flip map (lib.attrValues cfg.modems); + mapModems = lib.foreach (lib.attrValues cfg.modems); mkConfigFile = name: conf: # creates hylafax config file, diff --git a/nixos/modules/services/networking/ssh/sshd.nix b/nixos/modules/services/networking/ssh/sshd.nix index 0f9d2420903..005d8bfb61f 100644 --- a/nixos/modules/services/networking/ssh/sshd.nix +++ b/nixos/modules/services/networking/ssh/sshd.nix @@ -502,7 +502,7 @@ in assertions = [{ assertion = if cfg.forwardX11 then cfgc.setXAuthLocation else true; message = "cannot enable X11 forwarding without setting xauth location";}] - ++ flip map cfg.listenAddresses ({ addr, ... }: { + ++ foreach cfg.listenAddresses ({ addr, ... }: { assertion = addr != null; message = "addr must be specified in each listenAddresses entry"; }); diff --git a/nixos/modules/services/x11/xautolock.nix b/nixos/modules/services/x11/xautolock.nix index cbe000058dc..51bdcae992e 100644 --- a/nixos/modules/services/x11/xautolock.nix +++ b/nixos/modules/services/x11/xautolock.nix @@ -129,7 +129,7 @@ in assertion = cfg.killer != null -> cfg.killtime >= 10; message = "killtime has to be at least 10 minutes according to `man xautolock`"; } - ] ++ (lib.flip map [ "locker" "notifier" "nowlocker" "killer" ] + ] ++ (lib.foreach [ "locker" "notifier" "nowlocker" "killer" ] (option: { assertion = cfg."${option}" != null -> builtins.substring 0 1 cfg."${option}" == "/"; diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index 82730c5e80c..4d28a45c2ce 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/nixos/modules/services/x11/xserver.nix @@ -75,7 +75,7 @@ let in imap1 mkHead cfg.xrandrHeads; xrandrDeviceSection = let - monitors = flip map xrandrHeads (h: '' + monitors = foreach xrandrHeads (h: '' Option "monitor-${h.config.output}" "${h.name}" ''); # First option is indented through the space in the config but any diff --git a/nixos/modules/system/boot/loader/grub/grub.nix b/nixos/modules/system/boot/loader/grub/grub.nix index 4e4d14985b0..84753d77cc4 100644 --- a/nixos/modules/system/boot/loader/grub/grub.nix +++ b/nixos/modules/system/boot/loader/grub/grub.nix @@ -684,7 +684,7 @@ in assertion = if args.efiSysMountPoint == null then true else hasPrefix "/" args.efiSysMountPoint; message = "EFI paths must be absolute, not ${args.efiSysMountPoint}"; } - ] ++ flip map args.devices (device: { + ] ++ foreach args.devices (device: { assertion = device == "nodev" || hasPrefix "/" device; message = "GRUB devices must be absolute paths, not ${device} in ${args.path}"; })); diff --git a/nixos/modules/tasks/network-interfaces-systemd.nix b/nixos/modules/tasks/network-interfaces-systemd.nix index 857aaf1e6e3..2612d13da4f 100644 --- a/nixos/modules/tasks/network-interfaces-systemd.nix +++ b/nixos/modules/tasks/network-interfaces-systemd.nix @@ -74,7 +74,7 @@ in enable = true; networks."99-main" = genericNetwork mkDefault; } - (mkMerge (flip map interfaces (i: { + (mkMerge (foreach interfaces (i: { netdevs = mkIf i.virtual ({ "40-${i.name}" = { netdevConfig = { @@ -90,7 +90,7 @@ in name = mkDefault i.name; DHCP = mkForce (dhcpStr (if i.useDHCP != null then i.useDHCP else cfg.useDHCP && interfaceIps i == [ ])); - address = flip map (interfaceIps i) + address = foreach (interfaceIps i) (ip: "${ip.address}/${toString ip.prefixLength}"); networkConfig.IPv6PrivacyExtensions = "kernel"; } ]; @@ -102,7 +102,7 @@ in Kind = "bridge"; }; }; - networks = listToAttrs (flip map bridge.interfaces (bi: + networks = listToAttrs (foreach bridge.interfaces (bi: nameValuePair "40-${bi}" (mkMerge [ (genericNetwork (mkOverride 999)) { DHCP = mkOverride 0 (dhcpStr false); networkConfig.Bridge = name; @@ -173,7 +173,7 @@ in }; - networks = listToAttrs (flip map bond.interfaces (bi: + networks = listToAttrs (foreach bond.interfaces (bi: nameValuePair "40-${bi}" (mkMerge [ (genericNetwork (mkOverride 999)) { DHCP = mkOverride 0 (dhcpStr false); networkConfig.Bond = name; diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index f9b0eb330bf..2af20e05b05 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -926,7 +926,7 @@ in warnings = concatMap (i: i.warnings) interfaces; assertions = - (flip map interfaces (i: { + (foreach interfaces (i: { # With the linux kernel, interface name length is limited by IFNAMSIZ # to 16 bytes, including the trailing null byte. # See include/linux/if.h in the kernel sources @@ -934,12 +934,12 @@ in message = '' The name of networking.interfaces."${i.name}" is too long, it needs to be less than 16 characters. ''; - })) ++ (flip map slaveIfs (i: { + })) ++ (foreach slaveIfs (i: { assertion = i.ipv4.addresses == [ ] && i.ipv6.addresses == [ ]; message = '' The networking.interfaces."${i.name}" must not have any defined ips when it is a slave. ''; - })) ++ (flip map interfaces (i: { + })) ++ (foreach interfaces (i: { assertion = i.preferTempAddress -> cfg.enableIPv6; message = '' Temporary addresses are only needed when IPv6 is enabled. @@ -967,8 +967,8 @@ in "net.ipv6.conf.default.disable_ipv6" = mkDefault (!cfg.enableIPv6); "net.ipv6.conf.all.forwarding" = mkDefault (any (i: i.proxyARP) interfaces); } // listToAttrs (flip concatMap (filter (i: i.proxyARP) interfaces) - (i: flip map [ "4" "6" ] (v: nameValuePair "net.ipv${v}.conf.${i.name}.proxy_arp" true))) - // listToAttrs (flip map (filter (i: i.preferTempAddress) interfaces) + (i: foreach [ "4" "6" ] (v: nameValuePair "net.ipv${v}.conf.${i.name}.proxy_arp" true))) + // listToAttrs (foreach (filter (i: i.preferTempAddress) interfaces) (i: nameValuePair "net.ipv6.conf.${i.name}.use_tempaddr" 2)); # Capabilities won't work unless we have at-least a 4.3 Linux @@ -1051,7 +1051,7 @@ in ${cfg.localCommands} ''; }; - } // (listToAttrs (flip map interfaces (i: + } // (listToAttrs (foreach interfaces (i: let deviceDependency = if (config.boot.isContainer || i.name == "lo") then [] diff --git a/nixos/tests/networking.nix b/nixos/tests/networking.nix index ed9f287d558..9553b52850e 100644 --- a/nixos/tests/networking.nix +++ b/nixos/tests/networking.nix @@ -21,7 +21,7 @@ let useNetworkd = networkd; firewall.checkReversePath = true; firewall.allowedUDPPorts = [ 547 ]; - interfaces = mkOverride 0 (listToAttrs (flip map vlanIfs (n: + interfaces = mkOverride 0 (listToAttrs (foreach vlanIfs (n: nameValuePair "eth${toString n}" { ipv4.addresses = [ { address = "192.168.${toString n}.1"; prefixLength = 24; } ]; ipv6.addresses = [ { address = "fd00:1234:5678:${toString n}::1"; prefixLength = 64; } ]; diff --git a/pkgs/applications/networking/irc/weechat/wrapper.nix b/pkgs/applications/networking/irc/weechat/wrapper.nix index 6dcd9a31e5e..502a7917a09 100644 --- a/pkgs/applications/networking/irc/weechat/wrapper.nix +++ b/pkgs/applications/networking/irc/weechat/wrapper.nix @@ -54,7 +54,7 @@ let init = let init = builtins.replaceStrings [ "\n" ] [ ";" ] (config.init or ""); - mkScript = drv: lib.flip map drv.scripts (script: "/script load ${drv}/share/${script}"); + mkScript = drv: lib.foreach drv.scripts (script: "/script load ${drv}/share/${script}"); scripts = builtins.concatStringsSep ";" (lib.foldl (scripts: drv: scripts ++ mkScript drv) [ ] (config.scripts or [])); diff --git a/pkgs/applications/networking/remote/citrix-receiver/default.nix b/pkgs/applications/networking/remote/citrix-receiver/default.nix index d6e25ae4e7b..7bf465ef94a 100644 --- a/pkgs/applications/networking/remote/citrix-receiver/default.nix +++ b/pkgs/applications/networking/remote/citrix-receiver/default.nix @@ -58,7 +58,7 @@ let versions = [ "13.8.0" "13.9.0" "13.9.1" ]; in lib.listToAttrs - (lib.flip map versions + (lib.foreach versions (v: lib.nameValuePair v (throw "Unsupported citrix_receiver version: ${v}"))); in deprecatedVersions // supportedVersions; diff --git a/pkgs/applications/networking/remote/citrix-workspace/default.nix b/pkgs/applications/networking/remote/citrix-workspace/default.nix index 13a16a6e224..665a8669fe2 100644 --- a/pkgs/applications/networking/remote/citrix-workspace/default.nix +++ b/pkgs/applications/networking/remote/citrix-workspace/default.nix @@ -59,7 +59,7 @@ let versions = [ ]; in lib.listToAttrs - (lib.flip map versions + (lib.foreach versions (v: lib.nameValuePair v (throw "Unsupported citrix_workspace version: ${v}"))); in deprecatedVersions // supportedVersions; diff --git a/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix b/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix index 1115e4e232f..9fcaea2925c 100644 --- a/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix +++ b/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix @@ -4,7 +4,7 @@ let - hunspellDirs = with lib; makeSearchPath ":" (flatten (flip map langs (lang: [ + hunspellDirs = with lib; makeSearchPath ":" (flatten (foreach langs (lang: [ "${hunspellDicts.${lang}}/share/hunspell" "${hunspellDicts.${lang}}/share/myspell" "${hunspellDicts.${lang}}/share/myspell/dicts" -- cgit 1.4.1 From 91bb646e98808d594b339d3386f7963a546ccfb4 Mon Sep 17 00:00:00 2001 From: danbst Date: Mon, 5 Aug 2019 14:01:45 +0300 Subject: Revert "mass replace "flip map -> foreach"" This reverts commit 3b0534310c89d04fc3a9c5714b5a4d0f9fb0efca. --- nixos/doc/manual/default.nix | 2 +- nixos/lib/build-vms.nix | 6 +++--- nixos/maintainers/option-usages.nix | 2 +- nixos/modules/rename.nix | 2 +- nixos/modules/services/monitoring/ups.nix | 2 +- nixos/modules/services/networking/consul.nix | 2 +- nixos/modules/services/networking/hylafax/systemd.nix | 2 +- nixos/modules/services/networking/ssh/sshd.nix | 2 +- nixos/modules/services/x11/xautolock.nix | 2 +- nixos/modules/services/x11/xserver.nix | 2 +- nixos/modules/system/boot/loader/grub/grub.nix | 2 +- nixos/modules/tasks/network-interfaces-systemd.nix | 8 ++++---- nixos/modules/tasks/network-interfaces.nix | 12 ++++++------ nixos/tests/networking.nix | 2 +- pkgs/applications/networking/irc/weechat/wrapper.nix | 2 +- .../networking/remote/citrix-receiver/default.nix | 2 +- .../networking/remote/citrix-workspace/default.nix | 2 +- .../ibus-engines/ibus-typing-booster/wrapper.nix | 2 +- 18 files changed, 28 insertions(+), 28 deletions(-) diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix index 02dfeeefe3e..7fc0ad702f8 100644 --- a/nixos/doc/manual/default.nix +++ b/nixos/doc/manual/default.nix @@ -45,7 +45,7 @@ let + ""; in "${lib.concatStringsSep "\n" (map (p: describe (unpack p)) packages)}"; - optionsListDesc = lib.foreach optionsListVisible (opt: opt // { + optionsListDesc = lib.flip map optionsListVisible (opt: opt // { # Clean up declaration sites to not refer to the NixOS source tree. declarations = map stripAnyPrefixes opt.declarations; } diff --git a/nixos/lib/build-vms.nix b/nixos/lib/build-vms.nix index 2ecceb82fbe..6c92aa1ffa2 100644 --- a/nixos/lib/build-vms.nix +++ b/nixos/lib/build-vms.nix @@ -54,11 +54,11 @@ rec { machinesNumbered = zipLists machines (range 1 254); - nodes_ = foreach machinesNumbered (m: nameValuePair m.fst + nodes_ = flip map machinesNumbered (m: nameValuePair m.fst [ ( { config, nodes, ... }: let interfacesNumbered = zipLists config.virtualisation.vlans (range 1 255); - interfaces = foreach interfacesNumbered ({ fst, snd }: + interfaces = flip map interfacesNumbered ({ fst, snd }: nameValuePair "eth${toString snd}" { ipv4.addresses = [ { address = "192.168.${toString fst}.${toString m.snd}"; prefixLength = 24; @@ -88,7 +88,7 @@ rec { "${config.networking.hostName}\n")); virtualisation.qemu.options = - foreach interfacesNumbered + flip map interfacesNumbered ({ fst, snd }: qemuNICFlags snd fst m.snd); }; } diff --git a/nixos/maintainers/option-usages.nix b/nixos/maintainers/option-usages.nix index b207eaded41..a67a0ab960e 100644 --- a/nixos/maintainers/option-usages.nix +++ b/nixos/maintainers/option-usages.nix @@ -102,7 +102,7 @@ let # builtins multiply by 4 the memory usage and the time used to compute # each options. tryCollectOptions = moduleResult: - foreach (excludeOptions (collect isOption moduleResult)) (opt: + flip map (excludeOptions (collect isOption moduleResult)) (opt: { name = showOption opt.loc; } // builtins.tryEval (strict opt.value)); in keepNames ( diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index 218b1d9339a..e127782e85f 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -248,7 +248,7 @@ with lib; # KSM (mkRenamedOptionModule [ "hardware" "enableKSM" ] [ "hardware" "ksm" "enable" ]) - ] ++ (foreach [ "blackboxExporter" "collectdExporter" "fritzboxExporter" + ] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter" "jsonExporter" "minioExporter" "nginxExporter" "nodeExporter" "snmpExporter" "unifiExporter" "varnishExporter" ] (opt: mkRemovedOptionModule [ "services" "prometheus" "${opt}" ] '' diff --git a/nixos/modules/services/monitoring/ups.nix b/nixos/modules/services/monitoring/ups.nix index 57f0bfec574..bc755612fd9 100644 --- a/nixos/modules/services/monitoring/ups.nix +++ b/nixos/modules/services/monitoring/ups.nix @@ -225,7 +225,7 @@ in '' maxstartdelay = ${toString cfg.maxStartDelay} - ${flip concatStringsSep (foreach (attrValues cfg.ups) (ups: ups.summary)) " + ${flip concatStringsSep (flip map (attrValues cfg.ups) (ups: ups.summary)) " "} ''; diff --git a/nixos/modules/services/networking/consul.nix b/nixos/modules/services/networking/consul.nix index 78fca9326d3..3a92a883fbf 100644 --- a/nixos/modules/services/networking/consul.nix +++ b/nixos/modules/services/networking/consul.nix @@ -15,7 +15,7 @@ let ++ cfg.extraConfigFiles; devices = attrValues (filterAttrs (_: i: i != null) cfg.interface); - systemdDevices = foreach devices + systemdDevices = flip map devices (i: "sys-subsystem-net-devices-${utils.escapeSystemdPath i}.device"); in { diff --git a/nixos/modules/services/networking/hylafax/systemd.nix b/nixos/modules/services/networking/hylafax/systemd.nix index 527026c0076..ef177e4be34 100644 --- a/nixos/modules/services/networking/hylafax/systemd.nix +++ b/nixos/modules/services/networking/hylafax/systemd.nix @@ -7,7 +7,7 @@ let inherit (lib) concatStringsSep optionalString; cfg = config.services.hylafax; - mapModems = lib.foreach (lib.attrValues cfg.modems); + mapModems = lib.flip map (lib.attrValues cfg.modems); mkConfigFile = name: conf: # creates hylafax config file, diff --git a/nixos/modules/services/networking/ssh/sshd.nix b/nixos/modules/services/networking/ssh/sshd.nix index 005d8bfb61f..0f9d2420903 100644 --- a/nixos/modules/services/networking/ssh/sshd.nix +++ b/nixos/modules/services/networking/ssh/sshd.nix @@ -502,7 +502,7 @@ in assertions = [{ assertion = if cfg.forwardX11 then cfgc.setXAuthLocation else true; message = "cannot enable X11 forwarding without setting xauth location";}] - ++ foreach cfg.listenAddresses ({ addr, ... }: { + ++ flip map cfg.listenAddresses ({ addr, ... }: { assertion = addr != null; message = "addr must be specified in each listenAddresses entry"; }); diff --git a/nixos/modules/services/x11/xautolock.nix b/nixos/modules/services/x11/xautolock.nix index 51bdcae992e..cbe000058dc 100644 --- a/nixos/modules/services/x11/xautolock.nix +++ b/nixos/modules/services/x11/xautolock.nix @@ -129,7 +129,7 @@ in assertion = cfg.killer != null -> cfg.killtime >= 10; message = "killtime has to be at least 10 minutes according to `man xautolock`"; } - ] ++ (lib.foreach [ "locker" "notifier" "nowlocker" "killer" ] + ] ++ (lib.flip map [ "locker" "notifier" "nowlocker" "killer" ] (option: { assertion = cfg."${option}" != null -> builtins.substring 0 1 cfg."${option}" == "/"; diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index 4d28a45c2ce..82730c5e80c 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/nixos/modules/services/x11/xserver.nix @@ -75,7 +75,7 @@ let in imap1 mkHead cfg.xrandrHeads; xrandrDeviceSection = let - monitors = foreach xrandrHeads (h: '' + monitors = flip map xrandrHeads (h: '' Option "monitor-${h.config.output}" "${h.name}" ''); # First option is indented through the space in the config but any diff --git a/nixos/modules/system/boot/loader/grub/grub.nix b/nixos/modules/system/boot/loader/grub/grub.nix index 84753d77cc4..4e4d14985b0 100644 --- a/nixos/modules/system/boot/loader/grub/grub.nix +++ b/nixos/modules/system/boot/loader/grub/grub.nix @@ -684,7 +684,7 @@ in assertion = if args.efiSysMountPoint == null then true else hasPrefix "/" args.efiSysMountPoint; message = "EFI paths must be absolute, not ${args.efiSysMountPoint}"; } - ] ++ foreach args.devices (device: { + ] ++ flip map args.devices (device: { assertion = device == "nodev" || hasPrefix "/" device; message = "GRUB devices must be absolute paths, not ${device} in ${args.path}"; })); diff --git a/nixos/modules/tasks/network-interfaces-systemd.nix b/nixos/modules/tasks/network-interfaces-systemd.nix index 2612d13da4f..857aaf1e6e3 100644 --- a/nixos/modules/tasks/network-interfaces-systemd.nix +++ b/nixos/modules/tasks/network-interfaces-systemd.nix @@ -74,7 +74,7 @@ in enable = true; networks."99-main" = genericNetwork mkDefault; } - (mkMerge (foreach interfaces (i: { + (mkMerge (flip map interfaces (i: { netdevs = mkIf i.virtual ({ "40-${i.name}" = { netdevConfig = { @@ -90,7 +90,7 @@ in name = mkDefault i.name; DHCP = mkForce (dhcpStr (if i.useDHCP != null then i.useDHCP else cfg.useDHCP && interfaceIps i == [ ])); - address = foreach (interfaceIps i) + address = flip map (interfaceIps i) (ip: "${ip.address}/${toString ip.prefixLength}"); networkConfig.IPv6PrivacyExtensions = "kernel"; } ]; @@ -102,7 +102,7 @@ in Kind = "bridge"; }; }; - networks = listToAttrs (foreach bridge.interfaces (bi: + networks = listToAttrs (flip map bridge.interfaces (bi: nameValuePair "40-${bi}" (mkMerge [ (genericNetwork (mkOverride 999)) { DHCP = mkOverride 0 (dhcpStr false); networkConfig.Bridge = name; @@ -173,7 +173,7 @@ in }; - networks = listToAttrs (foreach bond.interfaces (bi: + networks = listToAttrs (flip map bond.interfaces (bi: nameValuePair "40-${bi}" (mkMerge [ (genericNetwork (mkOverride 999)) { DHCP = mkOverride 0 (dhcpStr false); networkConfig.Bond = name; diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index 2af20e05b05..f9b0eb330bf 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -926,7 +926,7 @@ in warnings = concatMap (i: i.warnings) interfaces; assertions = - (foreach interfaces (i: { + (flip map interfaces (i: { # With the linux kernel, interface name length is limited by IFNAMSIZ # to 16 bytes, including the trailing null byte. # See include/linux/if.h in the kernel sources @@ -934,12 +934,12 @@ in message = '' The name of networking.interfaces."${i.name}" is too long, it needs to be less than 16 characters. ''; - })) ++ (foreach slaveIfs (i: { + })) ++ (flip map slaveIfs (i: { assertion = i.ipv4.addresses == [ ] && i.ipv6.addresses == [ ]; message = '' The networking.interfaces."${i.name}" must not have any defined ips when it is a slave. ''; - })) ++ (foreach interfaces (i: { + })) ++ (flip map interfaces (i: { assertion = i.preferTempAddress -> cfg.enableIPv6; message = '' Temporary addresses are only needed when IPv6 is enabled. @@ -967,8 +967,8 @@ in "net.ipv6.conf.default.disable_ipv6" = mkDefault (!cfg.enableIPv6); "net.ipv6.conf.all.forwarding" = mkDefault (any (i: i.proxyARP) interfaces); } // listToAttrs (flip concatMap (filter (i: i.proxyARP) interfaces) - (i: foreach [ "4" "6" ] (v: nameValuePair "net.ipv${v}.conf.${i.name}.proxy_arp" true))) - // listToAttrs (foreach (filter (i: i.preferTempAddress) interfaces) + (i: flip map [ "4" "6" ] (v: nameValuePair "net.ipv${v}.conf.${i.name}.proxy_arp" true))) + // listToAttrs (flip map (filter (i: i.preferTempAddress) interfaces) (i: nameValuePair "net.ipv6.conf.${i.name}.use_tempaddr" 2)); # Capabilities won't work unless we have at-least a 4.3 Linux @@ -1051,7 +1051,7 @@ in ${cfg.localCommands} ''; }; - } // (listToAttrs (foreach interfaces (i: + } // (listToAttrs (flip map interfaces (i: let deviceDependency = if (config.boot.isContainer || i.name == "lo") then [] diff --git a/nixos/tests/networking.nix b/nixos/tests/networking.nix index 9553b52850e..ed9f287d558 100644 --- a/nixos/tests/networking.nix +++ b/nixos/tests/networking.nix @@ -21,7 +21,7 @@ let useNetworkd = networkd; firewall.checkReversePath = true; firewall.allowedUDPPorts = [ 547 ]; - interfaces = mkOverride 0 (listToAttrs (foreach vlanIfs (n: + interfaces = mkOverride 0 (listToAttrs (flip map vlanIfs (n: nameValuePair "eth${toString n}" { ipv4.addresses = [ { address = "192.168.${toString n}.1"; prefixLength = 24; } ]; ipv6.addresses = [ { address = "fd00:1234:5678:${toString n}::1"; prefixLength = 64; } ]; diff --git a/pkgs/applications/networking/irc/weechat/wrapper.nix b/pkgs/applications/networking/irc/weechat/wrapper.nix index 502a7917a09..6dcd9a31e5e 100644 --- a/pkgs/applications/networking/irc/weechat/wrapper.nix +++ b/pkgs/applications/networking/irc/weechat/wrapper.nix @@ -54,7 +54,7 @@ let init = let init = builtins.replaceStrings [ "\n" ] [ ";" ] (config.init or ""); - mkScript = drv: lib.foreach drv.scripts (script: "/script load ${drv}/share/${script}"); + mkScript = drv: lib.flip map drv.scripts (script: "/script load ${drv}/share/${script}"); scripts = builtins.concatStringsSep ";" (lib.foldl (scripts: drv: scripts ++ mkScript drv) [ ] (config.scripts or [])); diff --git a/pkgs/applications/networking/remote/citrix-receiver/default.nix b/pkgs/applications/networking/remote/citrix-receiver/default.nix index 7bf465ef94a..d6e25ae4e7b 100644 --- a/pkgs/applications/networking/remote/citrix-receiver/default.nix +++ b/pkgs/applications/networking/remote/citrix-receiver/default.nix @@ -58,7 +58,7 @@ let versions = [ "13.8.0" "13.9.0" "13.9.1" ]; in lib.listToAttrs - (lib.foreach versions + (lib.flip map versions (v: lib.nameValuePair v (throw "Unsupported citrix_receiver version: ${v}"))); in deprecatedVersions // supportedVersions; diff --git a/pkgs/applications/networking/remote/citrix-workspace/default.nix b/pkgs/applications/networking/remote/citrix-workspace/default.nix index 665a8669fe2..13a16a6e224 100644 --- a/pkgs/applications/networking/remote/citrix-workspace/default.nix +++ b/pkgs/applications/networking/remote/citrix-workspace/default.nix @@ -59,7 +59,7 @@ let versions = [ ]; in lib.listToAttrs - (lib.foreach versions + (lib.flip map versions (v: lib.nameValuePair v (throw "Unsupported citrix_workspace version: ${v}"))); in deprecatedVersions // supportedVersions; diff --git a/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix b/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix index 9fcaea2925c..1115e4e232f 100644 --- a/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix +++ b/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix @@ -4,7 +4,7 @@ let - hunspellDirs = with lib; makeSearchPath ":" (flatten (foreach langs (lang: [ + hunspellDirs = with lib; makeSearchPath ":" (flatten (flip map langs (lang: [ "${hunspellDicts.${lang}}/share/hunspell" "${hunspellDicts.${lang}}/share/myspell" "${hunspellDicts.${lang}}/share/myspell/dicts" -- cgit 1.4.1 From 0f8596ab3f05321e36d9bd53ea7f048b7f0b62e3 Mon Sep 17 00:00:00 2001 From: danbst Date: Mon, 5 Aug 2019 14:03:38 +0300 Subject: mass replace "flip map -> forEach" See `forEach`-introduction commit. ``` rg 'flip map ' --files-with-matches | xargs sed -i 's/flip map /forEach /g' ``` --- nixos/doc/manual/default.nix | 2 +- nixos/lib/build-vms.nix | 6 +++--- nixos/maintainers/option-usages.nix | 2 +- nixos/modules/rename.nix | 2 +- nixos/modules/services/monitoring/ups.nix | 2 +- nixos/modules/services/networking/consul.nix | 2 +- nixos/modules/services/networking/hylafax/systemd.nix | 2 +- nixos/modules/services/networking/ssh/sshd.nix | 2 +- nixos/modules/services/x11/xautolock.nix | 2 +- nixos/modules/services/x11/xserver.nix | 2 +- nixos/modules/system/boot/loader/grub/grub.nix | 2 +- nixos/modules/tasks/network-interfaces-systemd.nix | 8 ++++---- nixos/modules/tasks/network-interfaces.nix | 12 ++++++------ nixos/tests/networking.nix | 2 +- pkgs/applications/networking/irc/weechat/wrapper.nix | 2 +- .../networking/remote/citrix-receiver/default.nix | 2 +- .../networking/remote/citrix-workspace/default.nix | 2 +- .../ibus-engines/ibus-typing-booster/wrapper.nix | 2 +- 18 files changed, 28 insertions(+), 28 deletions(-) diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix index 7fc0ad702f8..0963560a5bf 100644 --- a/nixos/doc/manual/default.nix +++ b/nixos/doc/manual/default.nix @@ -45,7 +45,7 @@ let + ""; in "${lib.concatStringsSep "\n" (map (p: describe (unpack p)) packages)}"; - optionsListDesc = lib.flip map optionsListVisible (opt: opt // { + optionsListDesc = lib.forEach optionsListVisible (opt: opt // { # Clean up declaration sites to not refer to the NixOS source tree. declarations = map stripAnyPrefixes opt.declarations; } diff --git a/nixos/lib/build-vms.nix b/nixos/lib/build-vms.nix index 6c92aa1ffa2..00ab189be0f 100644 --- a/nixos/lib/build-vms.nix +++ b/nixos/lib/build-vms.nix @@ -54,11 +54,11 @@ rec { machinesNumbered = zipLists machines (range 1 254); - nodes_ = flip map machinesNumbered (m: nameValuePair m.fst + nodes_ = forEach machinesNumbered (m: nameValuePair m.fst [ ( { config, nodes, ... }: let interfacesNumbered = zipLists config.virtualisation.vlans (range 1 255); - interfaces = flip map interfacesNumbered ({ fst, snd }: + interfaces = forEach interfacesNumbered ({ fst, snd }: nameValuePair "eth${toString snd}" { ipv4.addresses = [ { address = "192.168.${toString fst}.${toString m.snd}"; prefixLength = 24; @@ -88,7 +88,7 @@ rec { "${config.networking.hostName}\n")); virtualisation.qemu.options = - flip map interfacesNumbered + forEach interfacesNumbered ({ fst, snd }: qemuNICFlags snd fst m.snd); }; } diff --git a/nixos/maintainers/option-usages.nix b/nixos/maintainers/option-usages.nix index a67a0ab960e..11247666ecd 100644 --- a/nixos/maintainers/option-usages.nix +++ b/nixos/maintainers/option-usages.nix @@ -102,7 +102,7 @@ let # builtins multiply by 4 the memory usage and the time used to compute # each options. tryCollectOptions = moduleResult: - flip map (excludeOptions (collect isOption moduleResult)) (opt: + forEach (excludeOptions (collect isOption moduleResult)) (opt: { name = showOption opt.loc; } // builtins.tryEval (strict opt.value)); in keepNames ( diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index e127782e85f..c226f28034d 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -248,7 +248,7 @@ with lib; # KSM (mkRenamedOptionModule [ "hardware" "enableKSM" ] [ "hardware" "ksm" "enable" ]) - ] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter" + ] ++ (forEach [ "blackboxExporter" "collectdExporter" "fritzboxExporter" "jsonExporter" "minioExporter" "nginxExporter" "nodeExporter" "snmpExporter" "unifiExporter" "varnishExporter" ] (opt: mkRemovedOptionModule [ "services" "prometheus" "${opt}" ] '' diff --git a/nixos/modules/services/monitoring/ups.nix b/nixos/modules/services/monitoring/ups.nix index bc755612fd9..429b40227d4 100644 --- a/nixos/modules/services/monitoring/ups.nix +++ b/nixos/modules/services/monitoring/ups.nix @@ -225,7 +225,7 @@ in '' maxstartdelay = ${toString cfg.maxStartDelay} - ${flip concatStringsSep (flip map (attrValues cfg.ups) (ups: ups.summary)) " + ${flip concatStringsSep (forEach (attrValues cfg.ups) (ups: ups.summary)) " "} ''; diff --git a/nixos/modules/services/networking/consul.nix b/nixos/modules/services/networking/consul.nix index 3a92a883fbf..f080f12eacc 100644 --- a/nixos/modules/services/networking/consul.nix +++ b/nixos/modules/services/networking/consul.nix @@ -15,7 +15,7 @@ let ++ cfg.extraConfigFiles; devices = attrValues (filterAttrs (_: i: i != null) cfg.interface); - systemdDevices = flip map devices + systemdDevices = forEach devices (i: "sys-subsystem-net-devices-${utils.escapeSystemdPath i}.device"); in { diff --git a/nixos/modules/services/networking/hylafax/systemd.nix b/nixos/modules/services/networking/hylafax/systemd.nix index ef177e4be34..0c6602e7f8a 100644 --- a/nixos/modules/services/networking/hylafax/systemd.nix +++ b/nixos/modules/services/networking/hylafax/systemd.nix @@ -7,7 +7,7 @@ let inherit (lib) concatStringsSep optionalString; cfg = config.services.hylafax; - mapModems = lib.flip map (lib.attrValues cfg.modems); + mapModems = lib.forEach (lib.attrValues cfg.modems); mkConfigFile = name: conf: # creates hylafax config file, diff --git a/nixos/modules/services/networking/ssh/sshd.nix b/nixos/modules/services/networking/ssh/sshd.nix index 0f9d2420903..91fc7d72bc6 100644 --- a/nixos/modules/services/networking/ssh/sshd.nix +++ b/nixos/modules/services/networking/ssh/sshd.nix @@ -502,7 +502,7 @@ in assertions = [{ assertion = if cfg.forwardX11 then cfgc.setXAuthLocation else true; message = "cannot enable X11 forwarding without setting xauth location";}] - ++ flip map cfg.listenAddresses ({ addr, ... }: { + ++ forEach cfg.listenAddresses ({ addr, ... }: { assertion = addr != null; message = "addr must be specified in each listenAddresses entry"; }); diff --git a/nixos/modules/services/x11/xautolock.nix b/nixos/modules/services/x11/xautolock.nix index cbe000058dc..10eef8aefbc 100644 --- a/nixos/modules/services/x11/xautolock.nix +++ b/nixos/modules/services/x11/xautolock.nix @@ -129,7 +129,7 @@ in assertion = cfg.killer != null -> cfg.killtime >= 10; message = "killtime has to be at least 10 minutes according to `man xautolock`"; } - ] ++ (lib.flip map [ "locker" "notifier" "nowlocker" "killer" ] + ] ++ (lib.forEach [ "locker" "notifier" "nowlocker" "killer" ] (option: { assertion = cfg."${option}" != null -> builtins.substring 0 1 cfg."${option}" == "/"; diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index 82730c5e80c..e716d3bcdc6 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/nixos/modules/services/x11/xserver.nix @@ -75,7 +75,7 @@ let in imap1 mkHead cfg.xrandrHeads; xrandrDeviceSection = let - monitors = flip map xrandrHeads (h: '' + monitors = forEach xrandrHeads (h: '' Option "monitor-${h.config.output}" "${h.name}" ''); # First option is indented through the space in the config but any diff --git a/nixos/modules/system/boot/loader/grub/grub.nix b/nixos/modules/system/boot/loader/grub/grub.nix index 4e4d14985b0..eca9dad6422 100644 --- a/nixos/modules/system/boot/loader/grub/grub.nix +++ b/nixos/modules/system/boot/loader/grub/grub.nix @@ -684,7 +684,7 @@ in assertion = if args.efiSysMountPoint == null then true else hasPrefix "/" args.efiSysMountPoint; message = "EFI paths must be absolute, not ${args.efiSysMountPoint}"; } - ] ++ flip map args.devices (device: { + ] ++ forEach args.devices (device: { assertion = device == "nodev" || hasPrefix "/" device; message = "GRUB devices must be absolute paths, not ${device} in ${args.path}"; })); diff --git a/nixos/modules/tasks/network-interfaces-systemd.nix b/nixos/modules/tasks/network-interfaces-systemd.nix index 857aaf1e6e3..fbca54978e5 100644 --- a/nixos/modules/tasks/network-interfaces-systemd.nix +++ b/nixos/modules/tasks/network-interfaces-systemd.nix @@ -74,7 +74,7 @@ in enable = true; networks."99-main" = genericNetwork mkDefault; } - (mkMerge (flip map interfaces (i: { + (mkMerge (forEach interfaces (i: { netdevs = mkIf i.virtual ({ "40-${i.name}" = { netdevConfig = { @@ -90,7 +90,7 @@ in name = mkDefault i.name; DHCP = mkForce (dhcpStr (if i.useDHCP != null then i.useDHCP else cfg.useDHCP && interfaceIps i == [ ])); - address = flip map (interfaceIps i) + address = forEach (interfaceIps i) (ip: "${ip.address}/${toString ip.prefixLength}"); networkConfig.IPv6PrivacyExtensions = "kernel"; } ]; @@ -102,7 +102,7 @@ in Kind = "bridge"; }; }; - networks = listToAttrs (flip map bridge.interfaces (bi: + networks = listToAttrs (forEach bridge.interfaces (bi: nameValuePair "40-${bi}" (mkMerge [ (genericNetwork (mkOverride 999)) { DHCP = mkOverride 0 (dhcpStr false); networkConfig.Bridge = name; @@ -173,7 +173,7 @@ in }; - networks = listToAttrs (flip map bond.interfaces (bi: + networks = listToAttrs (forEach bond.interfaces (bi: nameValuePair "40-${bi}" (mkMerge [ (genericNetwork (mkOverride 999)) { DHCP = mkOverride 0 (dhcpStr false); networkConfig.Bond = name; diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index f9b0eb330bf..7c98010bd3d 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -926,7 +926,7 @@ in warnings = concatMap (i: i.warnings) interfaces; assertions = - (flip map interfaces (i: { + (forEach interfaces (i: { # With the linux kernel, interface name length is limited by IFNAMSIZ # to 16 bytes, including the trailing null byte. # See include/linux/if.h in the kernel sources @@ -934,12 +934,12 @@ in message = '' The name of networking.interfaces."${i.name}" is too long, it needs to be less than 16 characters. ''; - })) ++ (flip map slaveIfs (i: { + })) ++ (forEach slaveIfs (i: { assertion = i.ipv4.addresses == [ ] && i.ipv6.addresses == [ ]; message = '' The networking.interfaces."${i.name}" must not have any defined ips when it is a slave. ''; - })) ++ (flip map interfaces (i: { + })) ++ (forEach interfaces (i: { assertion = i.preferTempAddress -> cfg.enableIPv6; message = '' Temporary addresses are only needed when IPv6 is enabled. @@ -967,8 +967,8 @@ in "net.ipv6.conf.default.disable_ipv6" = mkDefault (!cfg.enableIPv6); "net.ipv6.conf.all.forwarding" = mkDefault (any (i: i.proxyARP) interfaces); } // listToAttrs (flip concatMap (filter (i: i.proxyARP) interfaces) - (i: flip map [ "4" "6" ] (v: nameValuePair "net.ipv${v}.conf.${i.name}.proxy_arp" true))) - // listToAttrs (flip map (filter (i: i.preferTempAddress) interfaces) + (i: forEach [ "4" "6" ] (v: nameValuePair "net.ipv${v}.conf.${i.name}.proxy_arp" true))) + // listToAttrs (forEach (filter (i: i.preferTempAddress) interfaces) (i: nameValuePair "net.ipv6.conf.${i.name}.use_tempaddr" 2)); # Capabilities won't work unless we have at-least a 4.3 Linux @@ -1051,7 +1051,7 @@ in ${cfg.localCommands} ''; }; - } // (listToAttrs (flip map interfaces (i: + } // (listToAttrs (forEach interfaces (i: let deviceDependency = if (config.boot.isContainer || i.name == "lo") then [] diff --git a/nixos/tests/networking.nix b/nixos/tests/networking.nix index ed9f287d558..ff769886c57 100644 --- a/nixos/tests/networking.nix +++ b/nixos/tests/networking.nix @@ -21,7 +21,7 @@ let useNetworkd = networkd; firewall.checkReversePath = true; firewall.allowedUDPPorts = [ 547 ]; - interfaces = mkOverride 0 (listToAttrs (flip map vlanIfs (n: + interfaces = mkOverride 0 (listToAttrs (forEach vlanIfs (n: nameValuePair "eth${toString n}" { ipv4.addresses = [ { address = "192.168.${toString n}.1"; prefixLength = 24; } ]; ipv6.addresses = [ { address = "fd00:1234:5678:${toString n}::1"; prefixLength = 64; } ]; diff --git a/pkgs/applications/networking/irc/weechat/wrapper.nix b/pkgs/applications/networking/irc/weechat/wrapper.nix index 6dcd9a31e5e..5fe20829c03 100644 --- a/pkgs/applications/networking/irc/weechat/wrapper.nix +++ b/pkgs/applications/networking/irc/weechat/wrapper.nix @@ -54,7 +54,7 @@ let init = let init = builtins.replaceStrings [ "\n" ] [ ";" ] (config.init or ""); - mkScript = drv: lib.flip map drv.scripts (script: "/script load ${drv}/share/${script}"); + mkScript = drv: lib.forEach drv.scripts (script: "/script load ${drv}/share/${script}"); scripts = builtins.concatStringsSep ";" (lib.foldl (scripts: drv: scripts ++ mkScript drv) [ ] (config.scripts or [])); diff --git a/pkgs/applications/networking/remote/citrix-receiver/default.nix b/pkgs/applications/networking/remote/citrix-receiver/default.nix index d6e25ae4e7b..45012d32f45 100644 --- a/pkgs/applications/networking/remote/citrix-receiver/default.nix +++ b/pkgs/applications/networking/remote/citrix-receiver/default.nix @@ -58,7 +58,7 @@ let versions = [ "13.8.0" "13.9.0" "13.9.1" ]; in lib.listToAttrs - (lib.flip map versions + (lib.forEach versions (v: lib.nameValuePair v (throw "Unsupported citrix_receiver version: ${v}"))); in deprecatedVersions // supportedVersions; diff --git a/pkgs/applications/networking/remote/citrix-workspace/default.nix b/pkgs/applications/networking/remote/citrix-workspace/default.nix index 13a16a6e224..aa0541728aa 100644 --- a/pkgs/applications/networking/remote/citrix-workspace/default.nix +++ b/pkgs/applications/networking/remote/citrix-workspace/default.nix @@ -59,7 +59,7 @@ let versions = [ ]; in lib.listToAttrs - (lib.flip map versions + (lib.forEach versions (v: lib.nameValuePair v (throw "Unsupported citrix_workspace version: ${v}"))); in deprecatedVersions // supportedVersions; diff --git a/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix b/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix index 1115e4e232f..56ddf93af45 100644 --- a/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix +++ b/pkgs/tools/inputmethods/ibus-engines/ibus-typing-booster/wrapper.nix @@ -4,7 +4,7 @@ let - hunspellDirs = with lib; makeSearchPath ":" (flatten (flip map langs (lang: [ + hunspellDirs = with lib; makeSearchPath ":" (flatten (forEach langs (lang: [ "${hunspellDicts.${lang}}/share/hunspell" "${hunspellDicts.${lang}}/share/myspell" "${hunspellDicts.${lang}}/share/myspell/dicts" -- cgit 1.4.1 From d0413360d3a6c51dc56d4ce0ab07ad4678a83ada Mon Sep 17 00:00:00 2001 From: danbst Date: Mon, 5 Aug 2019 14:06:20 +0300 Subject: rename foreach -> forEach --- lib/lists.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/lists.nix b/lib/lists.nix index f9953720ee1..e4fcf959b60 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -24,15 +24,15 @@ rec { /* Apply the function to each element in the list. Same as `map`, but arguments flipped. - Type: foreach :: [a] -> (a -> b) -> [b] + Type: forEach :: [a] -> (a -> b) -> [b] Example: - foreach [ 1 2 ] (x: + forEach [ 1 2 ] (x: toString x ) => [ "1" "2" ] */ - foreach = xs: f: map f xs; + forEach = xs: f: map f xs; /* “right fold” a binary function `op` between successive elements of `list` with `nul' as the starting value, i.e., -- cgit 1.4.1 From 210c57883e659f5a1d4f5c29ed5970df93ee2940 Mon Sep 17 00:00:00 2001 From: danbst Date: Mon, 5 Aug 2019 14:10:35 +0300 Subject: and one more place --- lib/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/default.nix b/lib/default.nix index f876c57e25c..18d2dfae1e1 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -71,7 +71,7 @@ let zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil recursiveUpdate matchAttrs overrideExisting getOutput getBin getLib getDev chooseDevOutputs zipWithNames zip; - inherit (lists) singleton foreach foldr fold foldl foldl' imap0 imap1 + inherit (lists) singleton forEach foldr fold foldl foldl' imap0 imap1 concatMap flatten remove findSingle findFirst any all count optional optionals toList range partition zipListsWith zipLists reverseList listDfs toposort sort naturalSort compareLists take -- cgit 1.4.1 From 29ba0a0adff274f5ea0d93246be3f2957d234a7b Mon Sep 17 00:00:00 2001 From: danbst Date: Mon, 5 Aug 2019 14:34:51 +0300 Subject: add release notes --- nixos/doc/manual/release-notes/rl-1909.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nixos/doc/manual/release-notes/rl-1909.xml b/nixos/doc/manual/release-notes/rl-1909.xml index 6f049005ab6..398234cf025 100644 --- a/nixos/doc/manual/release-notes/rl-1909.xml +++ b/nixos/doc/manual/release-notes/rl-1909.xml @@ -387,6 +387,18 @@ installer after creating /var/lib/nextcloud. + + + There exists now lib.forEach, which is like map, but with + arguments flipped. When mapping function body spans many lines (or has nested + maps), it is often hard to follow which list is modified. + + + Previous solution to this problem was either to use lib.flip map + idiom or extract that anonymous mapping function to a named one. Both can still be used + but lib.forEach is preferred over lib.flip map. + + -- cgit 1.4.1