From 2c452cb395ea00967255727234bac16f898c8840 Mon Sep 17 00:00:00 2001 From: Daniel Dada Date: Sat, 13 Dec 2025 02:25:14 +0300 Subject: [PATCH] added home manager module --- flake.nix | 3 + home-manager-module.nix | 143 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 home-manager-module.nix diff --git a/flake.nix b/flake.nix index e073d5d..47e284a 100644 --- a/flake.nix +++ b/flake.nix @@ -70,6 +70,9 @@ default = clrsync; }; + homeManagerModules.default = import ./home-manager-module.nix; + homeManagerModules.clrsync = self.homeManagerModules.default; + apps.${system} = { clrsync-gui = { type = "app"; diff --git a/home-manager-module.nix b/home-manager-module.nix new file mode 100644 index 0000000..985552b --- /dev/null +++ b/home-manager-module.nix @@ -0,0 +1,143 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +let + cfg = config.programs.clrsync; + templateType = types.submodule { + options = { + enabled = mkOption { + type = types.bool; + default = true; + description = "Whether to enable this template."; + }; + inputPath = mkOption { + type = types.str; + description = "Path to the template input file."; + }; + outputPath = mkOption { + type = types.str; + description = "Path where the generated output will be written."; + }; + reloadCmd = mkOption { + type = types.str; + default = ""; + description = "Command to run after generating the output."; + }; + }; + }; + configFormat = pkgs.formats.toml { }; + configFile = configFormat.generate "config.toml" { + general = { + default_theme = cfg.defaultTheme; + palettes_path = cfg.palettesPath; + 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; + }; +in +{ + options.programs.clrsync = { + enable = mkEnableOption "clrsync color synchronization"; + package = mkOption { + type = types.package; + 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 = { }; + description = "Template configurations."; + example = literalExpression '' + { + kitty = { + enabled = true; + inputPath = "~/.config/clrsync/templates/kitty.conf"; + outputPath = "~/.config/kitty/kitty_test.conf"; + reloadCmd = "pkill -SIGUSR1 kitty"; + }; + } + ''; + }; + 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 must be set. Add clrsync as a flake input and 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; + }; + 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 ]; + }; + }; + }) + ]); +}