diff --git a/flake.lock b/flake.lock index 5819162..2d7b0ca 100644 --- a/flake.lock +++ b/flake.lock @@ -939,11 +939,11 @@ }, "nixpkgs_6": { "locked": { - "lastModified": 1742422364, - "narHash": "sha256-mNqIplmEohk5jRkqYqG19GA8MbQ/D4gQSK0Mu4LvfRQ=", + "lastModified": 1742889210, + "narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a84ebe20c6bc2ecbcfb000a50776219f48d134cc", + "rev": "698214a32beb4f4c8e3942372c694f40848b360d", "type": "github" }, "original": { diff --git a/home/lib/colorScheme/buildColorScheme.nix b/home/lib/colorScheme/buildColorScheme.nix index e4d0e8d..4da44ef 100644 --- a/home/lib/colorScheme/buildColorScheme.nix +++ b/home/lib/colorScheme/buildColorScheme.nix @@ -12,29 +12,32 @@ let name = colorScheme; isDefault = false; polarity = "dark"; - matugen = null; + fromImage.enable = false; } else colorScheme; wallpapers = config.wallpapers; + getImage = + image: + if builtins.typeOf image == "path" then + image + else + pkgs.fetchurl { + inherit (builtins.filter (wallpaper: wallpaper.name == image) wallpapers |> builtins.head) + name + url + sha256 + ; + }; + matugenToBase16 = colorScheme: let - inherit (colorScheme) name matugen polarity; - inherit (matugen) scheme; - image = - if builtins.typeOf matugen.image == "path" then - matugen.image - else - pkgs.fetchurl { - inherit (builtins.filter (wallpaper: wallpaper.name == matugen.image) wallpapers |> builtins.head) - name - url - sha256 - ; - }; + inherit (colorScheme) name polarity fromImage; + image = getImage fromImage.image; + scheme = if builtins.hasAttr "scheme" fromImage.passthru then fromImage.passthru.scheme else null; in pkgs.runCommand "${name}.yaml" { buildInputs = [ pkgs.matugen ]; } # bash @@ -43,6 +46,19 @@ let --name ${name} --polarity ${polarity} --type ${scheme} --output $out ''; + hellwalToBase16 = + colorScheme: + let + inherit (colorScheme) name polarity fromImage; + image = getImage fromImage.image; + in + pkgs.runCommand "${name}.yaml" { buildInputs = [ pkgs.hellwal ]; } + # bash + '' + ${pkgs.python3}/bin/python ${./hellwal2base16.py} ${image} \ + --name ${name} --polarity ${polarity} --output $out + ''; + buildColorScheme = colorScheme: let @@ -50,16 +66,29 @@ let name isDefault polarity - matugen + fromImage ; forceOrDefault = if isDefault then lib.mkDefault else lib.mkForce; in - { - base16Scheme = - if matugen != null then - "${matugenToBase16 colorScheme}" + ( + if fromImage.enable then + let + inherit (fromImage) method; + in + if method == "matugen" then + { + base16Scheme = forceOrDefault "${matugenToBase16 colorScheme}"; + } else - forceOrDefault "${pkgs.base16-schemes}/share/themes/${name}.yaml"; + { + base16Scheme = forceOrDefault "${hellwalToBase16 colorScheme}"; + } + else + { + base16Scheme = forceOrDefault "${pkgs.base16-schemes}/share/themes/${name}.yaml"; + } + ) + // { inherit polarity; }; diff --git a/home/lib/colorScheme/hellwal2base16.py b/home/lib/colorScheme/hellwal2base16.py new file mode 100644 index 0000000..10f556a --- /dev/null +++ b/home/lib/colorScheme/hellwal2base16.py @@ -0,0 +1,56 @@ +import json +import argparse +import subprocess + +parser = argparse.ArgumentParser( + description="Create base16 yaml file from matugen output" +) +parser.add_argument("image", help="The image to generate the colors from") +parser.add_argument("--name", "-n", help="The name of the colorscheme") +parser.add_argument("--polarity", "-p", help="Dark or light", default="dark") +parser.add_argument("--output", "-o", help="The output file", default="base16.yaml") +args = parser.parse_args() +image = args.image +name = args.name +polarity = args.polarity +output = args.output + +hellwal_output = subprocess.run( + ["hellwal", "-i", image, "--dark" if polarity == "dark" else "--light", "--json"], + capture_output=True, + text=True, +).stdout + +colors = json.loads(hellwal_output)["colors"] + +base16_colors = { + name: f'"{colors[colorname].strip("'")}"' + for name, colorname in [ + ("base00", "color0"), + ("base01", "color1"), + ("base02", "color2"), + ("base03", "color3"), + ("base04", "color4"), + ("base05", "color5"), + ("base06", "color6"), + ("base07", "color7"), + ("base08", "color8"), + ("base09", "color9"), + ("base0A", "color10"), + ("base0B", "color11"), + ("base0C", "color12"), + ("base0D", "color13"), + ("base0E", "color14"), + ("base0F", "color15"), + ] +} + +yaml_content = f"""system: "base16" +name: "{name}" +author: "matugen" +variant: "{polarity}" +palette: +""" + "\n".join([f" {k}: {v}" for k, v in base16_colors.items()]) + +with open(output, "w") as f: + f.write(yaml_content) diff --git a/home/programs/terminal/kitty.nix b/home/programs/terminal/kitty.nix index 5efd2e5..b3a852b 100644 --- a/home/programs/terminal/kitty.nix +++ b/home/programs/terminal/kitty.nix @@ -12,8 +12,6 @@ window_padding_width = "10 20 10 20"; cursor_trail = 1; cursor_trail_start_threshold = 0; - font_family = lib.mkForce "Monofur Nerd Font"; - font_size = lib.mkForce 15; }; extraConfig = '' map ctrl+shift+p kitten hints --type path --program @ diff --git a/home/programs/utils/default.nix b/home/programs/utils/default.nix index 6acb17c..aeac1bc 100644 --- a/home/programs/utils/default.nix +++ b/home/programs/utils/default.nix @@ -36,12 +36,13 @@ direnv entr lutgen + matugen + hellwal imagemagick ffmpeg nurl nix-init wl-color-picker - matugen (config.lib.misc.addFlags "--wayland-text-input-version=3" "cherry-studio" cherry-studio) ]; imports = [ diff --git a/home/tweaks/colorscheme.nix b/home/tweaks/colorscheme.nix index b22fd5a..047677e 100644 --- a/home/tweaks/colorscheme.nix +++ b/home/tweaks/colorscheme.nix @@ -5,13 +5,22 @@ isDefault = true; } "everforest" - "nord" + { + name = "frieren-butterflies-dark"; + fromImage = { + enable = true; + image = "frieren-butterflies.jpg"; + method = "hellwal"; + }; + } "petrichor-downpour" { - name = "green-blue-flowers-dark"; - matugen = { - image = "green-blue-flowers.jpg"; - scheme = "scheme-expressive"; + name = "zzzzoka-gbc-dark"; + fromImage = { + enable = true; + image = "zzzzoka-gbc.jpg"; + method = "matugen"; + passthru.scheme = "scheme-expressive"; }; } ]; diff --git a/home/tweaks/stylix.nix b/home/tweaks/stylix.nix index e370f11..a80a9a2 100644 --- a/home/tweaks/stylix.nix +++ b/home/tweaks/stylix.nix @@ -17,8 +17,8 @@ in size = 32; }; fonts = { - monospace.name = "Comic Mono"; - monospace.package = pkgs.comic-mono; + monospace.name = "Maple Mono NF CN"; + monospace.package = pkgs.maple-mono.NF-CN; sansSerif.name = "LXGW WenKai"; sansSerif.package = pkgs.lxgw-wenkai; serif.name = "LXGW WenKai"; diff --git a/modules/home-manager/colorscheme.nix b/modules/home-manager/colorscheme.nix index 639d36b..4ad3394 100644 --- a/modules/home-manager/colorscheme.nix +++ b/modules/home-manager/colorscheme.nix @@ -16,6 +16,29 @@ let }; }; + fromImageOptions = submodule { + options = { + enable = mkEnableOption "Enable generating colorscheme from image"; + image = mkOption { + type = either str path; + description = "Path to the image"; + }; + method = mkOption { + type = enum [ + "matugen" + "hellwal" + "stylix" + ]; + description = "The method to use to generate the colorscheme"; + default = "matugen"; + }; + passthru = mkOption { + type = attrs; + description = "Passthru options to the method"; + }; + }; + }; + colorScheme = submodule { options = { name = mkOption { @@ -35,10 +58,12 @@ let description = "Polarity of the color scheme (dark or light)"; default = "dark"; }; - matugen = mkOption { - type = nullOr matugenOptions; - description = "Matugen options"; - default = null; + fromImage = mkOption { + type = fromImageOptions; + description = "Options for generating colorscheme from image"; + default = { + enable = false; + }; }; }; }; diff --git a/os/system/fonts.nix b/os/system/fonts.nix index bea6a5c..9d52fe1 100644 --- a/os/system/fonts.nix +++ b/os/system/fonts.nix @@ -10,6 +10,8 @@ nerd-fonts.hurmit nerd-fonts.monofur lxgw-wenkai + maple-mono.NF-CN + maple-mono.variable ]; fonts.fontDir.enable = true; } diff --git a/os/system/stylix.nix b/os/system/stylix.nix index 3412585..e14bda3 100644 --- a/os/system/stylix.nix +++ b/os/system/stylix.nix @@ -9,20 +9,41 @@ let cfg = self.homeConfigurations."${user}@${host}".config; in { - stylix = { - enable = true; - base16Scheme = lib.mkDefault cfg.stylix.base16Scheme; - autoEnable = false; - targets = { - console.enable = true; - gnome.enable = true; - grub.enable = true; - plymouth.enable = true; - }; - }; + stylix = + { + enable = true; + autoEnable = false; + targets = { + console.enable = true; + gnome.enable = true; + grub.enable = true; + plymouth.enable = true; + }; + } + // ( + if builtins.hasAttr "base16Scheme" cfg.stylix then + { base16Scheme = lib.mkDefault cfg.stylix.base16Scheme; } + else + { } + ) + // ( + if builtins.hasAttr "image" cfg.stylix then { image = lib.mkDefault cfg.stylix.image; } else { } + ); specialisation = builtins.mapAttrs (name: value: { configuration = { - stylix.base16Scheme = lib.mkForce cfg.specialisation.${name}.configuration.stylix.base16Scheme; + stylix = + ( + if builtins.hasAttr "base16Scheme" value.configuration.stylix then + { base16Scheme = lib.mkForce cfg.specialisation.${name}.configuration.stylix.base16Scheme; } + else + { } + ) + // ( + if builtins.hasAttr "image" value.configuration.stylix then + { image = lib.mkForce cfg.specialisation.${name}.configuration.stylix.image; } + else + { } + ); environment.etc."specialisation".text = name; }; }) cfg.specialisation; diff --git a/pkgs/default.nix b/pkgs/default.nix index daa2e37..c410c32 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,7 +1,6 @@ { pkgs, ... }: { - inherit (pkgs.callPackage ./R.nix { }) myR; - inherit (pkgs.callPackage ./R.nix { }) myRstudio; + inherit (pkgs.callPackage ./R.nix { }) myR myRstudio; zju-connect = pkgs.callPackage ./zju-connect.nix { }; swhkd = pkgs.callPackage ./swhkd.nix { }; kose-font = pkgs.callPackage ./fonts/kose.nix { };