From 6fb793d24ad2d1eb0695fc3ab807e611d03020a3 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sun, 7 Aug 2022 13:31:06 +0800 Subject: [PATCH] programs/pop-launcher: create module This is to easily install launcher plugins and scripts in NixOS. I don't know if this is also possible on home-manager (which I think it could be since it also has the capability to set files). --- .../home-manager/programs/pop-launcher.nix | 75 +++++++++++++++++++ modules/nixos/programs/pop-launcher.nix | 75 +++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 modules/home-manager/programs/pop-launcher.nix create mode 100644 modules/nixos/programs/pop-launcher.nix diff --git a/modules/home-manager/programs/pop-launcher.nix b/modules/home-manager/programs/pop-launcher.nix new file mode 100644 index 00000000..f479a238 --- /dev/null +++ b/modules/home-manager/programs/pop-launcher.nix @@ -0,0 +1,75 @@ +{ config, options, lib, pkgs, ... }: + +let + cfg = config.programs.pop-launcher; + + # This assumes the package contains the built-in plugins being symlinked to + # the main binary with absolute paths. Most sensibly, the nixpkgs builder + # will rewrite symlinks relative to its output directory. Since we're putting + # them outside of its output directory, we'll have to stop it from doing + # that. + package = cfg.package.overrideAttrs (prev: { + dontRewriteSymlinks = true; + }); + + # Plugins and scripts are assumed to be packaged at + # `$out/share/pop-launcher`. + pluginsDir = pkgs.symlinkJoin { + name = "pop-launcher-plugins-system"; + paths = builtins.map (p: "${p}/share/pop-launcher") (cfg.plugins ++ [ package ]); + }; +in +{ + options.programs.pop-launcher = { + enable = lib.mkOption { + description = '' + Whether to enable Pop launcher, a launcher service for application + launchers. + + Take note you have to install an application launcher frontend to make + use of this such as onagre or + cosmic-launcher. + ''; + type = lib.types.bool; + default = false; + example = true; + }; + + package = lib.mkOption { + type = lib.types.package; + description = '' + The package where pop-launcher binary and + built-in plugins are expected. + ''; + default = pkgs.pop-launcher; + }; + + plugins = lib.mkOption { + type = lib.types.listOf lib.types.package; + description = '' + List of packages containing Pop launcher plugins and scripts to be + installed as system-wide plugins. + ''; + default = []; + defaultText = "[]"; + example = lib.literalExpression '' + with pkgs; [ + pop-launcher-plugin-duckduckgo-bangs + pop-launcher-plugin-jetbrains + ]; + ''; + }; + }; + + config = lib.mkIf cfg.enable { + # The local plugin path is hardcoded so we'll also do that instead of + # properly setting in `xdg.dataFile`. + home.file.".local/share/pop-launcher" = lib.mkIf (cfg.plugins != []) { + source = pluginsDir; + }; + + home.packages = with pkgs; [ + pop-launcher + ]; + }; +} diff --git a/modules/nixos/programs/pop-launcher.nix b/modules/nixos/programs/pop-launcher.nix new file mode 100644 index 00000000..62fd038a --- /dev/null +++ b/modules/nixos/programs/pop-launcher.nix @@ -0,0 +1,75 @@ +{ config, options, lib, pkgs, ... }: + +let + cfg = config.programs.pop-launcher; + + # This assumes the package contains the built-in plugins being symlinked to + # the main binary with absolute paths. Most sensibly, the nixpkgs builder + # will rewrite symlinks relative to its output directory. Since we're putting + # them outside of its output directory, we'll have to stop it from doing + # that. + package = cfg.package.overrideAttrs (prev: { + dontRewriteSymlinks = true; + }); + + # Plugins and scripts are assumed to be packaged at + # `$out/share/pop-launcher`. + pluginsDir = pkgs.symlinkJoin { + name = "pop-launcher-plugins-system"; + paths = builtins.map (p: "${p}/share/pop-launcher") (cfg.plugins ++ [ package ]); + }; +in +{ + options.programs.pop-launcher = { + enable = lib.mkOption { + description = '' + Whether to enable Pop launcher, a launcher service for application + launchers. + + Take note you have to install an application launcher frontend to make + use of this such as onagre or + cosmic-launcher. + ''; + type = lib.types.bool; + default = false; + example = true; + }; + + package = lib.mkOption { + type = lib.types.package; + description = '' + The package where pop-launcher binary and + built-in plugins are expected. + ''; + default = pkgs.pop-launcher; + }; + + plugins = lib.mkOption { + # Wait, why isn't this working? WHY IS THIS NOT WORKING?! + #type = with lib.types; listOf package; + type = lib.types.listOf lib.types.package; + description = '' + List of packages containing Pop launcher plugins and scripts to be + installed as system-wide plugins. + ''; + default = []; + defaultText = "[]"; + example = lib.literalExpression '' + with pkgs; [ + pop-launcher-plugin-duckduckgo-bangs + pop-launcher-plugin-jetbrains + ]; + ''; + }; + }; + + config = lib.mkIf cfg.enable { + environment.etc.pop-launcher = lib.mkIf (cfg.plugins != []) { + source = pluginsDir; + }; + + environment.systemPackages = with pkgs; [ + pop-launcher + ]; + }; +}