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.
This commit is contained in:
name_snrl 2023-11-13 22:20:24 +05:00
parent 771cae0903
commit e3a7f716c2

View File

@ -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.
'';
};