about summary refs log tree commit diff
path: root/nixos/lib/utils.nix
diff options
context:
space:
mode:
authorSandro Jäckel <sandro.jaeckel@sap.com>2022-04-11 10:51:54 +0200
committerSandro Jäckel <sandro.jaeckel@sap.com>2022-04-11 15:42:49 +0200
commit28539842d8c2b4a41c7ab4b31da5eeae828dbe2f (patch)
treeed8a417708d6f25d570ce0094cf19a71e199d78f /nixos/lib/utils.nix
parent28e936ba64c015caa1ce1be21ea7c790898ce336 (diff)
nixos/utils: move removePackagesByName to here from gnome
Diffstat (limited to 'nixos/lib/utils.nix')
-rw-r--r--nixos/lib/utils.nix16
1 files changed, 16 insertions, 0 deletions
diff --git a/nixos/lib/utils.nix b/nixos/lib/utils.nix
index 80341dd48fcd5..497d98aa4d195 100644
--- a/nixos/lib/utils.nix
+++ b/nixos/lib/utils.nix
@@ -194,6 +194,22 @@ rec {
       (( ! $inherit_errexit_enabled )) && shopt -u inherit_errexit
     '';
 
+  /* Remove packages of packagesToRemove from packages, based on their names.
+     Relies on package names and has quadratic complexity so use with caution!
+
+     Type:
+       removePackagesByName :: [package] -> [package] -> [package]
+
+     Example:
+       removePackagesByName [ nautilus file-roller ] [ file-roller totem ]
+       => [ nautilus ]
+  */
+  removePackagesByName = packages: packagesToRemove:
+    let
+      namesToRemove = map lib.getName packagesToRemove;
+    in
+      lib.filter (x: !(builtins.elem (lib.getName x) namesToRemove)) packages;
+
   systemdUtils = {
     lib = import ./systemd-lib.nix { inherit lib config pkgs; };
     unitOptions = import ./systemd-unit-options.nix { inherit lib systemdUtils; };