From 1b4b6c90ebec9dec38089f10e6a103fc12d9ef37 Mon Sep 17 00:00:00 2001 From: benvonh Date: Sat, 28 Dec 2024 16:32:59 +1000 Subject: [PATCH 1/2] nix: Add overlay to HM module + useful script --- nix/module.nix | 57 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index dbe5c04..fbbd3e5 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -7,7 +7,7 @@ let jsonFormat = pkgs.formats.json { }; # No package option - package = self.packages.${pkgs.system}.default; + package = pkgs.hyprpanel; # Shorthand lambda for self-documenting options under settings mkStrOption = default: mkOption { type = types.str; default = default; }; @@ -43,14 +43,14 @@ let let items = builtins.map toNestedValue value; in - "[" + (builtins.concatStringsSep ", " items) + "]" + "[\n" + (builtins.concatStringsSep ", " items) + "\n]" else if builtins.isAttrs value then let keys = builtins.attrNames value; toKeyValue = k: "\"${k}\": ${toNestedValue value.${k}}"; inner = builtins.concatStringsSep ", " (builtins.map toKeyValue keys); in - "{ " + inner + " }" + "{\n" + inner + "\n}" else abort "Unexpected error! Please post a new issue and @benvonh..."; @@ -59,7 +59,7 @@ let keys = builtins.attrNames attrSet; kvPairs = builtins.map (k: "\"${k}\": ${toNestedValue attrSet.${k}}") keys; in - "{ " + builtins.concatStringsSep ", " kvPairs + " }"; + "{\n " + builtins.concatStringsSep ",\n " kvPairs + "\n}"; in { options.programs.hyprpanel = { @@ -547,9 +547,40 @@ in }; }; - config = mkIf cfg.enable { + config = let + + theme = if cfg.theme != "" + then builtins.fromJSON (builtins.readFile ../themes/${cfg.theme}.json) + else {}; + + flatSet = flattenAttrs (lib.attrsets.recursiveUpdate cfg.settings theme) ""; + + mergeSet = flatSet // (flattenAttrs cfg.override ""); + + fullSet = if cfg.layout == null then mergeSet else mergeSet // cfg.layout; + + finalConfig = toNestedObject fullSet; + + hyprpanel-diff = pkgs.writeShellApplication { + runtimeInputs = [ pkgs.colordiff ]; + name = "hyprpanel-diff"; + text = '' + cd + echo '------------- HyprPanel -------------' + echo 'Please ignore the layout diff for now' + echo '-------------------------------------' + colordiff ${config.xdg.configFile.hyprpanel.target} \ + ${config.xdg.configFile.hyprpanel-swap.target} + ''; + }; + + in mkIf cfg.enable { + + nixpkgs.overlays = [ self.overlay ]; + home.packages = [ package + hyprpanel-diff (if pkgs ? nerd-fonts.jetbrains-mono then pkgs.nerd-fonts.jetbrains-mono # NOTE:(benvonh) Remove after next release 25.05 @@ -569,19 +600,17 @@ in ''; }; - xdg.configFile.hyprpanel = let - theme = if cfg.theme != "" - then builtins.fromJSON (builtins.readFile ../themes/${cfg.theme}.json) - else {}; - flatSet = flattenAttrs (lib.attrsets.recursiveUpdate cfg.settings theme) ""; - mergeSet = flatSet // (flattenAttrs cfg.override ""); - fullSet = if cfg.layout == null then mergeSet else mergeSet // cfg.layout; - in { + xdg.configFile.hyprpanel = { target = "hyprpanel/config.json"; - text = toNestedObject fullSet; + text = finalConfig; onChange = "${pkgs.procps}/bin/pkill -u $USER -USR1 hyprpanel || true"; }; + xdg.configFile.hyprpanel-swap = { + target = "hyprpanel/config.hm.json"; + text = finalConfig; + }; + systemd.user.services = mkIf cfg.systemd.enable { hyprpanel = { Unit = { From e52460c71d24362abf5627a759699cb2d9fe526f Mon Sep 17 00:00:00 2001 From: benvonh Date: Sun, 29 Dec 2024 00:14:06 +1000 Subject: [PATCH 2/2] nix: HM module overlay now an option --- nix/module.nix | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index fbbd3e5..c0f5912 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -7,7 +7,18 @@ let jsonFormat = pkgs.formats.json { }; # 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 mkStrOption = default: mkOption { type = types.str; default = default; }; @@ -64,6 +75,7 @@ in { options.programs.hyprpanel = { enable = mkEnableOption "HyprPanel"; + overlay.enable = mkEnableOption "script overlay"; systemd.enable = mkEnableOption "systemd integration"; hyprland.enable = mkEnableOption "Hyprland integration"; overwrite.enable = mkEnableOption "overwrite config fix"; @@ -549,7 +561,8 @@ in config = let - theme = if cfg.theme != "" + theme = + if cfg.theme != "" then builtins.fromJSON (builtins.readFile ../themes/${cfg.theme}.json) else {}; @@ -567,6 +580,7 @@ in text = '' cd echo '------------- HyprPanel -------------' + echo echo 'Please ignore the layout diff for now' echo '-------------------------------------' colordiff ${config.xdg.configFile.hyprpanel.target} \ @@ -576,7 +590,7 @@ in in mkIf cfg.enable { - nixpkgs.overlays = [ self.overlay ]; + nixpkgs.overlays = if cfg.overlay.enable then [ self.overlay ] else null; home.packages = [ package @@ -587,18 +601,15 @@ in 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 = - let path = "${config.xdg.configFile.hyprpanel.target}"; - in mkIf cfg.overwrite.enable { - hyprpanel = lib.hm.dag.entryBefore [ "writeBoundary" ] '' - [[ -L "${path}" ]] || rm -f "${path}" - ''; - }; + let + path = "${config.xdg.configFile.hyprpanel.target}"; + in + mkIf cfg.overwrite.enable { + hyprpanel = lib.hm.dag.entryBefore [ "writeBoundary" ] '' + [[ -L "${path}" ]] || rm -f "${path}" + ''; + }; xdg.configFile.hyprpanel = { target = "hyprpanel/config.json";