Created
February 3, 2025 13:01
-
-
Save EdenQwQ/f82c26d223b997c9aa37d0634af5e26d to your computer and use it in GitHub Desktop.
My nix configuration for generating wallpapers based on a given colorscheme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "Eden's NixOS Flake"; | |
outputs = { | |
nixpkgs, | |
home-manager, | |
nur, | |
... | |
} @ inputs: let | |
system = "x86_64-linux"; | |
pkgs = nixpkgs.legacyPackages.${system}; | |
colorScheme = rec { | |
custom = false; | |
name = "catppuccin-mocha"; | |
path = | |
if custom | |
then ./home/tweaks/colorschemes/${name}.yaml | |
else "${pkgs.base16-schemes}/share/themes/${name}.yaml"; | |
polarity = "dark"; | |
}; | |
wallpapers = { | |
"eDP-1" = { | |
path = ./home/tweaks/wallpapers/freiren-fire.jpg; | |
convertMethod = "lutgen"; # gonord, lutgen, none | |
}; | |
"HDMI-A-1" = { | |
path = ./home/tweaks/wallpapers/green-blue-flowers.jpg; | |
convertMethod = "gonord"; # gonord, lutgen, none | |
}; | |
}; | |
in { | |
nixosConfigurations = { | |
"eden-nixos" = nixpkgs.lib.nixosSystem { | |
system = "${system}"; | |
modules = [ | |
... | |
inputs.stylix.nixosModules.stylix | |
{ | |
stylix = { | |
enable = true; | |
base16Scheme = colorScheme.path; | |
}; | |
} | |
]; | |
}; | |
}; | |
homeConfigurations = { | |
"eden" = home-manager.lib.homeManagerConfiguration { | |
inherit pkgs; | |
modules = [ | |
... | |
inputs.stylix.homeManagerModules.stylix | |
{ | |
stylix = { | |
enable = true; | |
base16Scheme = colorScheme.path; | |
}; | |
} | |
]; | |
extraSpecialArgs = { | |
inherit inputs wallpapers; | |
}; | |
}; | |
}; | |
}; | |
inputs = { | |
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | |
home-manager = { | |
url = "github:nix-community/home-manager/master"; | |
inputs.nixpkgs.follows = "nixpkgs"; | |
}; | |
stylix = { | |
url = "github:danth/stylix"; | |
inputs.nixpkgs.follows = "nixpkgs"; | |
}; | |
... | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
home = { | |
... | |
activation = { | |
reload-waybar = | |
lib.hm.dag.entryAfter ["writeBoundary"] | |
/* | |
bash | |
*/ | |
'' | |
run --quiet ${pkgs.killall}/bin/killall .waybar-wrapped && run --silence ${pkgs.waybar}/bin/waybar \ | |
-c "$HOME/.config/niri/waybar/config.jsonc" \ | |
-s "$HOME/.config/niri/waybar/style.css" -l off & | |
''; | |
reload-swww = let | |
swww = "${pkgs.swww}/bin/swww"; | |
in | |
lib.hm.dag.entryAfter ["writeBoundary"] | |
/* | |
bash | |
*/ | |
'' | |
run --quiet ${swww} img -o eDP-1 "$HOME/Pictures/Wallpapers/eDP-1.jpg" \ | |
&& run --quiet ${swww} img -o HDMI-A-1 "$HOME/Pictures/Wallpapers/HDMI-A-1.jpg" | |
''; | |
}; | |
}; | |
... | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
pkgs, | |
lib, | |
config, | |
wallpapers, | |
... | |
}: let | |
goNord = | |
pkgs.writers.writePython3Bin "goNord" { | |
libraries = with pkgs.python3Packages; [image-go-nord pyyaml]; | |
} '' | |
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 | |
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) | |
''; | |
generateWallpaper = monitor: wallpaper: let | |
inherit (wallpaper) path convertMethod; | |
in | |
if convertMethod == "gonord" | |
then | |
pkgs.runCommand "${monitor}.jpg" {} '' | |
${goNord}/bin/goNord -c ${config.stylix.base16Scheme} -i ${path} -o $out | |
'' | |
else if convertMethod == "lutgen" | |
then let | |
inherit (config.lib.stylix.colors) base00 base01 base02 base03 base04 base05 base06 base07 base08 base09 base0A base0B base0C base0D base0E base0F; | |
in | |
pkgs.runCommand "${monitor}.jpg" {} '' | |
${pkgs.lutgen}/bin/lutgen apply -o $out ${path} -- \ | |
${base00} ${base01} ${base02} ${base03} ${base04} ${base05} \ | |
${base06} ${base07} ${base08} ${base09} ${base0A} ${base0B} \ | |
${base0C} ${base0D} ${base0E} ${base0F} | |
'' | |
else path; | |
generatedWallpapers = builtins.mapAttrs generateWallpaper wallpapers; | |
setWallpaper = monitor: wallpaper: { | |
target = "Pictures/Wallpapers/${monitor}.jpg"; | |
source = wallpaper; | |
}; | |
blurWallpaper = monitor: wallpaper: { | |
name = "${monitor}-blurred"; | |
value = { | |
target = "Pictures/Wallpapers/${monitor}-blurred.jpg"; | |
source = pkgs.runCommand "${monitor}-blurred.jpg" {} '' | |
${pkgs.imagemagick}/bin/magick ${wallpaper} -blur 0x10 $out | |
''; | |
}; | |
}; | |
in { | |
home.file = | |
builtins.mapAttrs setWallpaper generatedWallpapers | |
// lib.attrsets.mapAttrs' blurWallpaper generatedWallpapers; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment