From 3e6796b3ea2112f72778b38bf91c87e60ebd06dd Mon Sep 17 00:00:00 2001 From: EdenQwQ Date: Thu, 6 Mar 2025 13:06:52 +0800 Subject: [PATCH] treewide: make the libs actual libs --- home/programs/desktop/swhkd.nix | 2 +- home/programs/utils/eye-candy.nix | 19 ++---- home/tweaks/colorscheme.nix | 67 ++++++++++++++++++++ home/tweaks/default.nix | 2 + home/tweaks/stylix.nix | 3 +- home/tweaks/wallpaper.nix | 42 +++++++++++++ hosts/default.nix | 4 +- lib/colorScheme/buildColorScheme.nix | 73 +++------------------- lib/colorScheme/default.nix | 6 ++ lib/colorScheme/recolor.nix | 28 +++++---- lib/wallpaper/buildWallpaper.nix | 50 +++------------ lib/wallpaper/default.nix | 7 +++ lib/wallpaper/goNord.nix | 92 ++++++++++++++-------------- lib/wallpaper/lutgen.nix | 32 +++++----- 14 files changed, 230 insertions(+), 197 deletions(-) create mode 100644 home/tweaks/colorscheme.nix create mode 100644 home/tweaks/wallpaper.nix create mode 100644 lib/colorScheme/default.nix create mode 100644 lib/wallpaper/default.nix diff --git a/home/programs/desktop/swhkd.nix b/home/programs/desktop/swhkd.nix index 21bd72b..90792b8 100644 --- a/home/programs/desktop/swhkd.nix +++ b/home/programs/desktop/swhkd.nix @@ -6,7 +6,7 @@ pkill -HUP swhkd super + enter - kitty /home/${user} + kitty -d /home/${user} super + alt + c wl-color-picker diff --git a/home/programs/utils/eye-candy.nix b/home/programs/utils/eye-candy.nix index ef58e27..a5d2a8d 100644 --- a/home/programs/utils/eye-candy.nix +++ b/home/programs/utils/eye-candy.nix @@ -14,19 +14,12 @@ in ]; programs.fastfetch.enable = true; xdg.configFile."fastfetch/config.jsonc".source = ./fastfetch.jsonc; - home.file."Pictures/face.jpg".source = import ../../../lib/wallpaper/goNord.nix { - inherit - pkgs - config - ; - wallpaper = { - name = "face"; - path = pkgs.fetchurl { - name = "face.jpg"; - url = "https://avatars.githubusercontent.com/EdenQwQ"; - sha256 = "1hxl459l3ni5yaj72dngy9wx9rd1yvb85v31nibv5mih4mp1p6cp"; - }; - + home.file."Pictures/face.jpg".source = config.lib.wallpapers.goNord { + name = "face"; + path = pkgs.fetchurl { + name = "face.jpg"; + url = "https://avatars.githubusercontent.com/EdenQwQ"; + sha256 = "1hxl459l3ni5yaj72dngy9wx9rd1yvb85v31nibv5mih4mp1p6cp"; }; }; } diff --git a/home/tweaks/colorscheme.nix b/home/tweaks/colorscheme.nix new file mode 100644 index 0000000..32e5153 --- /dev/null +++ b/home/tweaks/colorscheme.nix @@ -0,0 +1,67 @@ +{ config, lib, ... }: +let + matugenOptions = lib.types.submodule { + options = { + image = lib.mkOption { + type = lib.types.either lib.types.str lib.types.path; + description = "Path to the image"; + }; + scheme = lib.mkOption { + type = lib.types.str; + description = "The material you scheme to use"; + default = "scheme-tonal-spot"; + }; + }; + }; + + colorScheme = lib.types.submodule { + options = { + name = lib.mkOption { + type = lib.types.str; + description = "Name of the color scheme"; + }; + isDefault = lib.mkOption { + type = lib.types.bool; + description = "Whether the color scheme is the default"; + default = false; + }; + polarity = lib.mkOption { + type = lib.types.enum [ + "dark" + "light" + ]; + description = "Polarity of the color scheme (dark or light)"; + default = "dark"; + }; + matugen = lib.mkOption { + type = lib.types.nullOr matugenOptions; + description = "Matugen options"; + default = null; + }; + }; + }; + +in +{ + options.colorSchemes = lib.mkOption { + type = lib.types.listOf (lib.types.either colorScheme lib.types.str); + description = "List of colorschemes"; + }; + + config = + with config.lib.colorScheme; + let + colorSchemes = config.colorSchemes |> map convertColorScheme; + in + { + stylix = { + enable = true; + inherit (builtins.filter (c: c.isDefault) colorSchemes |> builtins.head |> buildColorScheme) + base16Scheme + polarity + ; + }; + specialisation = + builtins.filter (c: !c.isDefault) colorSchemes |> map buildSpecialisation |> builtins.listToAttrs; + }; +} diff --git a/home/tweaks/default.nix b/home/tweaks/default.nix index 6f8aaf7..9ced03a 100644 --- a/home/tweaks/default.nix +++ b/home/tweaks/default.nix @@ -4,5 +4,7 @@ ./fcitx5.nix ./dconf.nix ./stylix.nix + ./wallpaper.nix + ./colorscheme.nix ]; } diff --git a/home/tweaks/stylix.nix b/home/tweaks/stylix.nix index 67387ff..298edfe 100644 --- a/home/tweaks/stylix.nix +++ b/home/tweaks/stylix.nix @@ -1,11 +1,10 @@ { pkgs, - lib, config, ... }: let - recolorScript = import ../../lib/colorScheme/recolor.nix { inherit pkgs config; }; + inherit (config.lib.colorScheme) recolorScript; in { stylix = { diff --git a/home/tweaks/wallpaper.nix b/home/tweaks/wallpaper.nix new file mode 100644 index 0000000..51a0d8f --- /dev/null +++ b/home/tweaks/wallpaper.nix @@ -0,0 +1,42 @@ +{ config, lib, ... }: +with config.lib.wallpapers; +let + wallpaper = lib.types.submodule { + options = { + name = lib.mkOption { + type = lib.types.str; + description = "Name of the wallpaper"; + }; + url = lib.mkOption { + type = lib.types.str; + description = "URL of the wallpaper"; + }; + sha256 = lib.mkOption { + type = lib.types.str; + description = "SHA256 of the wallpaper"; + }; + convertMethod = lib.mkOption { + type = lib.types.str; + description = "Method to convert the wallpaper (gonord, lutgen, none)"; + default = "lutgen"; + }; + }; + }; +in +{ + options.wallpapers = lib.mkOption { + type = lib.types.listOf wallpaper; + description = "List of wallpapers"; + }; + + config = + let + wallpapers = map getWallpaper config.wallpapers; + generatedWallpapers = map generateWallpaper wallpapers; + normalWallpapers = map setWallpaper generatedWallpapers |> builtins.listToAttrs; + blurredWallpapers = map blurWallpaper generatedWallpapers |> builtins.listToAttrs; + in + { + home.file = normalWallpapers // blurredWallpapers; + }; +} diff --git a/hosts/default.nix b/hosts/default.nix index 5bd8135..21f3d78 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -17,8 +17,8 @@ let ../home ../nix/nixpkgs.nix ../sharedConfig.nix - ../lib/colorScheme/buildColorScheme.nix - ../lib/wallpaper/buildWallpaper.nix + ../lib/colorScheme + ../lib/wallpaper inputs.nur.modules.homeManager.default inputs.stylix.homeManagerModules.stylix inputs.niri.homeModules.niri diff --git a/lib/colorScheme/buildColorScheme.nix b/lib/colorScheme/buildColorScheme.nix index 33ba417..d28779e 100644 --- a/lib/colorScheme/buildColorScheme.nix +++ b/lib/colorScheme/buildColorScheme.nix @@ -5,53 +5,13 @@ ... }: let - matugenOptions = lib.types.submodule { - options = { - image = lib.mkOption { - type = lib.types.either lib.types.str lib.types.path; - description = "Path to the image"; - }; - polarity = lib.mkOption { - type = lib.types.enum [ - "dark" - "light" - ]; - description = "Polarity of the color scheme (dark or light)"; - default = "dark"; - }; - scheme = lib.mkOption { - type = lib.types.str; - description = "The material you scheme to use"; - default = "scheme-tonal-spot"; - }; - }; - }; - - colorScheme = lib.types.submodule { - options = { - name = lib.mkOption { - type = lib.types.str; - description = "Name of the color scheme"; - }; - isDefault = lib.mkOption { - type = lib.types.bool; - description = "Whether the color scheme is the default"; - default = false; - }; - matugen = lib.mkOption { - type = lib.types.nullOr matugenOptions; - description = "Matugen options"; - default = null; - }; - }; - }; - convertColorScheme = colorScheme: if builtins.typeOf colorScheme == "string" then { name = colorScheme; isDefault = false; + polarity = "dark"; matugen = null; } else @@ -62,8 +22,8 @@ let matugenToBase16 = colorScheme: let - inherit (colorScheme) name matugen; - inherit (matugen) polarity scheme; + inherit (colorScheme) name matugen polarity; + inherit (matugen) scheme; image = if builtins.typeOf matugen.image == "path" then matugen.image @@ -89,6 +49,7 @@ let inherit (colorScheme) name isDefault + polarity matugen ; forceOrDefault = if isDefault then lib.mkDefault else lib.mkForce; @@ -99,13 +60,7 @@ let "${matugenToBase16 colorScheme}" else forceOrDefault "${pkgs.base16-schemes}/share/themes/${name}.yaml"; - polarity = - if matugen != null then - matugen.polarity - else if builtins.fromJSON config.lib.stylix.colors.base00-dec-r < 0.5 then - forceOrDefault "dark" - else - forceOrDefault "light"; + inherit polarity; }; buildSpecialisation = @@ -122,21 +77,7 @@ let }; in { - options.colorSchemes = lib.mkOption { - type = lib.types.listOf (lib.types.either colorScheme lib.types.str); - description = "List of colorschemes"; + config.lib.colorScheme = { + inherit convertColorScheme buildColorScheme buildSpecialisation; }; - - config = - let - colorSchemes = config.colorSchemes |> map convertColorScheme; - in - { - stylix = { - enable = true; - } // (builtins.filter (c: c.isDefault) colorSchemes |> builtins.head |> buildColorScheme); - - specialisation = - builtins.filter (c: !c.isDefault) colorSchemes |> map buildSpecialisation |> builtins.listToAttrs; - }; } diff --git a/lib/colorScheme/default.nix b/lib/colorScheme/default.nix new file mode 100644 index 0000000..35e1e62 --- /dev/null +++ b/lib/colorScheme/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./recolor.nix + ./buildColorScheme.nix + ]; +} diff --git a/lib/colorScheme/recolor.nix b/lib/colorScheme/recolor.nix index 6e26401..5225952 100644 --- a/lib/colorScheme/recolor.nix +++ b/lib/colorScheme/recolor.nix @@ -1,6 +1,6 @@ -{ pkgs, config }: +{ pkgs, config, ... }: let - cfg.recolor = { + recolorConfig = { mode = "palette"; colors = config.lib.stylix.colors.withHashtag.toList; smooth = true; @@ -31,14 +31,16 @@ let ] ); in -with cfg.recolor; -'' - ${pythonEnv}/bin/python ${./recolor.py} --src $out/share/icons \ - --smooth '${toString smooth}' \ - ${ - if cfg.recolor.mode == "monochrome" then - "--monochrome '${builtins.concatStringsSep "," cfg.recolor.colors}'" - else - "--palette ''${builtins.concatStringsSep "," cfg.recolor.colors}''" - } -'' +with recolorConfig; +{ + config.lib.colorScheme.recolorScript = '' + ${pythonEnv}/bin/python ${./recolor.py} --src $out/share/icons \ + --smooth '${toString smooth}' \ + ${ + if mode == "monochrome" then + "--monochrome '${builtins.concatStringsSep "," colors}'" + else + "--palette ''${builtins.concatStringsSep "," colors}''" + } + ''; +} diff --git a/lib/wallpaper/buildWallpaper.nix b/lib/wallpaper/buildWallpaper.nix index 1ba4c4f..6eee540 100644 --- a/lib/wallpaper/buildWallpaper.nix +++ b/lib/wallpaper/buildWallpaper.nix @@ -6,6 +6,8 @@ }: with builtins; let + inherit (config.lib.wallpapers) goNord lutgen; + getWallpaper = wallpaper: let @@ -16,12 +18,6 @@ let path = "${wallpaperPkg}"; }; - wallpapers = map getWallpaper config.wallpapers; - - goNord = wallpaper: import ./goNord.nix { inherit pkgs config wallpaper; }; - - lutgen = wallpaper: import ./lutgen.nix { inherit pkgs config wallpaper; }; - getName = path: baseNameOf path |> match "(.*)\\..*" |> head |> lib.splitString "-" |> tail |> concatStringsSep "-"; @@ -47,8 +43,6 @@ let path; }; - generatedWallpapers = map generateWallpaper wallpapers; - setWallpaper = wallpaper: let @@ -78,39 +72,15 @@ let ''; }; }; - - normalWallpapers = map setWallpaper generatedWallpapers |> listToAttrs; - blurredWallpapers = map blurWallpaper generatedWallpapers |> listToAttrs; - - wallpaper = lib.types.submodule { - options = { - name = lib.mkOption { - type = lib.types.str; - description = "Name of the wallpaper"; - }; - url = lib.mkOption { - type = lib.types.str; - description = "URL of the wallpaper"; - }; - sha256 = lib.mkOption { - type = lib.types.str; - description = "SHA256 of the wallpaper"; - }; - convertMethod = lib.mkOption { - type = lib.types.str; - description = "Method to convert the wallpaper (gonord, lutgen, none)"; - default = "lutgen"; - }; - }; - }; in { - options.wallpapers = lib.mkOption { - type = lib.types.listOf wallpaper; - description = "List of wallpapers"; - }; - - config = { - home.file = normalWallpapers // blurredWallpapers; + config.lib.wallpapers = { + inherit + getWallpaper + convertWallpaper + generateWallpaper + setWallpaper + blurWallpaper + ; }; } diff --git a/lib/wallpaper/default.nix b/lib/wallpaper/default.nix new file mode 100644 index 0000000..3976759 --- /dev/null +++ b/lib/wallpaper/default.nix @@ -0,0 +1,7 @@ +{ + imports = [ + ./goNord.nix + ./lutgen.nix + ./buildWallpaper.nix + ]; +} diff --git a/lib/wallpaper/goNord.nix b/lib/wallpaper/goNord.nix index e12b54c..af7502f 100644 --- a/lib/wallpaper/goNord.nix +++ b/lib/wallpaper/goNord.nix @@ -1,50 +1,50 @@ +{ config, pkgs, ... }: { - pkgs, - config, - wallpaper, -}: -let - goNordScript = - pkgs.writers.writePython3Bin "goNord" - { - libraries = with pkgs.python3Packages; [ - image-go-nord - pyyaml - ]; - doCheck = false; - } - '' - from ImageGoNord import GoNord - import argparse - import yaml + config.lib.wallpapers.goNord = + image: + let + goNordScript = + pkgs.writers.writePython3Bin "goNord" + { + libraries = with pkgs.python3Packages; [ + image-go-nord + pyyaml + ]; + doCheck = false; + } + '' + from ImageGoNord import GoNord + import argparse + import yaml - parser = argparse.ArgumentParser(description="Go nord") - parser.add_argument( - "--colorscheme", "-c", help="Path to the yaml file containing the colorscheme" - ) - parser.add_argument("--image", "-i", help="Path to the image to quantize") - parser.add_argument( - "--output", "-o", help="Path to the output image", default="output.png" - ) - args = parser.parse_args() - colorscheme = args.colorscheme - image = args.image - output = args.output + parser = argparse.ArgumentParser(description="Go nord") + parser.add_argument( + "--colorscheme", "-c", help="Path to the yaml file containing the colorscheme" + ) + parser.add_argument("--image", "-i", help="Path to the image to quantize") + parser.add_argument( + "--output", "-o", help="Path to the output image", default="output.png" + ) + args = parser.parse_args() + colorscheme = args.colorscheme + image = args.image + output = args.output - go_nord = GoNord() - go_nord.enable_avg_algorithm() - go_nord.enable_gaussian_blur() - image = go_nord.open_image(image) - if colorscheme: - go_nord.reset_palette() - palette = set(yaml.safe_load(open(colorscheme))["palette"].values()) - for color in palette: - go_nord.add_color_to_palette(color) - go_nord.quantize_image(image, save_path=output) - ''; + go_nord = GoNord() + go_nord.enable_avg_algorithm() + go_nord.enable_gaussian_blur() + image = go_nord.open_image(image) + if colorscheme: + go_nord.reset_palette() + palette = set(yaml.safe_load(open(colorscheme))["palette"].values()) + for color in palette: + go_nord.add_color_to_palette(color) + go_nord.quantize_image(image, save_path=output) + ''; - inherit (wallpaper) name path; -in -pkgs.runCommand "${name}.jpg" { } '' - ${goNordScript}/bin/goNord -c ${config.stylix.base16Scheme} -i ${path} -o $out -'' + inherit (image) name path; + in + pkgs.runCommand "${name}.jpg" { } '' + ${goNordScript}/bin/goNord -c ${config.stylix.base16Scheme} -i ${path} -o $out + ''; +} diff --git a/lib/wallpaper/lutgen.nix b/lib/wallpaper/lutgen.nix index cec3005..23da813 100644 --- a/lib/wallpaper/lutgen.nix +++ b/lib/wallpaper/lutgen.nix @@ -1,18 +1,22 @@ { pkgs, config, - wallpaper, + ... }: -let - inherit (wallpaper) name path live; - colors = builtins.concatStringsSep " " config.lib.stylix.colors.toList; -in -if live then - pkgs.runCommand "${name}.gif" { } '' - ${pkgs.lutgen}/bin/lutgen generate -o palette.png -- ${colors} - ${pkgs.ffmpeg}/bin/ffmpeg -i ${path} -i palette.png -filter_complex '[0][1] haldclut' $out - '' -else - pkgs.runCommand "${name}.jpg" { } '' - ${pkgs.lutgen}/bin/lutgen apply -o $out ${path} -- ${colors} - '' +{ + config.lib.wallpapers.lutgen = + image: + let + inherit (image) name path live; + colors = builtins.concatStringsSep " " config.lib.stylix.colors.toList; + in + if live then + pkgs.runCommand "${name}.gif" { } '' + ${pkgs.lutgen}/bin/lutgen generate -o palette.png -- ${colors} + ${pkgs.ffmpeg}/bin/ffmpeg -i ${path} -i palette.png -filter_complex '[0][1] haldclut' $out + '' + else + pkgs.runCommand "${name}.jpg" { } '' + ${pkgs.lutgen}/bin/lutgen apply -o $out ${path} -- ${colors} + ''; +}