nix: HM module overlay now an option

This commit is contained in:
benvonh
2024-12-29 00:14:06 +10:00
parent 1b4b6c90eb
commit e52460c71d

View File

@@ -7,7 +7,18 @@ let
jsonFormat = pkgs.formats.json { }; jsonFormat = pkgs.formats.json { };
# No package option # No package option
package = pkgs.hyprpanel; package = if pkgs ? hyprpanel then pkgs.hyprpanel
else abort ''
******************************************
* HyprPanel *
******************************************
* You didn't add the overlay! *
* *
* Either set 'overlay.enable = true' or *
* manually add it to 'nixpkgs.overlays'. *
******************************************
'';
# Shorthand lambda for self-documenting options under settings # Shorthand lambda for self-documenting options under settings
mkStrOption = default: mkOption { type = types.str; default = default; }; mkStrOption = default: mkOption { type = types.str; default = default; };
@@ -64,6 +75,7 @@ in
{ {
options.programs.hyprpanel = { options.programs.hyprpanel = {
enable = mkEnableOption "HyprPanel"; enable = mkEnableOption "HyprPanel";
overlay.enable = mkEnableOption "script overlay";
systemd.enable = mkEnableOption "systemd integration"; systemd.enable = mkEnableOption "systemd integration";
hyprland.enable = mkEnableOption "Hyprland integration"; hyprland.enable = mkEnableOption "Hyprland integration";
overwrite.enable = mkEnableOption "overwrite config fix"; overwrite.enable = mkEnableOption "overwrite config fix";
@@ -549,7 +561,8 @@ in
config = let config = let
theme = if cfg.theme != "" theme =
if cfg.theme != ""
then builtins.fromJSON (builtins.readFile ../themes/${cfg.theme}.json) then builtins.fromJSON (builtins.readFile ../themes/${cfg.theme}.json)
else {}; else {};
@@ -567,6 +580,7 @@ in
text = '' text = ''
cd cd
echo '------------- HyprPanel -------------' echo '------------- HyprPanel -------------'
echo
echo 'Please ignore the layout diff for now' echo 'Please ignore the layout diff for now'
echo '-------------------------------------' echo '-------------------------------------'
colordiff ${config.xdg.configFile.hyprpanel.target} \ colordiff ${config.xdg.configFile.hyprpanel.target} \
@@ -576,7 +590,7 @@ in
in mkIf cfg.enable { in mkIf cfg.enable {
nixpkgs.overlays = [ self.overlay ]; nixpkgs.overlays = if cfg.overlay.enable then [ self.overlay ] else null;
home.packages = [ home.packages = [
package package
@@ -587,14 +601,11 @@ in
else pkgs.nerdfonts.override { fonts = [ "JetBrainsMono" ]; }) else pkgs.nerdfonts.override { fonts = [ "JetBrainsMono" ]; })
]; ];
# NOTE:(benvonh)
# When changing the configuration through the GUI, HyprPanel will delete the `config.json` file and create a new
# one in its place which destroys the original symlink to the current Home Manager generation. To work around this,
# we can automatically delete the `config.json` file before generating a new config by enabling the
# `overwrite.enable` option. Though, at some point, a proper fix should be implemented.
home.activation = home.activation =
let path = "${config.xdg.configFile.hyprpanel.target}"; let
in mkIf cfg.overwrite.enable { path = "${config.xdg.configFile.hyprpanel.target}";
in
mkIf cfg.overwrite.enable {
hyprpanel = lib.hm.dag.entryBefore [ "writeBoundary" ] '' hyprpanel = lib.hm.dag.entryBefore [ "writeBoundary" ] ''
[[ -L "${path}" ]] || rm -f "${path}" [[ -L "${path}" ]] || rm -f "${path}"
''; '';