about summary refs log tree commit diff
path: root/nixos/modules/programs
diff options
context:
space:
mode:
authorname_snrl <Demogorgon-74@ya.ru>2023-11-13 22:20:24 +0500
committername_snrl <Demogorgon-74@ya.ru>2023-11-13 23:06:45 +0500
commite3a7f716c230dfff5f5deb9c454ddd4f4621eb79 (patch)
tree527f413471362526793ea57db24b1eef6eb37efb /nixos/modules/programs
parent771cae0903f05ad58ee5831c03d898a4a26550bd (diff)
downloadnixlib-e3a7f716c230dfff5f5deb9c454ddd4f4621eb79.tar
nixlib-e3a7f716c230dfff5f5deb9c454ddd4f4621eb79.tar.gz
nixlib-e3a7f716c230dfff5f5deb9c454ddd4f4621eb79.tar.bz2
nixlib-e3a7f716c230dfff5f5deb9c454ddd4f4621eb79.tar.lz
nixlib-e3a7f716c230dfff5f5deb9c454ddd4f4621eb79.tar.xz
nixlib-e3a7f716c230dfff5f5deb9c454ddd4f4621eb79.tar.zst
nixlib-e3a7f716c230dfff5f5deb9c454ddd4f4621eb79.zip
nixos/sway: refactoring of `package` option
Instead of the `defaultSwayPackage` variable that overrides `pkgs.sway`, use a
function that will override the user-defined package, but only if the package
contains the necessary arguments.
Diffstat (limited to 'nixos/modules/programs')
-rw-r--r--nixos/modules/programs/wayland/sway.nix43
1 files changed, 30 insertions, 13 deletions
diff --git a/nixos/modules/programs/wayland/sway.nix b/nixos/modules/programs/wayland/sway.nix
index 698d9c2b46c4..bb381196bdec 100644
--- a/nixos/modules/programs/wayland/sway.nix
+++ b/nixos/modules/programs/wayland/sway.nix
@@ -26,13 +26,28 @@ let
     };
   };
 
-  defaultSwayPackage = pkgs.sway.override {
-    extraSessionCommands = cfg.extraSessionCommands;
-    extraOptions = cfg.extraOptions;
-    withBaseWrapper = cfg.wrapperFeatures.base;
-    withGtkWrapper = cfg.wrapperFeatures.gtk;
-    isNixOS = true;
-  };
+  genFinalPackage = pkg:
+    let
+      expectedArgs = lib.naturalSort [
+        "extraSessionCommands"
+        "extraOptions"
+        "withBaseWrapper"
+        "withGtkWrapper"
+        "isNixOS"
+      ];
+      existedArgs = with lib;
+        naturalSort
+        (intersectLists expectedArgs (attrNames (functionArgs pkg.override)));
+    in if existedArgs != expectedArgs then
+      pkg
+    else
+      pkg.override {
+        extraSessionCommands = cfg.extraSessionCommands;
+        extraOptions = cfg.extraOptions;
+        withBaseWrapper = cfg.wrapperFeatures.base;
+        withGtkWrapper = cfg.wrapperFeatures.gtk;
+        isNixOS = true;
+      };
 in {
   options.programs.sway = {
     enable = mkEnableOption (lib.mdDoc ''
@@ -44,14 +59,16 @@ in {
 
     package = mkOption {
       type = with types; nullOr package;
-      default = defaultSwayPackage;
+      default = pkgs.sway;
+      apply = p: if p == null then null else genFinalPackage p;
       defaultText = literalExpression "pkgs.sway";
       description = lib.mdDoc ''
-        Sway package to use. Will override the options
-        'wrapperFeatures', 'extraSessionCommands', and 'extraOptions'.
-        Set to `null` to not add any Sway package to your
-        path. This should be done if you want to use the Home Manager Sway
-        module to install Sway.
+        Sway package to use. If the package does not contain the override arguments
+        `extraSessionCommands`, `extraOptions`, `withBaseWrapper`, `withGtkWrapper`,
+        `isNixOS`, then the module options {option}`wrapperFeatures`,
+        {option}`wrapperFeatures` and {option}`wrapperFeatures` will have no effect.
+        Set to `null` to not add any Sway package to your path. This should be done if
+        you want to use the Home Manager Sway module to install Sway.
       '';
     };