Skip to content

Commit

Permalink
nix: Add overlay to HM module + useful script
Browse files Browse the repository at this point in the history
  • Loading branch information
benvonh committed Dec 28, 2024
1 parent ba7e0df commit 1b4b6c9
Showing 1 changed file with 43 additions and 14 deletions.
57 changes: 43 additions & 14 deletions nix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand Down Expand Up @@ -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...";

Expand All @@ -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 = {
Expand Down Expand Up @@ -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
Expand All @@ -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 = {
Expand Down

0 comments on commit 1b4b6c9

Please sign in to comment.