util: mkMergedYAML

This commit is contained in:
js0ny 2025-12-15 01:19:02 +00:00
parent ba412e143b
commit 0cdf9f51bf
5 changed files with 236 additions and 46 deletions

View file

@ -0,0 +1,44 @@
{
config,
lib,
pkgs,
...
}: let
mkMergedYaml = {
name, # This value should be unique for each merged YAML config
target, # The target YAML file path relative to $HOME
settings, # The Nix Settings to convert to YAML and merge
}: let
yamlContent = lib.generators.toYAML {} settings;
# This file will hold the Nix-managed YAML content
# symlink to /nix/store/***.nix-managed for clarity
patchFile = "${target}.nix-managed";
in {
# Write the Nix-managed YAML content for merging and preservation
home.file."${patchFile}".text = yamlContent;
home.activation."merge-${name}" = lib.hm.dag.entryAfter ["writeBoundary"] ''
TARGET="$HOME/${target}"
PATCH="$HOME/${patchFile}"
if [ -f "$PATCH" ]; then
verboseEcho "Merging Nix managed YAML config into: $TARGET"
run mkdir -p "$(dirname "$TARGET")"
if [ ! -f "$TARGET" ]; then
echo "{}" > "$TARGET"
fi
# Arguments:
# * -i: In-place edit
# * -oy: Output YAML
# * -P: Pretty Print (indentation, etc.)
run ${pkgs.yq-go}/bin/yq -i -oy -P ". *= load(\"$PATCH\")" "$TARGET"
fi
'';
};
in {
inherit mkMergedYaml;
}

View file

@ -0,0 +1,69 @@
{
pkgs,
lib,
config,
...
}: let
catppuccinCider = pkgs.fetchFromGitHub {
owner = "catppuccin";
repo = "cider";
rev = "d336144a63f7dc1510b072cfb94eda1730db45cb";
sha256 = "sha256-wzlRiGDDmVAqAazhhXAl4LepNY/UyyWdLLQVvkHTTSE=";
};
ctp-mocha = pkgs.runCommand "cider-theme-ctp-mocha" {} ''
cp -r ${catppuccinCider}/themes/ctp-mocha $out
chmod -R u+w $out
echo "marketplaceID: 12" >> "$out/theme.yml"
echo 'version: "25.02"' >> "$out/theme.yml"
'';
mergetools = import ../lib/mergetools.nix {inherit pkgs lib config;};
mkMergedYaml = mergetools.mkMergedYaml;
ciderSpaConfig = mkMergedYaml {
name = "cider-spa-config";
target = ".config/sh.cider.genten/spa-config.yml";
settings = {
general = {
language = "zh-CN";
keybindings = {
commandCenter = ["ctrlKey" "KeyO"];
};
closeToTray = true;
checkForUpdates = false;
};
updates = {
# Managed by Nix, disable built-in update checks
checkForUpdates = false;
};
};
};
in {
imports = [
../../../modules/home/programs/cider-2.nix
ciderSpaConfig
];
programs.cider-2 = {
enable = true;
# --- Themes ---
themes = {
# This maps to ~/.config/sh.cider.genten/themes/12
"12" = {
src = ctp-mocha;
};
};
# --- Plugins ---
plugins = {
# This maps to ~/.config/sh.cider.genten/plugins/ch.kaifa.listenbrainz
"ch.kaifa.listenbrainz" = {
marketplace = {
id = 10;
version = "1.1.0";
sha256 = "sha256-YelqonGEQVZk4+IQ8YwgfqP93a+enN6XxVktlyBCEZI=";
};
};
};
};
}

View file

@ -1,45 +0,0 @@
{pkgs, ...}: let
catppuccinCider = pkgs.fetchFromGitHub {
owner = "catppuccin";
repo = "cider";
rev = "d336144a63f7dc1510b072cfb94eda1730db45cb";
sha256 = "sha256-wzlRiGDDmVAqAazhhXAl4LepNY/UyyWdLLQVvkHTTSE=";
};
ctp-mocha = pkgs.runCommand "cider-theme-ctp-mocha" {} ''
cp -r ${catppuccinCider}/themes/ctp-mocha $out
chmod -R u+w $out
echo "marketplaceID: 12" >> "$out/theme.yml"
echo 'version: "25.02"' >> "$out/theme.yml"
'';
ciderConfigDir = "sh.cider.genten";
themeDir = "${ciderConfigDir}/themes";
pluginDir = "${ciderConfigDir}/plugins";
ciderThemes = [
{
package = ctp-mocha;
id = 12;
version = "25.02";
}
];
plugin-listenBrainz =
pkgs.runCommand "cider-plugin-listenbrainz" {
# name = "ListenBrainz-1.1.0.zip";
nativeBuildInputs = [pkgs.unzip];
src = pkgs.fetchurl {
url = "https://api.connect.cider.sh/marketplace/projects/10/versions/1.1.0/download";
sha256 = "sha256-YelqonGEQVZk4+IQ8YwgfqP93a+enN6XxVktlyBCEZI=";
};
recursive = true;
}
''
mkdir -p $out
unzip $src -d $out
chmod -R u+w $out
'';
in {
home.packages = [pkgs.cider-2];
xdg.configFile."${themeDir}/12".source = ctp-mocha;
xdg.configFile."${pluginDir}/ch.kaifa.listenbrainz".source = plugin-listenBrainz;
}

View file

@ -75,7 +75,7 @@ in {
./programs/sioyek.nix
./programs/celluloid.nix
./programs/picard.nix
./programs/cider2.nix
./programs/cider-2.nix
# Desktop Linux
./programs/desktop/gnome