[user/malte,module/base-system] Initial dark/light-mode

This commit is contained in:
Malte Tammena 2022-05-08 21:41:26 +02:00
parent 78795db8a0
commit 3171f6ab6f
11 changed files with 306 additions and 63 deletions

View file

@ -21,6 +21,7 @@ in {
./scanner.nix
./taskserver.nix
./wakeup.nix
./darkman.nix
];
options.settings = with lib; {

16
modules/darkman.nix Normal file
View file

@ -0,0 +1,16 @@
{
pkgs,
lib,
config,
...
}: let
cfg = config.services.darkman;
in {
options.services.darkman.enable = lib.mkEnableOption "darkman, the light/dark mode switcher";
config = lib.mkIf cfg.enable {
services.dbus.packages = [pkgs.darkman];
systemd.packages = [pkgs.darkman];
environment.systemPackages = [pkgs.darkman];
};
}

View file

@ -34,6 +34,7 @@ in {
home-manager.users.malte.imports = [../users/malte/home.nix];
programs.fish.enable = true;
services.darkman.enable = true;
sops.secrets = let
sopsFile = ../secrets/users/malte/secrets.yaml;

View file

@ -9,35 +9,36 @@
rev = "c2656986c24a7118146b92958c1063d195513c2f";
sha256 = "5DXfUmE58W+5aHmMqLJYLjFoUUFhrUEP9Vz5CXmyT2s=";
vendorSha256 = "CGgWEaHztWeCQPIrobwLHuDkFauJM19hBU7JsA3HMic=";
in buildGoModule {
pname = name;
version = rev;
in
buildGoModule {
pname = name;
version = rev;
src = fetchFromGitLab {
inherit sha256 rev;
owner = "WhyNotHugo";
repo = name;
};
src = fetchFromGitLab {
inherit sha256 rev;
owner = "WhyNotHugo";
repo = name;
};
nativeBuildInputs = [ scdoc ];
propagatedBuildInputs = [ geoclue2 ];
nativeBuildInputs = [scdoc];
propagatedBuildInputs = [geoclue2];
inherit vendorSha256;
inherit vendorSha256;
postBuild = ''
make build
#cp $GOPATH/bin/darkman .
'';
postBuild = ''
make build
#cp $GOPATH/bin/darkman .
'';
installPhase = ''
mkdir -p $out
make install DESTDIR=$out
'';
installPhase = ''
mkdir -p $out
make install PREFIX=/ DESTDIR=$out
'';
meta = {
description = "🌇 Framework for dark-mode and light-mode transitions on Linux desktop";
homepage = "https://gitlab.com/WhyNotHugo/darkman";
license = lib.licenses.isc;
maintainers = [];
};
}
meta = {
description = "🌇 Framework for dark-mode and light-mode transitions on Linux desktop";
homepage = "https://gitlab.com/WhyNotHugo/darkman";
license = lib.licenses.isc;
maintainers = [];
};
}

View file

@ -50,4 +50,15 @@ in rec {
cursor-theme = gtk.gtk3.extraConfig.gtk-cursor-theme-name;
};
};
services.darkman."gtk.sh" = {
onLight = ''
#!${pkgs.runtimeShell}
${pkgs.dconf}/bin/dconf write /org/gnome/desktop/interface/gtk-theme "'Adwaita'"
'';
onDark = ''
#!${pkgs.runtimeShell}
${pkgs.dconf}/bin/dconf write /org/gnome/desktop/interface/gtk-theme "'Gruvbox-Material-Dark'"
'';
};
}

View file

@ -60,6 +60,7 @@ in {
../modules/synchronize-calendars.nix
../modules/persway.nix
../modules/protonmail-bridge.nix
../modules/darkman.nix
];
config = {

View file

@ -5,6 +5,8 @@
...
}: let
col = config.colors;
kakBin = "${pkgs.kakoune}/bin/kak";
configDir = "~/.config/kak";
# Configuration for kakoune plugins
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
@ -123,21 +125,13 @@
# Additional configuration for kakoune
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
additionalConfig = let
fg62 = col.fg.rgbWithAlpha 0.62;
bg1 = col.dark1.rgb;
in ''
additionalConfig = ''
add-highlighter global/ number-lines -relative
add-highlighter global/ wrap -word -indent
add-highlighter global/ regex '\h*(//|#|;|%)\h*(TODO:|FIXME:)([^\n]*)' 2:black,bright-red+Fb 3:default+b
# Highlighter for headers in the nix config
add-highlighter global/ regex '^\h*#\h*([^\n]+)\n\h*#\h*(‾+)$' 1:bright-yellow+bf 2:yellow+bf
face global PrimarySelection rgba:${fg62},rgba:8ec07c40
face global SecondarySelection rgba:${fg62},rgba:83a59840
face global MatchingChar rgb:${col.fg.rgb},rgb:${bg1}+bf
face global Reference rgb:${bg1}
# Do something about tabs..
map global insert <tab> ' '
hook global BufSetOption filetype=nix %{
@ -145,6 +139,10 @@
}
set-option global tabstop 4
# Disable info boxes
set-option global autoinfo onkey
set-option global startup_info_version 20211107
# Toggle whitespaces!
declare-option -docstring "Whether whitespaces are visible" bool whitespacesshown
define-command -docstring "Toggle whitespace highlighter" togglewhitespace %{
@ -158,8 +156,38 @@
fi
}
}
# Initialize theme
source ${currentThemeFile}
'';
# Light/Dark mode
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
lightModeConfig = let
bg62 = col.bg.rgbWithAlpha 0.62;
fg2 = col.light2.rgb;
in ''
colorscheme gruvbox-light
face global PrimarySelection rgba:${bg62},rgba:8ec07c40
face global SecondarySelection rgba:${bg62},rgba:83a59840
face global MatchingChar rgb:${col.bg.rgb},rgb:${fg2}+bf
face global Reference rgb:${fg2}
'';
darkModeConfig = let
fg62 = col.fg.rgbWithAlpha 0.62;
bg1 = col.dark1.rgb;
in ''
colorscheme gruvbox-dark
face global PrimarySelection rgba:${fg62},rgba:8ec07c40
face global SecondarySelection rgba:${fg62},rgba:83a59840
face global MatchingChar rgb:${col.fg.rgb},rgb:${bg1}+bf
face global Reference rgb:${bg1}
'';
linkTheme = theme: ''
ln -sf ~/${config.xdg.configFile."kak/${theme}".target} ${currentThemeFile}
'';
currentThemeFile = "${configDir}/theme";
# Configuration for kakoune LSP
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
kakLspConfigGen = pkgs.formats.toml {};
@ -288,9 +316,8 @@ in {
enable = true;
config = {
colorScheme = "gruvbox-dark";
ui.enableMouse = true;
ui.assistant = "dilbert";
ui.assistant = "none";
showMatching = true;
hooks = selectList "hooks";
@ -304,9 +331,46 @@ in {
};
home.sessionVariables = {
EDITOR = "${pkgs.kakoune}/bin/kak";
VISUAL = "${pkgs.kitty}/bin/kitty ${pkgs.kakoune}/bin/kak";
EDITOR = kakBin;
VISUAL = "${pkgs.kitty}/bin/kitty ${kakBin}";
};
xdg.configFile."kak-lsp/kak-lsp.toml".source = kakLspConfigGen.generate "kak-lsp.toml" kakLspConfig;
xdg.configFile."kak/light-moderc".text = lightModeConfig;
xdg.configFile."kak/dark-moderc".text = darkModeConfig;
services.darkman."kakoune.sh" = {
onLight = ''
#!${pkgs.runtimeShell}
for id in $(${kakBin} -l); do
echo 'source ~/${config.xdg.configFile."kak/light-moderc".target}' | ${kakBin} -p $id
done
${linkTheme "light-moderc"}
'';
onDark = ''
#!${pkgs.runtimeShell}
for id in $(${kakBin} -l); do
echo 'source ~/${config.xdg.configFile."kak/dark-moderc".target}' | ${kakBin} -p $id
done
${linkTheme "dark-moderc"}
'';
};
home.activation.initializeKakouneTheme = lib.hm.dag.entryAfter ["writeBoundary"] ''
$VERBOSE_ECHO "initializing kakoune theme"
if [[ -v DRY_RUN ]]; then
# Create the folder
$DRY_RUN_CMD mkdir -p ${configDir}
if [[ ! -e ${configDir}/${currentThemeFile} ]]; then
$DRY_RUN_CMD ${linkTheme "dark-moderc"}
fi
else
# Create the folder
mkdir -p ${configDir}
if [[ ! -e ${configDir}/${currentThemeFile} ]]; then
${linkTheme "dark-moderc"}
fi
fi
'';
}

View file

@ -1,9 +1,15 @@
{
pkgs,
lib,
config,
...
}: let
darkTheme = "Gruvbox Dark";
lightTheme = "Gruvbox Light";
col = config.colors;
configDir = "~/.config/kitty";
themeConfigFile = "theme.conf";
genKittyTheme = theme: "${pkgs.kitty}/bin/kitty +kitten themes --reload-in=all --config-file-name=${themeConfigFile} '${theme}'";
in {
programs.kitty = {
enable = true;
@ -22,26 +28,59 @@ in {
allow_remote_control = "yes";
# https://github.com/gruvbox-community/gruvbox-contrib/blob/master/kitty/gruvbox-dark.conf
background = col.bg.hashRgb;
foreground = col.fg.hashRgb;
cursor = col.fg.hashRgb;
url_color = col.brightBlue.hashRgb;
color0 = col.bg.hashRgb;
color1 = col.neutralRed.hashRgb;
color2 = col.neutralGreen.hashRgb;
color3 = col.neutralYellow.hashRgb;
color4 = col.neutralBlue.hashRgb;
color5 = col.neutralPurple.hashRgb;
color6 = col.neutralAqua.hashRgb;
color7 = col.light4.hashRgb;
color8 = col.light4.hashRgb;
color9 = col.brightRed.hashRgb;
color10 = col.brightGreen.hashRgb;
color11 = col.brightYellow.hashRgb;
color12 = col.brightBlue.hashRgb;
color13 = col.brightPurple.hashRgb;
color14 = col.brightAqua.hashRgb;
color15 = col.light1.hashRgb;
# background = col.bg.hashRgb;
# foreground = col.fg.hashRgb;
# cursor = col.fg.hashRgb;
# url_color = col.brightBlue.hashRgb;
# color0 = col.bg.hashRgb;
# color1 = col.neutralRed.hashRgb;
# color2 = col.neutralGreen.hashRgb;
# color3 = col.neutralYellow.hashRgb;
# color4 = col.neutralBlue.hashRgb;
# color5 = col.neutralPurple.hashRgb;
# color6 = col.neutralAqua.hashRgb;
# color7 = col.light4.hashRgb;
# color8 = col.light4.hashRgb;
# color9 = col.brightRed.hashRgb;
# color10 = col.brightGreen.hashRgb;
# color11 = col.brightYellow.hashRgb;
# color12 = col.brightBlue.hashRgb;
# color13 = col.brightPurple.hashRgb;
# color14 = col.brightAqua.hashRgb;
# color15 = col.light1.hashRgb;
};
extraConfig = ''
include ${themeConfigFile}
'';
};
home.activation.initializeKittyTheme = lib.hm.dag.entryAfter ["writeBoundary"] ''
$VERBOSE_ECHO "initializing kitty theme"
if [[ -v DRY_RUN ]]; then
# Create the folder
$DRY_RUN_CMD mkdir -p ${configDir}
if [[ ! -e ${configDir}/${themeConfigFile} ]]; then
$DRY_RUN_CMD ${genKittyTheme darkTheme}
fi
else
# Create the folder
mkdir -p ${configDir}
if [[ ! -e ${configDir}/${themeConfigFile} ]]; then
${genKittyTheme darkTheme}
fi
fi
'';
services.darkman."kitty.sh" = {
onLight = ''
#!${pkgs.runtimeShell}
${genKittyTheme lightTheme}
'';
onDark = ''
#!${pkgs.runtimeShell}
${genKittyTheme darkTheme}
'';
};
}

View file

@ -1,4 +1,14 @@
{pkgs, ...}: {
{
pkgs,
lib,
...
}: let
batConfigDir = "~/.config/bat";
batConfig = "${batConfigDir}/config";
setBatTheme = theme: ''
echo '--theme=${theme}' > ${batConfig}
'';
in {
home.packages = with pkgs; [
(pkgs.callPackage ../../pkgs/rip.nix {})
bottom
@ -154,11 +164,39 @@
programs.bat = {
enable = true;
config = {theme = "gruvbox-dark";};
};
programs.nix-index = {
enable = true;
enableFishIntegration = true;
};
home.activation.initializeBatTheme = lib.hm.dag.entryAfter ["writeBoundary"] ''
$VERBOSE_ECHO "initializing bat theme"
if [[ -v DRY_RUN ]]; then
# Create the folder
$DRY_RUN_CMD mkdir -p ${batConfigDir}
if [[ ! -e ${batConfig} ]]; then
$DRY_RUN_CMD ${setBatTheme "gruvbox-dark"}
fi
else
# Create the folder
mkdir -p ${batConfigDir}
if [[ ! -e ${batConfig} ]]; then
${setBatTheme "gruvbox-dark"}
fi
fi
'';
services.darkman."bat.sh" = {
onLight = ''
#!${pkgs.runtimeShell}
${setBatTheme "gruvbox-light"}
'';
onDark = ''
#!${pkgs.runtimeShell}
${setBatTheme "gruvbox-dark"}
'';
};
}

View file

@ -227,11 +227,11 @@ in {
};
gaps = let
size = 3;
size = 4;
in {
smartBorders = "on";
smartGaps = true;
#inner = size;
inner = size;
#outer = size;
};
@ -398,5 +398,30 @@ in {
systemd-cat -t sway sway
end
'';
darkman."sway.sh" = let
swayBin = "${pkgs.sway}/bin/sway";
fadedAqua = col.fadedAqua.hashRgb;
primary = col.primary.hashRgb;
d0 = col.dark0.hashRgb;
d0Darker = (col.dark0.darker 0.4).hashRgb;
in {
onLight = ''
#!${pkgs.runtimeShell}
${swayBin} "
client.focused ${fadedAqua} ${fadedAqua} ${d0} ${fadedAqua} ${fadedAqua}
client.unfocused ${d0} ${d0} ${fadedAqua} ${d0} ${d0}
client.focused_inactive ${d0} ${d0} ${fadedAqua} ${d0} ${d0}
"
'';
onDark = ''
#!${pkgs.runtimeShell}
${swayBin} "
client.focused ${primary} ${primary} ${d0Darker} ${primary} ${primary}
client.unfocused ${d0Darker} ${d0Darker} ${primary} ${d0Darker} ${d0Darker}
client.focused_inactive ${d0Darker} ${d0Darker} ${primary} ${d0Darker} ${d0Darker}
"
'';
};
};
}

46
users/modules/darkman.nix Normal file
View file

@ -0,0 +1,46 @@
{
pkgs,
lib,
config,
...
}: let
cfg = config.services.darkman;
mkScript = text: {
inherit text;
executable = true;
};
mkLightPath = path: "light-mode.d/${path}";
mkDarkPath = path: "dark-mode.d/${path}";
in {
options.services.darkman = with lib;
mkOption {
description = "Darkman scripts";
type = with types;
attrsOf (uniq (submodule {
options = {
onLight = mkOption {
description = "Script to execute when lightmode is activated";
type = lines;
};
onDark = mkOption {
description = "Script to execute when darkmode is activated";
type = lines;
};
};
}));
};
config.xdg.dataFile =
(lib.attrsets.mapAttrs' (key: conf: {
name = mkLightPath key;
value = mkScript conf.onLight;
})
cfg)
// (lib.attrsets.mapAttrs' (key: conf: {
name = mkDarkPath key;
value = mkScript conf.onDark;
})
cfg);
}