mirror of
https://github.com/obsqrbtz/clrsync.git
synced 2026-04-08 20:19:04 +03:00
cleaned up module and added package with overlay
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
flake:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
@@ -8,11 +9,8 @@ with lib;
|
||||
let
|
||||
cfg = config.programs.clrsync;
|
||||
|
||||
defaultPackage =
|
||||
if args ? inputs && args.inputs ? clrsync
|
||||
then args.inputs.clrsync.packages.${pkgs.system}.default or null
|
||||
else null;
|
||||
|
||||
clrsyncPackage = flake.packages.${pkgs.system}.default;
|
||||
|
||||
templateType = types.submodule {
|
||||
options = {
|
||||
enabled = mkOption {
|
||||
@@ -35,6 +33,7 @@ let
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
configFormat = pkgs.formats.toml { };
|
||||
configFile = configFormat.generate "config.toml" {
|
||||
general = {
|
||||
@@ -43,43 +42,44 @@ let
|
||||
font = cfg.font;
|
||||
font_size = cfg.fontSize;
|
||||
};
|
||||
templates = mapAttrs (name: template: {
|
||||
enabled = template.enabled;
|
||||
input_path = template.inputPath;
|
||||
output_path = template.outputPath;
|
||||
reload_cmd = template.reloadCmd;
|
||||
}) cfg.templates;
|
||||
templates = mapAttrs (
|
||||
name: template: {
|
||||
enabled = template.enabled;
|
||||
input_path = template.inputPath;
|
||||
output_path = template.outputPath;
|
||||
reload_cmd = template.reloadCmd;
|
||||
}
|
||||
) cfg.templates;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.programs.clrsync = {
|
||||
enable = mkEnableOption "clrsync color synchronization";
|
||||
package = mkOption {
|
||||
type = types.nullOr types.package;
|
||||
default = defaultPackage;
|
||||
defaultText = literalExpression "inputs.clrsync.packages.\${pkgs.system}.default";
|
||||
description = "The clrsync package to use.";
|
||||
};
|
||||
|
||||
defaultTheme = mkOption {
|
||||
type = types.str;
|
||||
default = "cursed";
|
||||
description = "Default theme to use.";
|
||||
};
|
||||
|
||||
palettesPath = mkOption {
|
||||
type = types.str;
|
||||
default = "~/.config/clrsync/palettes";
|
||||
description = "Path to color palettes directory.";
|
||||
};
|
||||
|
||||
font = mkOption {
|
||||
type = types.str;
|
||||
default = "JetBrainsMono Nerd Font Mono";
|
||||
description = "Font family to use.";
|
||||
};
|
||||
|
||||
fontSize = mkOption {
|
||||
type = types.int;
|
||||
default = 14;
|
||||
description = "Font size.";
|
||||
};
|
||||
|
||||
templates = mkOption {
|
||||
type = types.attrsOf templateType;
|
||||
default = { };
|
||||
@@ -95,64 +95,61 @@ in
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
applyTheme = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Whether to apply the default theme on activation.";
|
||||
};
|
||||
|
||||
systemdTarget = mkOption {
|
||||
type = types.str;
|
||||
default = "graphical-session.target";
|
||||
description = "Systemd target to bind the clrsync service to.";
|
||||
};
|
||||
};
|
||||
config = mkIf cfg.enable (mkMerge [
|
||||
{
|
||||
assertions = [
|
||||
{
|
||||
assertion = cfg.package != null;
|
||||
message = ''
|
||||
programs.clrsync.package could not be automatically determined.
|
||||
Please add clrsync to your flake inputs and pass it via extraSpecialArgs:
|
||||
|
||||
home-manager.extraSpecialArgs = { inherit inputs; };
|
||||
|
||||
Or manually set:
|
||||
programs.clrsync.package = inputs.clrsync.packages.''${pkgs.system}.default;
|
||||
'';
|
||||
}
|
||||
];
|
||||
}
|
||||
(mkIf (cfg.package != null) {
|
||||
home.packages = [ cfg.package ];
|
||||
xdg.configFile."clrsync/config.toml" = {
|
||||
source = configFile;
|
||||
force = true;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = [ clrsyncPackage ];
|
||||
|
||||
xdg.enable = true;
|
||||
|
||||
home.activation.clrsyncDesktop = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
if [ -d "$HOME/.nix-profile/share/applications" ]; then
|
||||
${pkgs.desktop-file-utils}/bin/update-desktop-database "$HOME/.nix-profile/share/applications" || true
|
||||
fi
|
||||
'';
|
||||
|
||||
xdg.configFile."clrsync/config.toml" = {
|
||||
source = configFile;
|
||||
force = true;
|
||||
};
|
||||
|
||||
home.activation.clrsyncConfig = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
run --quiet mkdir -p $HOME/.config/clrsync
|
||||
run --quiet cp -f ${configFile} $HOME/.config/clrsync/config.toml
|
||||
'';
|
||||
|
||||
home.activation.clrsyncApply = mkIf cfg.applyTheme (
|
||||
lib.hm.dag.entryAfter [ "clrsyncConfig" ] ''
|
||||
run --quiet ${clrsyncPackage}/bin/clrsync_cli --apply --theme ${cfg.defaultTheme}
|
||||
''
|
||||
);
|
||||
|
||||
systemd.user.services.clrsync = mkIf cfg.applyTheme {
|
||||
Unit = {
|
||||
Description = "Apply clrsync color palette";
|
||||
After = [ cfg.systemdTarget ];
|
||||
PartOf = [ cfg.systemdTarget ];
|
||||
};
|
||||
home.activation.clrsyncConfig = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
run --quiet mkdir -p $HOME/.config/clrsync
|
||||
run --quiet cp -f ${configFile} $HOME/.config/clrsync/config.toml
|
||||
'';
|
||||
home.activation.clrsyncApply = mkIf cfg.applyTheme (
|
||||
lib.hm.dag.entryAfter [ "clrsyncConfig" ] ''
|
||||
run --quiet ${cfg.package}/bin/clrsync_cli --apply --theme ${cfg.defaultTheme}
|
||||
''
|
||||
);
|
||||
systemd.user.services.clrsync = mkIf cfg.applyTheme {
|
||||
Unit = {
|
||||
Description = "Apply clrsync color palette";
|
||||
After = [ cfg.systemdTarget ];
|
||||
PartOf = [ cfg.systemdTarget ];
|
||||
};
|
||||
Service = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${cfg.package}/bin/clrsync_cli --apply --theme ${cfg.defaultTheme}";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
Install = {
|
||||
WantedBy = [ cfg.systemdTarget ];
|
||||
};
|
||||
Service = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${clrsyncPackage}/bin/clrsync_cli --apply --theme ${cfg.defaultTheme}";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
})
|
||||
]);
|
||||
}
|
||||
Install = {
|
||||
WantedBy = [ cfg.systemdTarget ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user