Merge pull request #267261 from name-snrl/make-overriding-sway-package-easier

nixos/sway: refactoring of `package` option
This commit is contained in:
Thiago Kenji Okada 2023-12-21 10:34:16 +00:00 committed by GitHub
commit ad16ca96e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,13 +26,28 @@ let
}; };
}; };
defaultSwayPackage = pkgs.sway.override { genFinalPackage = pkg:
extraSessionCommands = cfg.extraSessionCommands; let
extraOptions = cfg.extraOptions; expectedArgs = lib.naturalSort [
withBaseWrapper = cfg.wrapperFeatures.base; "extraSessionCommands"
withGtkWrapper = cfg.wrapperFeatures.gtk; "extraOptions"
isNixOS = true; "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 { in {
options.programs.sway = { options.programs.sway = {
enable = mkEnableOption (lib.mdDoc '' enable = mkEnableOption (lib.mdDoc ''
@ -44,14 +59,16 @@ in {
package = mkOption { package = mkOption {
type = with types; nullOr package; type = with types; nullOr package;
default = defaultSwayPackage; default = pkgs.sway;
apply = p: if p == null then null else genFinalPackage p;
defaultText = literalExpression "pkgs.sway"; defaultText = literalExpression "pkgs.sway";
description = lib.mdDoc '' description = lib.mdDoc ''
Sway package to use. Will override the options Sway package to use. If the package does not contain the override arguments
'wrapperFeatures', 'extraSessionCommands', and 'extraOptions'. `extraSessionCommands`, `extraOptions`, `withBaseWrapper`, `withGtkWrapper`,
Set to `null` to not add any Sway package to your `isNixOS`, then the module options {option}`wrapperFeatures`,
path. This should be done if you want to use the Home Manager Sway {option}`wrapperFeatures` and {option}`wrapperFeatures` will have no effect.
module to install Sway. 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.
''; '';
}; };