nixos/ayatana-indicators: Support new passthru.ayatana-indicators format

+28 -7
+28 -7
nixos/modules/services/desktops/ayatana-indicators.nix
··· 20 20 example = lib.literalExpression "with pkgs; [ ayatana-indicator-messages ]"; 21 21 description = '' 22 22 List of packages containing Ayatana Indicator services 23 - that should be brought up by the SystemD "ayatana-indicators" user target. 23 + that should be brought up by a SystemD "ayatana-indicators" user target. 24 24 25 25 Packages specified here must have passthru.ayatana-indicators set correctly. 26 26 27 27 If, how, and where these indicators are displayed will depend on your DE. 28 + Which target they will be brought up by depends on the packages' passthru.ayatana-indicators. 28 29 ''; 29 30 }; 30 31 }; ··· 39 40 # libayatana-common's ayatana-indicators.target with explicit Wants & Before to bring up requested indicator services 40 41 systemd.user.targets = 41 42 let 42 - indicatorServices = lib.lists.flatten ( 43 - map (pkg: (map (ind: "${ind}.service") pkg.passthru.ayatana-indicators)) cfg.packages 44 - ); 43 + namesToServices = map (indicator: "${indicator}.service"); 44 + indicatorServices = 45 + target: 46 + lib.lists.flatten ( 47 + map ( 48 + pkg: 49 + if lib.isList pkg.passthru.ayatana-indicators then 50 + # Old format, add to every target 51 + (lib.warn "${pkg.name} is using the old passthru.ayatana-indicators format, please update it!" ( 52 + namesToServices pkg.passthru.ayatana-indicators 53 + )) 54 + else 55 + # New format, filter by target being mentioned 56 + (namesToServices ( 57 + builtins.filter ( 58 + service: 59 + builtins.any ( 60 + targetPrefix: "${targetPrefix}-indicators" == target 61 + ) pkg.passthru.ayatana-indicators.${service} 62 + ) (builtins.attrNames pkg.passthru.ayatana-indicators) 63 + )) 64 + ) cfg.packages 65 + ); 45 66 in 46 67 lib.attrsets.mapAttrs 47 - (_: desc: { 68 + (name: desc: { 48 69 description = "Target representing the lifecycle of the ${desc}. Each indicator should be bound to it in its individual service file"; 49 70 partOf = [ "graphical-session.target" ]; 50 - wants = indicatorServices; 51 - before = indicatorServices; 71 + wants = indicatorServices name; 72 + before = indicatorServices name; 52 73 }) 53 74 { 54 75 ayatana-indicators = "Ayatana Indicators";