Merge pull request #654 from benvonh/master
nix: Add overlay option to HM module
This commit is contained in:
@@ -7,7 +7,18 @@ let
|
|||||||
jsonFormat = pkgs.formats.json { };
|
jsonFormat = pkgs.formats.json { };
|
||||||
|
|
||||||
# No package option
|
# No package option
|
||||||
package = self.packages.${pkgs.system}.default;
|
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; };
|
||||||
@@ -43,14 +54,14 @@ let
|
|||||||
let
|
let
|
||||||
items = builtins.map toNestedValue value;
|
items = builtins.map toNestedValue value;
|
||||||
in
|
in
|
||||||
"[" + (builtins.concatStringsSep ", " items) + "]"
|
"[\n" + (builtins.concatStringsSep ", " items) + "\n]"
|
||||||
else if builtins.isAttrs value then
|
else if builtins.isAttrs value then
|
||||||
let
|
let
|
||||||
keys = builtins.attrNames value;
|
keys = builtins.attrNames value;
|
||||||
toKeyValue = k: "\"${k}\": ${toNestedValue value.${k}}";
|
toKeyValue = k: "\"${k}\": ${toNestedValue value.${k}}";
|
||||||
inner = builtins.concatStringsSep ", " (builtins.map toKeyValue keys);
|
inner = builtins.concatStringsSep ", " (builtins.map toKeyValue keys);
|
||||||
in
|
in
|
||||||
"{ " + inner + " }"
|
"{\n" + inner + "\n}"
|
||||||
else
|
else
|
||||||
abort "Unexpected error! Please post a new issue and @benvonh...";
|
abort "Unexpected error! Please post a new issue and @benvonh...";
|
||||||
|
|
||||||
@@ -59,11 +70,12 @@ let
|
|||||||
keys = builtins.attrNames attrSet;
|
keys = builtins.attrNames attrSet;
|
||||||
kvPairs = builtins.map (k: "\"${k}\": ${toNestedValue attrSet.${k}}") keys;
|
kvPairs = builtins.map (k: "\"${k}\": ${toNestedValue attrSet.${k}}") keys;
|
||||||
in
|
in
|
||||||
"{ " + builtins.concatStringsSep ", " kvPairs + " }";
|
"{\n " + builtins.concatStringsSep ",\n " kvPairs + "\n}";
|
||||||
in
|
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";
|
||||||
@@ -547,41 +559,69 @@ 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
|
||||||
|
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 = if cfg.overlay.enable then [ self.overlay ] else null;
|
||||||
|
|
||||||
home.packages = [
|
home.packages = [
|
||||||
package
|
package
|
||||||
|
hyprpanel-diff
|
||||||
(if pkgs ? nerd-fonts.jetbrains-mono
|
(if pkgs ? nerd-fonts.jetbrains-mono
|
||||||
then pkgs.nerd-fonts.jetbrains-mono
|
then pkgs.nerd-fonts.jetbrains-mono
|
||||||
# NOTE:(benvonh) Remove after next release 25.05
|
# NOTE:(benvonh) Remove after next release 25.05
|
||||||
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}";
|
||||||
hyprpanel = lib.hm.dag.entryBefore [ "writeBoundary" ] ''
|
in
|
||||||
[[ -L "${path}" ]] || rm -f "${path}"
|
mkIf cfg.overwrite.enable {
|
||||||
'';
|
hyprpanel = lib.hm.dag.entryBefore [ "writeBoundary" ] ''
|
||||||
};
|
[[ -L "${path}" ]] || rm -f "${path}"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
xdg.configFile.hyprpanel = let
|
xdg.configFile.hyprpanel = {
|
||||||
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 {
|
|
||||||
target = "hyprpanel/config.json";
|
target = "hyprpanel/config.json";
|
||||||
text = toNestedObject fullSet;
|
text = finalConfig;
|
||||||
onChange = "${pkgs.procps}/bin/pkill -u $USER -USR1 hyprpanel || true";
|
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 {
|
systemd.user.services = mkIf cfg.systemd.enable {
|
||||||
hyprpanel = {
|
hyprpanel = {
|
||||||
Unit = {
|
Unit = {
|
||||||
|
|||||||
Reference in New Issue
Block a user