A gift for Darcy 💜

This commit is contained in:
kat witch 2021-08-30 19:36:48 +01:00
parent 1581b51523
commit 9f35a4b893
No known key found for this signature in database
GPG key ID: 1B477797DCA5EC72
4 changed files with 148 additions and 96 deletions

View file

@ -8,6 +8,7 @@
(import sources.anicca).modules.home
./deploy.nix
./theme.nix
./swaylock.nix
./secrets.nix
(sources.tf-nix + "/modules/home/secrets.nix")
];

View file

@ -0,0 +1,44 @@
{ config, lib, pkgs, ... }: with lib;
let cfg = config.programs.swaylock; in
{
options.programs.swaylock = {
enable = mkEnableOption "locker integration";
package = mkOption {
type = types.package;
default = pkgs.swaylock-effects;
};
wrapped = mkOption {
type = types.package;
};
script = mkOption {
type = types.path;
default = "${cfg.wrapped}/bin/swaylock";
};
colors = mkOption {
type = types.attrsOf types.str;
default = { };
};
args = mkOption {
type = with types; attrsOf (oneOf [ str bool int float ]);
default = { };
};
};
config = mkIf cfg.enable {
programs.swaylock = let
argList = concatLists (mapAttrsToList (arg: value:
if value == true then
singleton "--${toString arg}"
else [
"--${arg}"
(toString value)
]) cfg.args);
argStr = escapeShellArgs argList;
in {
args = mapAttrs' (arg: color: nameValuePair ("${arg}-color") (removePrefix "#" color)) cfg.colors;
wrapped = pkgs.writeShellScriptBin "swaylock" ''
${cfg.package}/bin/swaylock ${argStr} $@
'';
};
};
}

View file

@ -1,8 +1,8 @@
{ config, pkgs, lib, ... }:
/*
This module:
* provides a central way to change the font my system uses.
This module:
* provides a central way to change the font my system uses.
*/
with lib;
@ -11,10 +11,21 @@ let cfg = config.kw.theme; in
{
options.kw.theme = {
enable = mkEnableOption "kat's theme module";
css_style = mkOption {
type = types.enum [ "nested" "compressed" "compact" "expanded" ];
default = "expanded";
sass = {
variables = mkOption {
type = types.attrsOf types.str;
default = (cfg.base16 // cfg.base16t // {
term_font = cfg.font.termName;
font = cfg.font.name;
font_size = cfg.font.size_css;
});
};
css_style = mkOption {
type = types.enum [ "nested" "compressed" "compact" "expanded" ];
default = "expanded";
};
};
swaylock = mkEnableOption "use swaylock module";
base16 = mkOption {
type = types.attrsOf types.str;
};
@ -42,45 +53,103 @@ let cfg = config.kw.theme; in
default = "${toString (cfg.font.size + 3)}px";
};
};
variables = mkOption {
type = types.attrsOf types.str;
default = (cfg.base16 // cfg.base16t // {
term_font = cfg.font.termName;
font = cfg.font.name;
font_size = cfg.font.size_css;
});
};
};
config = mkIf (cfg.enable) {
kw.theme = {
base16 = lib.mapAttrs' (k: v: lib.nameValuePair k "#${v.hex.rgb}")
(lib.filterAttrs (n: _: lib.hasInfix "base" n) config.lib.arc.base16.schemeForAlias.default);
(lib.filterAttrs (n: _: lib.hasInfix "base" n) config.lib.arc.base16.schemeForAlias.default);
base16t = lib.mapAttrs' (k: v: lib.nameValuePair "${k}t" "rgba(${toString v.rgb.r}, ${toString v.rgb.g}, ${toString v.rgb.b}, ${toString cfg.alpha})")
(lib.filterAttrs (n: _: lib.hasInfix "base" n) config.lib.arc.base16.schemeForAlias.default);
(lib.filterAttrs (n: _: lib.hasInfix "base" n) config.lib.arc.base16.schemeForAlias.default);
alpha = 0.7;
};
lib.kw.sassTemplate = { name, src }:
programs.swaylock = mkIf (cfg.swaylock) {
enable = true;
args = {
screenshots = true;
daemonize = true;
show-failed-attempts = true;
indicator = true;
indicator-radius = 110;
indicator-thickness = 8;
font = cfg.font.name;
font-size = cfg.font.size_css;
clock = true;
datestr = "%F";
timestr = "%T";
effect-blur = "5x2";
fade-in = 0.2;
};
colors = with cfg.base16; {
key-hl = base0C;
separator = base01;
line = base01;
line-clear = base01;
line-caps-lock = base01;
line-ver = base01;
line-wrong = base01;
ring = base00;
ring-clear = base0B;
ring-caps-lock = base09;
ring-ver = base0D;
ring-wrong = base08;
inside = base00;
inside-clear = base00;
inside-caps-lock = base00;
inside-ver = base00;
inside-wrong = base00;
text = base05;
text-clear = base05;
text-caps-lock = base05;
text-ver = base05;
text-wrong = base05;
};
};
systemd.user.services.swayidle = mkIf (cfg.swaylock) {
Unit = {
Description = "swayidle";
Documentation = [ "man:swayidle(1)" ];
PartOf = [ "graphical-session.target" ];
};
Service = {
Type = "simple";
ExecStart = let
lockCommand = config.programs.swaylock.script;
in ''
${pkgs.swayidle}/bin/swayidle -w \
timeout 300 '${lockCommand}' \
timeout 600 'swaymsg "output * dpms off"' \
resume 'swaymsg "output * dpms on"' \
before-sleep '${lockCommand}'
'';
RestartSec = 3;
Restart = "always";
};
Install = { WantedBy = [ "sway-session.target" ]; };
};
lib.kw.sassTemplate = { name, src }:
let
variables = pkgs.writeText "base-variables.sass" ''
${(concatStringsSep "\n" (mapAttrsToList(var: con: "\$${var}: ${con}") cfg.variables))}
${(concatStringsSep "\n" (mapAttrsToList(var: con: "\$${var}: ${con}") cfg.sass.variables))}
'';
source = pkgs.callPackage
({ sass, stdenv }: stdenv.mkDerivation ({
inherit name src variables;
nativeBuildInputs = lib.singleton sass;
phases = [ "buildPhase" ];
buildPhase = ''
({ sass, stdenv }: stdenv.mkDerivation {
inherit name src variables;
nativeBuildInputs = lib.singleton sass;
phases = [ "buildPhase" ];
buildPhase = ''
cat $variables $src > src-mut.sass
sass src-mut.sass $out --sourcemap=none --style=${cfg.css_style}
'';
} // cfg.variables))
{ };
sass src-mut.sass $out --sourcemap=none --style=${cfg.sass.css_style}
'';
})
{ };
in
{
inherit source;
text = builtins.readFile source;
};
_module.args = { inherit (config.lib) kw; };
};
}
_module.args = { inherit (config.lib) kw; };
};
}

View file

@ -1,49 +1,6 @@
{ config, pkgs, lib, witch, ... }:
{ config, pkgs, lib, ... }:
let
lockCommand =
let
base16 = lib.mapAttrs' (k: v: lib.nameValuePair k (lib.removePrefix "#" v)) config.kw.theme.base16;
# TODO: integrate into /config/modules/home/theme.nix
# thank you to @u1f408 💜
in
pkgs.writeShellScriptBin "fancylock" ''
${pkgs.swaylock-effects}/bin/swaylock \
--screenshots \
--indicator \
-fF \
--indicator-radius 110 \
--indicator-thickness 8 \
--font ${config.kw.theme.font.name} \
--font-size ${config.kw.theme.font.size_css} \
--clock --timestr '%H:%M:%S' --datestr '%Y-%m-%d' \
--effect-blur 5x2 \
--fade-in 0.2 \
--key-hl-color ${base16.base0C} \
--separator-color ${base16.base01} \
--line-color ${base16.base01} \
--line-clear-color ${base16.base01} \
--line-caps-lock-color ${base16.base01} \
--line-ver-color ${base16.base01} \
--line-wrong-color ${base16.base01} \
--ring-color ${base16.base00} \
--ring-clear-color ${base16.base0B} \
--ring-caps-lock-color ${base16.base09} \
--ring-ver-color ${base16.base0D} \
--ring-wrong-color ${base16.base08} \
--inside-color ${base16.base00} \
--inside-clear-color ${base16.base00} \
--inside-caps-lock-color ${base16.base00} \
--inside-ver-color ${base16.base00} \
--inside-wrong-color ${base16.base00} \
--text-color ${base16.base05} \
--text-clear-color ${base16.base05} \
--text-caps-lock-color ${base16.base05} \
--text-ver-color ${base16.base05} \
--text-wrong-color ${base16.base05} \
'';
in
{
let lockCommand = config.programs.swaylock.script; in {
home.sessionVariables = {
XDG_CURRENT_DESKTOP = "sway";
XDG_SESSION_TYPE = "wayland";
@ -54,26 +11,7 @@ in
services.i3gopher = { enable = true; };
systemd.user.services.swayidle = {
Unit = {
Description = "swayidle";
Documentation = [ "man:swayidle(1)" ];
PartOf = [ "graphical-session.target" ];
};
Service = {
Type = "simple";
ExecStart = ''
${pkgs.swayidle}/bin/swayidle -w \
timeout 300 '${lockCommand}/bin/fancylock' \
timeout 600 'swaymsg "output * dpms off"' \
resume 'swaymsg "output * dpms on"' \
before-sleep '${lockCommand}/bin/fancylock'
'';
RestartSec = 3;
Restart = "always";
};
Install = { WantedBy = [ "sway-session.target" ]; };
};
kw.theme.swaylock = true;
programs.zsh.profileExtra = ''
# If running from tty1 start sway
@ -141,7 +79,7 @@ in
modes = {
"System (l) lock, (e) logout, (s) suspend, (h) hibernate, (r) reboot, (Shift+s) shutdown" =
{
"l" = "exec ${lockCommand}/bin/fancylock, mode default";
"l" = "exec ${lockCommand}, mode default";
"e" = "exec swaymsg exit, mode default";
"s" = "exec systemctl suspend, mode default";
"h" = "exec systemctl hibernate, mode default";
@ -208,7 +146,7 @@ in
keybindings = {
"${cfg.modifier}+Return" = "exec ${cfg.terminal}";
"${cfg.modifier}+x" = "exec ${lockCommand}/bin/fancylock";
"${cfg.modifier}+x" = "exec ${lockCommand}";
# focus windows - regular
"${cfg.modifier}+Left" = "focus left";