From bc9b2e37104b6de76e17e13ab250cf1f695951e1 Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Mon, 23 Dec 2024 11:24:01 +0100 Subject: [PATCH 1/8] add darker theme --- palette-generator/Stylix/Palette.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/palette-generator/Stylix/Palette.hs b/palette-generator/Stylix/Palette.hs index 83d18596e..c2ffafb83 100644 --- a/palette-generator/Stylix/Palette.hs +++ b/palette-generator/Stylix/Palette.hs @@ -72,9 +72,10 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where + sum (V.map (difference accentValue) $ accent lightnesses) scheme = case polarity of - "either" -> min lightScheme darkScheme + "either" -> min lightScheme darkScheme darkerScheme "light" -> lightScheme "dark" -> darkScheme + "darker" -> darkerScheme _ -> error ("Invalid polarity: " ++ polarity) {- @@ -90,3 +91,6 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where -} darkScheme = lightnessError (V.fromList [10, 30, 45, 65, 75, 90, 95, 95]) 60 + + darkerScheme + = lightnessError (V.fromList [5, 15, 20, 30, 40, 80, 95, 95]) 60 From c5c1fa3e732a0a5325bd21b61d2b6fae86ae5513 Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Mon, 23 Dec 2024 11:24:50 +0100 Subject: [PATCH 2/8] add darker theme --- palette-generator/Stylix/Palette.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/palette-generator/Stylix/Palette.hs b/palette-generator/Stylix/Palette.hs index c2ffafb83..4a471aa8d 100644 --- a/palette-generator/Stylix/Palette.hs +++ b/palette-generator/Stylix/Palette.hs @@ -72,7 +72,7 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where + sum (V.map (difference accentValue) $ accent lightnesses) scheme = case polarity of - "either" -> min lightScheme darkScheme darkerScheme + "either" -> min lightScheme darkScheme "light" -> lightScheme "dark" -> darkScheme "darker" -> darkerScheme From 07e3eb5fed17037f2c9cda30eb98c658e50a7eed Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Mon, 23 Dec 2024 11:30:09 +0100 Subject: [PATCH 3/8] add darker theme --- modules/gnome/hm.nix | 18 ++++++++++-------- modules/qutebrowser/hm.nix | 13 +++++++------ stylix/palette.nix | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/modules/gnome/hm.nix b/modules/gnome/hm.nix index c0cfd2293..a2e6ef710 100644 --- a/modules/gnome/hm.nix +++ b/modules/gnome/hm.nix @@ -1,10 +1,12 @@ -{ pkgs, config, lib, ... }: - -let +{ + pkgs, + config, + lib, + ... +}: let inherit (config.stylix.fonts) sansSerif serif monospace; fontSize = toString config.stylix.fonts.sizes.applications; documentFontSize = toString (config.stylix.fonts.sizes.applications - 1); - in { options.stylix.targets.gnome.enable = config.lib.stylix.mkEnableTarget "GNOME" true; @@ -35,7 +37,7 @@ in { # settings tile is removed. The value is still used by Epiphany to # request dark mode for websites which support it. color-scheme = - if config.stylix.polarity == "dark" + if config.stylix.polarity == "dark" || config.stylix.polarity == "darker" then "prefer-dark" else "default"; @@ -50,11 +52,11 @@ in { }; xdg.dataFile."themes/Stylix/gnome-shell/gnome-shell.css" = { - source = - let theme = pkgs.callPackage ./theme.nix { + source = let + theme = pkgs.callPackage ./theme.nix { inherit (config.lib.stylix) colors templates; }; - in "${theme}/share/gnome-shell/gnome-shell.css"; + in "${theme}/share/gnome-shell/gnome-shell.css"; onChange = '' if [[ -x "$(command -v gnome-extensions)" ]]; then gnome-extensions disable user-theme@gnome-shell-extensions.gcampax.github.com diff --git a/modules/qutebrowser/hm.nix b/modules/qutebrowser/hm.nix index 033ad4b7d..fc839c7bf 100644 --- a/modules/qutebrowser/hm.nix +++ b/modules/qutebrowser/hm.nix @@ -1,9 +1,10 @@ -{ config, lib, ... }: - +{ + config, + lib, + ... +}: with config.lib.stylix.colors.withHashtag; -with config.stylix.fonts; - -let +with config.stylix.fonts; let background = base00; secondary-background = base01; selection-background = base03; @@ -247,7 +248,7 @@ in { }; webpage = let - isDark = config.stylix.polarity == "dark"; + isDark = config.stylix.polarity == "dark" || config.stylix.polarity == "darker"; in { darkmode.enabled = lib.mkIf isDark (lib.mkDefault true); diff --git a/stylix/palette.nix b/stylix/palette.nix index 7fe9600a5..0c6f49889 100644 --- a/stylix/palette.nix +++ b/stylix/palette.nix @@ -23,7 +23,7 @@ let in { options.stylix = { polarity = lib.mkOption { - type = lib.types.enum [ "either" "light" "dark" ]; + type = lib.types.enum [ "either" "light" "dark" "darker" ]; default = "either"; description = '' Use this option to force a light or dark theme. From 66106cc1c7cfcd304720861d878122f2ae749b1f Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Mon, 23 Dec 2024 11:34:17 +0100 Subject: [PATCH 4/8] add darker theme --- palette-generator/Stylix/Palette.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/palette-generator/Stylix/Palette.hs b/palette-generator/Stylix/Palette.hs index 4a471aa8d..528f2f65c 100644 --- a/palette-generator/Stylix/Palette.hs +++ b/palette-generator/Stylix/Palette.hs @@ -93,4 +93,4 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where = lightnessError (V.fromList [10, 30, 45, 65, 75, 90, 95, 95]) 60 darkerScheme - = lightnessError (V.fromList [5, 15, 20, 30, 40, 80, 95, 95]) 60 + = lightnessError (V.fromList [5, 10, 15, 20, 25, 80, 95, 95]) 60 From 66c79065dae1299e6d8ebca863760d4f15c30340 Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Mon, 23 Dec 2024 11:45:16 +0100 Subject: [PATCH 5/8] add darker theme --- palette-generator/Stylix/Palette.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/palette-generator/Stylix/Palette.hs b/palette-generator/Stylix/Palette.hs index 528f2f65c..1727af445 100644 --- a/palette-generator/Stylix/Palette.hs +++ b/palette-generator/Stylix/Palette.hs @@ -93,4 +93,4 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where = lightnessError (V.fromList [10, 30, 45, 65, 75, 90, 95, 95]) 60 darkerScheme - = lightnessError (V.fromList [5, 10, 15, 20, 25, 80, 95, 95]) 60 + = lightnessError (V.fromList [5, 10, 15, 20, 70, 80, 95, 95]) 60 From 78ac78bb1d2160b3601b2656dd2c48857068d0c5 Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Mon, 23 Dec 2024 15:28:40 +0100 Subject: [PATCH 6/8] feat: add even-darker --- modules/gnome/hm.nix | 2 +- modules/qutebrowser/hm.nix | 2 +- palette-generator/Stylix/Palette.hs | 4 ++++ stylix/palette.nix | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/gnome/hm.nix b/modules/gnome/hm.nix index a2e6ef710..d79b876e6 100644 --- a/modules/gnome/hm.nix +++ b/modules/gnome/hm.nix @@ -37,7 +37,7 @@ in { # settings tile is removed. The value is still used by Epiphany to # request dark mode for websites which support it. color-scheme = - if config.stylix.polarity == "dark" || config.stylix.polarity == "darker" + if config.stylix.polarity == "dark" || config.stylix.polarity == "darker" || config.stylix.polarity == "even-darker" then "prefer-dark" else "default"; diff --git a/modules/qutebrowser/hm.nix b/modules/qutebrowser/hm.nix index fc839c7bf..bfc545623 100644 --- a/modules/qutebrowser/hm.nix +++ b/modules/qutebrowser/hm.nix @@ -248,7 +248,7 @@ in { }; webpage = let - isDark = config.stylix.polarity == "dark" || config.stylix.polarity == "darker"; + isDark = config.stylix.polarity == "dark" || config.stylix.polarity == "darker" || config.stylix.polarity == "even-darker"; in { darkmode.enabled = lib.mkIf isDark (lib.mkDefault true); diff --git a/palette-generator/Stylix/Palette.hs b/palette-generator/Stylix/Palette.hs index 1727af445..535a420f4 100644 --- a/palette-generator/Stylix/Palette.hs +++ b/palette-generator/Stylix/Palette.hs @@ -76,6 +76,7 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where "light" -> lightScheme "dark" -> darkScheme "darker" -> darkerScheme + "even-darker" -> evenDarkerScheme _ -> error ("Invalid polarity: " ++ polarity) {- @@ -94,3 +95,6 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where darkerScheme = lightnessError (V.fromList [5, 10, 15, 20, 70, 80, 95, 95]) 60 + + evenDarkerScheme + = lightnessError (V.fromList [2, 4, 8, 10, 70, 80, 95, 95]) 60 diff --git a/stylix/palette.nix b/stylix/palette.nix index 0c6f49889..3d7befc69 100644 --- a/stylix/palette.nix +++ b/stylix/palette.nix @@ -23,7 +23,7 @@ let in { options.stylix = { polarity = lib.mkOption { - type = lib.types.enum [ "either" "light" "dark" "darker" ]; + type = lib.types.enum [ "either" "light" "dark" "darker" "even-darker" ]; default = "either"; description = '' Use this option to force a light or dark theme. From ff7e1e77a395c9a287c59d179f78c6d874e46630 Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Mon, 23 Dec 2024 15:42:54 +0100 Subject: [PATCH 7/8] feat: add even-darker --- palette-generator/Stylix/Palette.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/palette-generator/Stylix/Palette.hs b/palette-generator/Stylix/Palette.hs index 535a420f4..4683d0b06 100644 --- a/palette-generator/Stylix/Palette.hs +++ b/palette-generator/Stylix/Palette.hs @@ -94,7 +94,7 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where = lightnessError (V.fromList [10, 30, 45, 65, 75, 90, 95, 95]) 60 darkerScheme - = lightnessError (V.fromList [5, 10, 15, 20, 70, 80, 95, 95]) 60 + = lightnessError (V.fromList [5, 10, 15, 60, 70, 80, 95, 95]) 60 evenDarkerScheme - = lightnessError (V.fromList [2, 4, 8, 10, 70, 80, 95, 95]) 60 + = lightnessError (V.fromList [2, 4, 8, 55, 70, 80, 95, 95]) 60 From c02de177ea438ee08d1126cc39a70e53799d5ce5 Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Tue, 24 Dec 2024 17:32:00 +0100 Subject: [PATCH 8/8] feat: replace polarity modifications with primary scale options --- docs/src/configuration.md | 4 +- modules/gnome/hm.nix | 2 +- modules/kubecolor/hm.nix | 10 +- modules/qutebrowser/hm.nix | 4 +- palette-generator/Stylix/Main.hs | 23 +++-- palette-generator/Stylix/Palette.hs | 64 ++++++++++--- stylix/hm/icon.nix | 44 +++++---- stylix/home-manager-integration.nix | 78 ++++++++------- stylix/palette.nix | 64 +++++++++---- stylix/testbed.nix | 141 ++++++++++++++-------------- 10 files changed, 264 insertions(+), 170 deletions(-) diff --git a/docs/src/configuration.md b/docs/src/configuration.md index 9f51a1cad..cdb0191f2 100644 --- a/docs/src/configuration.md +++ b/docs/src/configuration.md @@ -47,11 +47,11 @@ If you only set a wallpaper, Stylix will use a to create a color scheme. The quality of these schemes can vary, but more colorful images tend to have better results. -You can force a light or dark scheme using the polarity option: +You can force a light or dark scheme using the `polarity.force` option: ```nix { - stylix.polarity = "dark"; + stylix.force.polarity = "dark"; } ``` diff --git a/modules/gnome/hm.nix b/modules/gnome/hm.nix index d79b876e6..81dca188f 100644 --- a/modules/gnome/hm.nix +++ b/modules/gnome/hm.nix @@ -37,7 +37,7 @@ in { # settings tile is removed. The value is still used by Epiphany to # request dark mode for websites which support it. color-scheme = - if config.stylix.polarity == "dark" || config.stylix.polarity == "darker" || config.stylix.polarity == "even-darker" + if config.stylix.polarity.force == "dark" then "prefer-dark" else "default"; diff --git a/modules/kubecolor/hm.nix b/modules/kubecolor/hm.nix index 378e3fcb5..86224bbff 100644 --- a/modules/kubecolor/hm.nix +++ b/modules/kubecolor/hm.nix @@ -1,10 +1,16 @@ -{ config, lib, ... }: { + config, + lib, + ... +}: { options.stylix.targets.kubecolor.enable = config.lib.stylix.mkEnableTarget "kubecolor" true; config = lib.mkIf config.stylix.targets.kubecolor.enable { programs.kubecolor.settings = { - preset = if config.stylix.polarity == "either" then "" else "${config.stylix.polarity}"; + preset = + if config.stylix.polarity.force == "either" + then "" + else "${config.stylix.polarity.force}"; theme = { base = { info = "fg=${config.lib.stylix.colors.withHashtag.base05-hex}"; diff --git a/modules/qutebrowser/hm.nix b/modules/qutebrowser/hm.nix index bfc545623..4e9db0f64 100644 --- a/modules/qutebrowser/hm.nix +++ b/modules/qutebrowser/hm.nix @@ -248,13 +248,13 @@ in { }; webpage = let - isDark = config.stylix.polarity == "dark" || config.stylix.polarity == "darker" || config.stylix.polarity == "even-darker"; + isDark = config.stylix.polarity.force == "dark"; in { darkmode.enabled = lib.mkIf isDark (lib.mkDefault true); preferred_color_scheme = lib.mkIf - isDark (lib.mkDefault config.stylix.polarity); + isDark (lib.mkDefault config.stylix.polarity.force); }; }; diff --git a/palette-generator/Stylix/Main.hs b/palette-generator/Stylix/Main.hs index d4a49e609..5673d3289 100644 --- a/palette-generator/Stylix/Main.hs +++ b/palette-generator/Stylix/Main.hs @@ -8,30 +8,39 @@ import System.Environment ( getArgs ) import System.Exit ( die ) import System.Random ( setStdGen, mkStdGen ) import Text.JSON ( encode ) +import Text.Read (readMaybe) + +-- String to float +stringToDouble :: String -> Double +stringToDouble s = case readMaybe s of + Just x -> x + Nothing -> error "Invalid float value" -- | Load an image file. loadImage :: String -- ^ Path to the file -> IO DynamicImage loadImage input = either error id <$> readImage input -mainProcess :: (String, String, String) -> IO () -mainProcess (polarity, input, output) = do +mainProcess :: (String,String,String, String, String) -> IO () +mainProcess (polarity, primaryScaleDark, primaryScaleLight, input, output) = do putStrLn $ "Processing " ++ input -- Random numbers must be deterministic when running inside Nix. setStdGen $ mkStdGen 0 image <- loadImage input - palette <- evolve (polarity, convertRGB8 image) + palette <- evolve (polarity,stringToDouble primaryScaleDark,stringToDouble primaryScaleLight,convertRGB8 image) let outputTable = makeOutputTable $ V.map lab2rgb palette writeFile output $ encode outputTable putStrLn $ "Saved to " ++ output -parseArguments :: [String] -> Either String (String, String, String) -parseArguments [polarity, input, output] = Right (polarity, input, output) -parseArguments [_, _] = Left "Please specify an output file" -parseArguments [_] = Left "Please specify an image" +parseArguments :: [String] -> Either String (String, String,String,String, String) +parseArguments [polarity, primaryScaleDark, primaryScaleLight,input, output] = Right (polarity,primaryScaleDark, primaryScaleLight, input, output) +parseArguments [_, _,_,_] = Left "Please specify an output file" +parseArguments [_, _,_] = Left "Please specify an image" +parseArguments [_, _] = Left "Please specify a primary scaling factor for the light polarity" +parseArguments [_] = Left "Please specify a primary scaling factor for the dark polarity" parseArguments [] = Left "Please specify a polarity: either, light or dark" parseArguments _ = Left "Too many arguments" diff --git a/palette-generator/Stylix/Palette.hs b/palette-generator/Stylix/Palette.hs index 4683d0b06..265fabaf0 100644 --- a/palette-generator/Stylix/Palette.hs +++ b/palette-generator/Stylix/Palette.hs @@ -10,6 +10,10 @@ import Data.Vector ( (//) ) import qualified Data.Vector as V import System.Random ( randomRIO ) +-- Adjust value according to coefficients +adjustValue :: Double -> Double-> Double -> Double -> Double +adjustValue v a b x = minimum [maximum [0.0, v*(a*x+b)], 100.0] + -- | Extract the primary scale from a pallete. primary :: V.Vector a -> V.Vector a primary = V.take 8 @@ -34,17 +38,17 @@ randomFromImage image = do color = RGB (fromIntegral r) (fromIntegral g) (fromIntegral b) return $ rgb2lab color -instance Species (String, Image PixelRGB8) (V.Vector LAB) where - generate (_, image) = V.replicateM 16 $ randomFromImage image +instance Species (String,Double,Double, Image PixelRGB8) (V.Vector LAB) where + generate (_,_,_, image) = V.replicateM 16 $ randomFromImage image crossover _ a b = return $ alternatingZip a b - mutate (_, image) palette = do + mutate (_,_,_, image) palette = do index <- randomRIO (0, 15) colour <- randomFromImage image return $ palette // [(index, colour)] - fitness (polarity, _) palette + fitness (polarity,primaryScaleDark,primaryScaleLight, _) palette = realToFrac $ accentDifference - (primarySimilarity/10) - scheme where -- The primary scale should use similar colours, to an extent. @@ -75,8 +79,6 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where "either" -> min lightScheme darkScheme "light" -> lightScheme "dark" -> darkScheme - "darker" -> darkerScheme - "even-darker" -> evenDarkerScheme _ -> error ("Invalid polarity: " ++ polarity) {- @@ -84,17 +86,51 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where The accent colours are slightly darker. -} lightScheme - = lightnessError (V.fromList [90, 70, 55, 35, 25, 10, 5, 5]) 40 + = lightnessError (V.fromList [ + (adjustValue 90.0 0.1 0.0 primaryScaleLight), + (adjustValue 70.0 0.963 0.037 primaryScaleLight), + (adjustValue 55.0 0.913 0.087 primaryScaleLight), + (adjustValue 35.0 0.167 0.883 primaryScaleLight), + (adjustValue 25.0 0.078 0.922 primaryScaleLight), + (adjustValue 10.0 0.056 0.944 primaryScaleLight), + (adjustValue 5.0 0.0 1.0 primaryScaleLight), + (adjustValue 5.0 0.0 1.0 primaryScaleLight) + ]) 40 + + -- 0.1, 0.133,0.178,0.85,0.93,0.95,1.0,1.0 for 0.1 scale + -- f(x) = ax+b for multiplier (light) + -- 1.0, 0.0 + -- 0.963, 0.037 + -- 0.913, 0.087 + -- 0.167, 0.833 + -- 0.078, 0.922 + -- 0.056, 0.944 + -- 0.0, 1.0 + -- 0.0, 1.0 {- For dark themes, the background is dark and the text is bright. The accent colours are slightly brighter. -} darkScheme - = lightnessError (V.fromList [10, 30, 45, 65, 75, 90, 95, 95]) 60 - - darkerScheme - = lightnessError (V.fromList [5, 10, 15, 60, 70, 80, 95, 95]) 60 - - evenDarkerScheme - = lightnessError (V.fromList [2, 4, 8, 55, 70, 80, 95, 95]) 60 + = lightnessError (V.fromList [ + (adjustValue 10.0 1.0 0.0 primaryScaleDark), + (adjustValue 30.0 0.963 0.037 primaryScaleDark), + (adjustValue 45.0 0.913 0.087 primaryScaleDark), + (adjustValue 65.0 0.167 0.883 primaryScaleDark), + (adjustValue 75.0 0.078 0.922 primaryScaleDark), + (adjustValue 90.0 0.056 0.944 primaryScaleDark), + (adjustValue 95.0 0.0 1.0 primaryScaleDark), + (adjustValue 95.0 0.0 1.0 primaryScaleDark) + ]) 60 + + -- 0.1, 0.133,0.178,0.85,0.93,0.95,1.0,1.0 for 0.1 scale + -- f(x) = ax+b for multiplier (dark) + -- 1.0, 0.0 + -- 0.963, 0.037 + -- 0.913, 0.087 + -- 0.167, 0.833 + -- 0.078, 0.922 + -- 0.056, 0.944 + -- 0.0, 1.0 + -- 0.0, 1.0 diff --git a/stylix/hm/icon.nix b/stylix/hm/icon.nix index c0d9fddbe..b16154014 100644 --- a/stylix/hm/icon.nix +++ b/stylix/hm/icon.nix @@ -1,22 +1,26 @@ -{ config, lib, ... }: - -let - cfg = config.stylix.iconTheme; - inherit (config.stylix) polarity; +{ + config, + lib, + ... +}: let + cfg = config.stylix.iconTheme; + inherit (config.stylix) polarity; in { - imports = [ ../icon.nix ]; - config = lib.mkIf (config.stylix.enable && cfg.enable) { - gtk = { - iconTheme = { - inherit (cfg) package; - name = builtins.head (lib.filter (x: null != x) [ - ({ - inherit (cfg) dark light; - }."${polarity}" or null) - cfg.dark - cfg.light - ]); - }; - }; - }; + imports = [../icon.nix]; + config = lib.mkIf (config.stylix.enable && cfg.enable) { + gtk = { + iconTheme = { + inherit (cfg) package; + name = builtins.head (lib.filter (x: null != x) [ + ({ + inherit (cfg) dark light; + } + ."${polarity.force}" + or null) + cfg.dark + cfg.light + ]); + }; + }; + }; } diff --git a/stylix/home-manager-integration.nix b/stylix/home-manager-integration.nix index 5afe202b1..ce88c0d53 100644 --- a/stylix/home-manager-integration.nix +++ b/stylix/home-manager-integration.nix @@ -1,45 +1,55 @@ -homeManagerModule: -{ lib, config, options, ... }: - -let - copyModules = builtins.map +homeManagerModule: { + lib, + config, + options, + ... +}: let + copyModules = + builtins.map ( - { path, condition ? lib.const true }: - { config, osConfig, ... }: - lib.mkIf (condition config) - (lib.setAttrByPath path (lib.mkDefault (lib.getAttrFromPath path osConfig))) + { + path, + condition ? lib.const true, + }: { + config, + osConfig, + ... + }: + lib.mkIf (condition config) + (lib.setAttrByPath path (lib.mkDefault (lib.getAttrFromPath path osConfig))) ) [ - { path = [ "stylix" "autoEnable" ]; } + {path = ["stylix" "autoEnable"];} { - path = [ "stylix" "base16Scheme" ]; + path = ["stylix" "base16Scheme"]; condition = homeConfig: config.stylix.image == homeConfig.stylix.image; } - { path = [ "stylix" "cursor" "name" ]; } - { path = [ "stylix" "cursor" "package" ]; } - { path = [ "stylix" "cursor" "size" ]; } - { path = [ "stylix" "enable" ]; } - { path = [ "stylix" "fonts" "serif" ]; } - { path = [ "stylix" "fonts" "sansSerif" ]; } - { path = [ "stylix" "fonts" "monospace" ]; } - { path = [ "stylix" "fonts" "emoji" ]; } - { path = [ "stylix" "fonts" "sizes" "desktop" ]; } - { path = [ "stylix" "fonts" "sizes" "applications" ]; } - { path = [ "stylix" "fonts" "sizes" "terminal" ]; } - { path = [ "stylix" "fonts" "sizes" "popups" ]; } - { path = [ "stylix" "image" ]; } - { path = [ "stylix" "imageScalingMode" ]; } - { path = [ "stylix" "opacity" "desktop" ]; } - { path = [ "stylix" "opacity" "applications" ]; } - { path = [ "stylix" "opacity" "terminal" ]; } - { path = [ "stylix" "opacity" "popups" ]; } + {path = ["stylix" "cursor" "name"];} + {path = ["stylix" "cursor" "package"];} + {path = ["stylix" "cursor" "size"];} + {path = ["stylix" "enable"];} + {path = ["stylix" "fonts" "serif"];} + {path = ["stylix" "fonts" "sansSerif"];} + {path = ["stylix" "fonts" "monospace"];} + {path = ["stylix" "fonts" "emoji"];} + {path = ["stylix" "fonts" "sizes" "desktop"];} + {path = ["stylix" "fonts" "sizes" "applications"];} + {path = ["stylix" "fonts" "sizes" "terminal"];} + {path = ["stylix" "fonts" "sizes" "popups"];} + {path = ["stylix" "image"];} + {path = ["stylix" "imageScalingMode"];} + {path = ["stylix" "opacity" "desktop"];} + {path = ["stylix" "opacity" "applications"];} + {path = ["stylix" "opacity" "terminal"];} + {path = ["stylix" "opacity" "popups"];} { - path = [ "stylix" "override" ]; + path = ["stylix" "override"]; condition = homeConfig: config.stylix.base16Scheme == homeConfig.stylix.base16Scheme; } - { path = [ "stylix" "polarity" ]; } + {path = ["stylix" "polarity" "force"];} + {path = ["stylix" "polarity" "primaryScale" "dark"];} + {path = ["stylix" "polarity" "primaryScale" "light"];} ]; - in { options.stylix.homeManagerIntegration = { followSystem = lib.mkOption { @@ -73,7 +83,7 @@ in { lib.optionalAttrs (options ? home-manager) (lib.mkIf config.stylix.homeManagerIntegration.autoImport { home-manager.sharedModules = - [ homeManagerModule ] ++ - (lib.optionals config.stylix.homeManagerIntegration.followSystem copyModules); + [homeManagerModule] + ++ (lib.optionals config.stylix.homeManagerIntegration.followSystem copyModules); }); } diff --git a/stylix/palette.nix b/stylix/palette.nix index 3d7befc69..76bc29af0 100644 --- a/stylix/palette.nix +++ b/stylix/palette.nix @@ -1,13 +1,20 @@ -{ palette-generator, base16 }: -{ pkgs, lib, config, ... }: - -let +{ + palette-generator, + base16, +}: { + pkgs, + lib, + config, + ... +}: let cfg = config.stylix; paletteJSON = let - generatedJSON = pkgs.runCommand "palette.json" { } '' + generatedJSON = pkgs.runCommand "palette.json" {} '' ${palette-generator}/bin/palette-generator \ - "${cfg.polarity}" \ + "${cfg.polarity.force}" \ + "${toString cfg.polarity.primaryScale.dark}" \ + "${toString cfg.polarity.primaryScale.light}" \ ${lib.escapeShellArg "${cfg.image}"} \ "$out" ''; @@ -17,21 +24,40 @@ let template = ./palette.json.mustache; extension = ".json"; }; - in json; + in + json; generatedScheme = lib.importJSON paletteJSON; - in { options.stylix = { - polarity = lib.mkOption { - type = lib.types.enum [ "either" "light" "dark" "darker" "even-darker" ]; - default = "either"; - description = '' - Use this option to force a light or dark theme. + polarity = { + force = lib.mkOption { + type = lib.types.enum ["either" "light" "dark"]; + default = "either"; + description = '' + Use this option to force a light or dark theme. + + By default we will select whichever is ranked better by the genetic + algorithm. This aims to get good contrast between the foreground and + background, as well as some variety in the highlight colours. + ''; + }; - By default we will select whichever is ranked better by the genetic - algorithm. This aims to get good contrast between the foreground and - background, as well as some variety in the highlight colours. - ''; + primaryScale = { + dark = lib.mkOption { + type = lib.types.float; + default = 1.0; + description = '' + Use this option to scale color values for the generated light theme. + ''; + }; + light = lib.mkOption { + type = lib.types.float; + default = 1.0; + description = '' + Use this option to scale color values for the generated light theme. + ''; + }; + }; }; image = lib.mkOption { @@ -45,7 +71,7 @@ in { }; imageScalingMode = lib.mkOption { - type = lib.types.enum [ "stretch" "fill" "fit" "center" "tile" ]; + type = lib.types.enum ["stretch" "fill" "fit" "center" "tile"]; default = "fill"; description = '' Wallpaper scaling mode; @@ -86,7 +112,7 @@ in { This can be a path to a file, a string of YAML, or an attribute set. ''; - type = with lib.types; oneOf [ path lines attrs ]; + type = with lib.types; oneOf [path lines attrs]; default = generatedScheme; defaultText = lib.literalMD '' The colors used in the theming. diff --git a/stylix/testbed.nix b/stylix/testbed.nix index c5b7c1aeb..19185699f 100644 --- a/stylix/testbed.nix +++ b/stylix/testbed.nix @@ -1,14 +1,17 @@ -{ pkgs, inputs, lib, ... }: - -let +{ + pkgs, + inputs, + lib, + ... +}: let username = "guest"; - commonModule = { config, ... }: { + commonModule = {config, ...}: { users.users.${username} = { description = "Guest"; hashedPassword = ""; isNormalUser = true; - extraGroups = [ "wheel" ]; + extraGroups = ["wheel"]; }; security.sudo.wheelNeedsPassword = false; @@ -25,83 +28,83 @@ let }; }; - autoload = builtins.concatLists + autoload = + builtins.concatLists (lib.mapAttrsToList - (name: _: - let testbed = { - inherit name; - module = "${inputs.self}/modules/${name}/testbed.nix"; - }; + ( + name: _: let + testbed = { + inherit name; + module = "${inputs.self}/modules/${name}/testbed.nix"; + }; in lib.optional (builtins.pathExists testbed.module) testbed ) (builtins.readDir "${inputs.self}/modules")); - makeTestbed = - testbed: stylix: - let - name = "testbed-${testbed.name}-${stylix.polarity}"; + makeTestbed = testbed: stylix: let + name = "testbed-${testbed.name}-${stylix.polarity.force}"; - system = lib.nixosSystem { - inherit (pkgs) system; + system = lib.nixosSystem { + inherit (pkgs) system; - modules = [ - commonModule - inputs.self.nixosModules.stylix - inputs.home-manager.nixosModules.home-manager - testbed.module + modules = [ + commonModule + inputs.self.nixosModules.stylix + inputs.home-manager.nixosModules.home-manager + testbed.module - { - inherit stylix; - system.name = name; - } - ]; - }; + { + inherit stylix; + system.name = name; + } + ]; + }; - script = pkgs.writeShellApplication { - inherit name; - text = '' - cleanup() { - if rm --recursive "$directory"; then - printf '%s\n' 'Virtualisation disk image removed.' - fi - } + script = pkgs.writeShellApplication { + inherit name; + text = '' + cleanup() { + if rm --recursive "$directory"; then + printf '%s\n' 'Virtualisation disk image removed.' + fi + } - # We create a temporary directory rather than a temporary file, since - # temporary files are created empty and are not valid disk images. - directory="$(mktemp --directory)" - trap cleanup EXIT + # We create a temporary directory rather than a temporary file, since + # temporary files are created empty and are not valid disk images. + directory="$(mktemp --directory)" + trap cleanup EXIT - NIX_DISK_IMAGE="$directory/nixos.qcow2" \ - ${lib.getExe system.config.system.build.vm} - ''; - }; - in - lib.nameValuePair name script; + NIX_DISK_IMAGE="$directory/nixos.qcow2" \ + ${lib.getExe system.config.system.build.vm} + ''; + }; + in + lib.nameValuePair name script; # This generates a copy of each testbed for each of the following themes. - makeTestbeds = testbed: map (makeTestbed testbed) [ - { - enable = true; - image = pkgs.fetchurl { - name = "three-bicycles.jpg"; - url = "https://unsplash.com/photos/hwLAI5lRhdM/download?ixid=M3wxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNzE2MzYxNDcwfA&force=true"; - hash = "sha256-S0MumuBGJulUekoGI2oZfUa/50Jw0ZzkqDDu1nRkFUA="; - }; - base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-latte.yaml"; - polarity = "light"; - } - { - enable = true; - image = pkgs.fetchurl { - name = "mountains.jpg"; - url = "https://unsplash.com/photos/ZqLeQDjY6fY/download?ixid=M3wxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNzE2MzY1NDY4fA&force=true"; - hash = "sha256-Dm/0nKiTFOzNtSiARnVg7zM0J1o+EuIdUQ3OAuasM58="; - }; - base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-macchiato.yaml"; - polarity = "dark"; - } - ]; - + makeTestbeds = testbed: + map (makeTestbed testbed) [ + { + enable = true; + image = pkgs.fetchurl { + name = "three-bicycles.jpg"; + url = "https://unsplash.com/photos/hwLAI5lRhdM/download?ixid=M3wxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNzE2MzYxNDcwfA&force=true"; + hash = "sha256-S0MumuBGJulUekoGI2oZfUa/50Jw0ZzkqDDu1nRkFUA="; + }; + base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-latte.yaml"; + polarity.force = "light"; + } + { + enable = true; + image = pkgs.fetchurl { + name = "mountains.jpg"; + url = "https://unsplash.com/photos/ZqLeQDjY6fY/download?ixid=M3wxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNzE2MzY1NDY4fA&force=true"; + hash = "sha256-Dm/0nKiTFOzNtSiARnVg7zM0J1o+EuIdUQ3OAuasM58="; + }; + base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-macchiato.yaml"; + polarity.force = "dark"; + } + ]; in lib.listToAttrs (lib.flatten (map makeTestbeds autoload))