Finish modularising config

There are still some things I want to change, but at least there aren't two systems now.
This commit is contained in:
Charlotte Van Petegem 2021-06-27 00:11:23 +02:00
parent 9f04c5d815
commit 0df4d5654f
No known key found for this signature in database
GPG key ID: 019E764B7184435A
68 changed files with 860 additions and 1441 deletions

View file

@ -0,0 +1,7 @@
{ pkgs }:
pkgs.writeShellScriptBin "color_picker" ''
color=$(${pkgs.grim}/bin/grim -t png -g "$(${pkgs.slurp}/bin/slurp -p)" - | ${pkgs.imagemagick}/bin/convert png:- -unique-colors txt:- | grep -o '#[A-F0-9]\+')
${pkgs.sway}/bin/swaymsg exec -- "echo -n '$color' | ${pkgs.wl-clipboard}/bin/wl-copy --foreground"
''

177
modules/sway/default.nix Normal file
View file

@ -0,0 +1,177 @@
{ config, lib, pkgs, ... }:
let
launcher = import ./launcher.nix { inherit pkgs; stdenv = pkgs.stdenv; };
color-picker = import ./color-picker.nix { inherit pkgs; };
screenshot = import ./screenshot.nix { inherit pkgs; };
status-configuration = import ./status-configuration.nix { inherit pkgs config; };
in
{
options.chvp.sway.enable = lib.mkOption {
default = false;
example = true;
};
config = lib.mkIf config.chvp.sway.enable {
services.dbus.packages = with pkgs; [ gnome3.dconf ];
security.pam.services.swaylock = { };
xdg.portal = {
enable = true;
gtkUsePortal = true;
extraPortals = [ pkgs.xdg-desktop-portal-gtk pkgs.xdg-desktop-portal-wlr ];
};
home-manager.users.charlotte = { pkgs, ... }: {
home.packages = with pkgs; [
color-picker
screenshot
wf-recorder
wl-clipboard
];
programs = {
mako = {
enable = true;
font = "Fira Code Normal 9";
};
zsh.loginExtra = ''
if [[ -z "$DISPLAY" ]] && [[ $(tty) = "/dev/tty1" ]]; then
exec sway
fi
'';
};
services.kanshi = {
enable = true;
profiles = {
"home-undocked" = {
outputs = [
{ criteria = "Unknown 0x2036 0x00000000"; position = "0,0"; mode = "2560x1440"; scale = 1.0; }
];
};
"home-docked" = {
outputs = [
{ criteria = "Unknown 0x2036 0x00000000"; position = "0,0"; mode = "2560x1440"; scale = 1.0; }
{ criteria = "Dell Inc. DELL U2718Q FN84K01T095L"; position = "2560,0"; mode = "3840x2160"; scale = 1.0; }
];
};
"work-undocked" = {
outputs = [
{ criteria = "Chimei Innolux Corporation 0x14D3 0x00000000"; position = "0,0"; mode = "1920x1080"; scale = 1.0; }
];
};
"work-docked" = {
outputs = [
{ criteria = "Chimei Innolux Corporation 0x14D3 0x00000000"; position = "0,0"; mode = "1920x1080"; scale = 1.0; }
{ criteria = "Dell Inc. DELL U2718Q FN84K83Q1KHL"; position = "1920,0"; mode = "3840x2160"; scale = 1.0; }
];
};
};
};
wayland.windowManager.sway = {
enable = true;
config = rec {
modifier = "Mod4";
left = "h";
down = "j";
up = "k";
right = "l";
terminal = "${pkgs.kitty}/bin/kitty";
menu = "${terminal} --class launcher -e ${launcher}/bin/launcher";
fonts = { names = [ "Fira Code" ]; size = 9.0; style = "Normal"; };
bars = [
{
colors = {
background = "#ffffff";
statusline = "#000000";
activeWorkspace = { border = "#f2eff3"; background = "#f2eff3"; text = "#000000"; };
focusedWorkspace = { border = "#6aaeff"; background = "#6aaeff"; text = "#000000"; };
inactiveWorkspace = { border = "#ffffff"; background = "#ffffff"; text = "#000000"; };
urgentWorkspace = { border = "#ff8892"; background = "#ff8892"; text = "#000000"; };
};
fonts = { names = [ "Fira Code" ]; size = 9.0; style = "Normal"; };
position = "top";
statusCommand = "${pkgs.i3status-rust}/bin/i3status-rs ${status-configuration}";
extraConfig = ''
status_padding 0
icon_theme Arc
'';
}
];
output = {
"Unknown 0x2036 0x00000000" = { position = "0,0"; mode = "2560x1440"; scale = "1.0"; };
"Dell Inc. DELL U2718Q FN84K01T095L" = { position = "2560,0"; mode = "3840x2160"; scale = "1.0"; };
"Chimei Innolux Corporation 0x14D3 0x00000000" = { position = "0,0"; mode = "1920x1080"; scale = "1.0"; };
"Dell Inc. DELL U2718Q FN84K83Q1KHL" = { position = "1920,0"; mode = "3840x2160"; scale = "1.0"; };
};
startup = [
{
command = "${pkgs.swayidle}/bin/swayidle -w timeout 300 '${pkgs.swaylock}/bin/swaylock -f -c 000000' timeout 150 '${pkgs.sway}/bin/swaymsg \"output * dpms off\"' resume '${pkgs.sway}/bin/swaymsg \"output * dpms on\"' before-sleep '${pkgs.swaylock}/bin/swaylock -f -c 000000'";
}
];
window.commands = [
{ command = "floating enable"; criteria = { app_id = "launcher"; }; }
{ command = "floating enable"; criteria = { title = "Quick Format Citation"; class = "Zotero"; }; }
];
input = {
"type:keyboard" = { xkb_layout = "us"; xkb_variant = "altgr-intl"; xkb_numlock = "enabled"; xkb_options = "compose:caps"; };
"type:touchpad" = { drag = "enabled"; dwt = "enabled"; scroll_method = "two_finger"; tap = "enabled"; };
};
modes = { }; # Unset default "resize" mode
keybindings = lib.mkOptionDefault {
"${modifier}+Shift+q" = "nop Unset default kill";
"${modifier}+r" = "nop Unset default resize mode";
"${modifier}+Shift+c" = "kill";
"${modifier}+Shift+r" = "reload";
"${modifier}+c" = "exec ${pkgs.swaylock}/bin/swaylock -f -c 000000";
"${modifier}+i" = "inhibit_idle open; border normal; mark --add inhibiting_idle";
"${modifier}+Shift+i" = "inhibit_idle none; border pixel; unmark inhibiting_idle";
"Print" = "exec ${screenshot}/bin/screenshot";
"Alt+Print" = "exec ${screenshot}/bin/screenshot -d";
"Shift+Print" = "exec ${screenshot}/bin/screenshot -r";
"Alt+Shift+Print" = "exec ${screenshot}/bin/screenshot -r -d";
"XF86AudioRaiseVolume" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ +5%";
"XF86AudioLowerVolume" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ -5%";
"XF86AudioMute" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-mute @DEFAULT_SINK@ toggle";
"XF86AudioMicMute" = "exec ${pkgs.pulseaudio}/bin/pactl set-source-mute @DEFAULT_SOURCE@ toggle";
"XF86MonBrightnessDown" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set 5%-";
"XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set +5%";
"${modifier}+Alt+Left" = "move workspace to output left";
"${modifier}+Alt+Right" = "move workspace to output right";
};
};
extraConfig = ''
workspace 1 output eDP-1
workspace 2 output DP-3 DP-4 DP-5 HDMI-A-1 eDP-1
workspace 3 output DP-3 DP-4 DP-5 HDMI-A-1 eDP-1
workspace 4 output DP-3 DP-4 DP-5 HDMI-A-1 eDP-1
workspace 5 output DP-3 DP-4 DP-5 HDMI-A-1 eDP-1
workspace 6 output DP-3 DP-4 DP-5 HDMI-A-1 eDP-1
workspace 7 output DP-3 DP-4 DP-5 HDMI-A-1 eDP-1
workspace 8 output DP-3 DP-4 DP-5 HDMI-A-1 eDP-1
workspace 9 output DP-3 DP-4 DP-5 HDMI-A-1 eDP-1
workspace 1
exec ${pkgs.firefox}/bin/firefox
no_focus [title="Microsoft Teams Notification"]
default_border pixel
'';
extraSessionCommands = ''
export XDG_SESSION_TYPE=wayland
export XDG_CURRENT_DESKTOP=sway
export QT_WAYLAND_DISABLE_WINDOWDECORATION=1
export QT_AUTO_SCREEN_SCALE_FACTOR=0
export QT_SCALE_FACTOR=1
export GDK_SCALE=1
export GDK_DPI_SCALE=1
export MOZ_ENABLE_WAYLAND=1
export _JAVA_AWT_WM_NONREPARENTING=1
'';
wrapperFeatures = {
base = true;
gtk = true;
};
xwayland = true;
};
};
};
}

52
modules/sway/launcher.nix Normal file
View file

@ -0,0 +1,52 @@
{ pkgs, stdenv }:
let
gemoji = pkgs.buildRubyGem {
pname = "gemoji";
gemName = "gemoji";
source.sha256 = "1xv38sxql1fmaxi5lzj6v98l2aqhi6bqkhi6kqd0k38vw40l3yqc";
type = "gem";
version = "4.0.0.rc2";
};
emojiList = stdenv.mkDerivation {
name = "emoji_list";
buildInputs = [ pkgs.ruby gemoji ];
unpackPhase = "true";
buildPhase = ''
cat > extract_emoji.rb <<HERE
require 'emoji'
File.open('emoji_list.txt', 'w') do |f|
Emoji.all.each do |e|
f.puts("#{e.raw} #{e.description} #{e.name}#{(" " + e.tags.join(" ")) if e.tags.any?} (#{e.category})")
end
end
HERE
ruby extract_emoji.rb
'';
installPhase = ''
cp emoji_list.txt $out
'';
};
script = pkgs.substituteAll {
src = ./launcher.zsh;
inherit (pkgs)
fzy
jq
kitty
libqalculate
pass
slurp
sway
tmuxinator
zsh
;
inherit emojiList;
wfRecorder = pkgs.wf-recorder;
wlClipboard = pkgs.wl-clipboard;
xdgUserDirs = pkgs.xdg-user-dirs;
};
in
pkgs.runCommandNoCC "launcher" { } ''
mkdir -p $out/bin
cp ${script} $out/bin/launcher
chmod +x $out/bin/launcher
''

124
modules/sway/launcher.zsh Normal file
View file

@ -0,0 +1,124 @@
#!@zsh@/bin/zsh
_sighandler() {
kill -INT "$child" 2>/dev/null
}
calc_options() {
echo "calc "
}
calc() {
if [ -n "$1" ]
then
@libqalculate@/bin/qalc "$1"
sleep 5
else
@libqalculate@/bin/qalc
fi
}
emoji_options() {
cat @emojiList@ | sed "s/^/emoji /"
}
emoji() {
char=$(echo -n "$1" | sed "s/^\([^ ]*\) .*/\1/")
@sway@/bin/swaymsg exec -- "echo -n $char | @wlClipboard@/bin/wl-copy --foreground"
}
pass_options(){
prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg )
printf 'password %s\n' ${${password_files%.gpg}#$prefix/}
printf 'username %s\n' ${${password_files%.gpg}#$prefix/}
printf 'otp %s\n' ${${password_files%.gpg}#$prefix/}
}
username() {
swaymsg exec -- "@pass@/bin/pass show '$@' | sed -n 's/^Username: *//p' | tr -d '\n' | @wlClipboard@/bin/wl-copy --foreground"
}
password() {
swaymsg exec -- "@pass@/bin/pass show -c0 '$@'"
}
otp() {
swaymsg exec -- "@pass@/bin/pass otp -c '$@'"
}
record_options() {
@sway@/bin/swaymsg -t get_outputs | @jq@/bin/jq -r '.[]["name"]' | sed "s/^/record /"
echo record select
}
record() {
filename="$(@xdgUserDirs@/bin/xdg-user-dir VIDEOS)/$(date +'screenrecording_%y-%m-%d-%H%M%S.mp4')"
trap _sighandler SIGINT
if [[ "$1" = "select" ]]
then
@wfRecorder@/bin/wf-recorder -g "$(@slurp@/bin/slurp)" -f "$filename" &
else
@wfRecorder@/bin/wf-recorder -o $! -f "$filename" &
fi
child=$!
wait "$child"
# We wait two times, because the first wait exits when the process receives a signal. The process might have finished though, so we ignore errors.
wait "$child" 2>/dev/null
if [ -f "$filename" ]
then
echo "Saved as $filename"
else
echo "Something went wrong while recording"
fi
sleep 5
}
run_options() {
print -rl -- ''${(ko)commands} | sed "s/^/run /"
}
run() {
@sway@/bin/swaymsg exec $1
}
ssh_options() {
cat $HOME/.ssh/config | grep "^Host [a-zA-Z]\+" | sed "s/Host /ssh /"
}
ssh() {
@sway@/bin/swaymsg exec "@kitty@/bin/kitty -e ssh $1"
}
systemctl_options() {
echo systemctl hibernate
echo systemctl poweroff
echo systemctl reboot
echo systemctl suspend
}
tmuxinator_options() {
ls ~/.config/tmuxinator | sed "s/\.yml$//" | sed "s/^/tmuxinator /"
}
tmuxinator() {
@sway@/bin/swaymsg exec "@kitty@/bin/kitty -e @tmuxinator@/bin/tmuxinator start $1"
}
windows_options() {
@sway@/bin/swaymsg -t get_tree | @jq@/bin/jq -r 'recurse(.nodes[]?)|recurse(.floating_nodes[]?)|select(.layout=="none")|select(.app_id!="launcher")|select(.type=="con"),select(.type=="floating_con")|(if .app_id then .app_id else .window_properties.class end)+": "+.name+" ("+(.id|tostring)+")"' | sed "s/^/windows /"
}
windows() {
window=$(echo $@ | sed 's/.* (\([^)]*\))$/\1/')
@sway@/bin/swaymsg \[con_id="$window"\] focus
}
CHOSEN=$(cat <(windows_options) <(tmuxinator_options) <(ssh_options) <(systemctl_options) <(pass_options) <(run_options) <(record_options) <(calc_options) <(emoji_options) | @fzy@/bin/fzy --lines 36 | tail -n1)
if [ -n "$CHOSEN" ]
then
PREFIX=$(echo $CHOSEN | sed "s/^\([^ ]*\) .*/\1/g")
WORD=$(echo $CHOSEN | sed "s/^[^ ]* \(.*\)/\1/g")
$PREFIX $WORD
fi

View file

@ -0,0 +1,36 @@
{ pkgs }:
pkgs.writeShellScriptBin "screenshot" ''
while getopts ":rd" opt
do
case "''${opt}" in
r)
remote=true
;;
d)
delay=true
;;
esac
done
dims="$(${pkgs.slurp}/bin/slurp)"
if [[ -n "$delay" ]]
then
sleep 5
fi
if [[ -n "$remote" ]]
then
name=$(${pkgs.utillinux}/bin/uuidgen).png
${pkgs.grim}/bin/grim -t png -g "$dims" - | ${pkgs.openssh}/bin/ssh data "cat > data/public/$name"
path="https://data.vanpetegem.me/public/$name"
else
name=$(date +'screenshot_%Y-%m-%d-%H%M%S.png')
path="$(${pkgs.xdg-user-dirs}/bin/xdg-user-dir PICTURES)/$name"
${pkgs.grim}/bin/grim -g "$dims" "$path"
fi
${pkgs.sway}/bin/swaymsg exec -- "echo -n '$path' | ${pkgs.wl-clipboard}/bin/wl-copy --foreground"
${pkgs.libnotify}/bin/notify-send "Screenshot taken" "$path"
''

View file

@ -0,0 +1,94 @@
{ config, pkgs, ... }:
let
mic-status = pkgs.writeShellScript "mic-status" ''
if [ "$(${pkgs.pulseaudio}/bin/pactl list sources | grep -o 'Mute: yes')" = "Mute: yes" ]
then
echo -e '\uf131'
else
echo -e '\uf130'
fi
'';
mail-status = pkgs.writeShellScript "mail-status" ''
mails=$(${pkgs.mblaze}/bin/mlist -N ~/mail/*/INBOX | wc -l)
if [ "$mails" -gt 0 ]
then
echo "{ \"state\": \"Info\", \"text\": \" 📬 $mails\" }"
else
echo "{ \"state\": \"Idle\", \"text\": \" 📭 $mails\" }"
fi
'';
in
pkgs.writeText "configuration.toml" ''
[theme]
name = "gruvbox-light"
[theme.overrides]
idle_bg="#ffffff"
idle_fg="#000000"
info_bg="#6aaeff"
info_fg="#000000"
good_bg="#5ada88"
good_fg="#000000"
warning_bg="#f5df23"
warning_fg="#000000"
critical_bg="#ff8892"
critical_fg="#000000"
separator=""
[icons]
name = "awesome"
[[block]]
block = "net"
device = "wlp2s0"
format = "{ssid}"
hide_missing = true
hide_inactive = true
[[block]]
block = "net"
device = "wlp0s20f3"
format = "{ssid}"
hide_missing = true
hide_inactive = true
[[block]]
block = "net"
device = "enp0s31f6"
format = "{ip}"
hide_missing = true
hide_inactive = true
[[block]]
block = "net"
device = "enp0s20f0u1u2"
format = "{ip}"
hide_missing = true
hide_inactive = true
[[block]]
block = "battery"
[[block]]
block = "backlight"
[[block]]
block = "sound"
[[block]]
block = "custom"
command = "${mic-status}"
interval = 1
on_click = "${pkgs.pulseaudio}/bin/pactl set-source-mute @DEFAULT_SOURCE@ toggle"
[[block]]
block = "custom"
json = true
command = "${mail-status}"
interval = 1
on_click = "${pkgs.isync}/bin/mbsync -a && ${config.chvp.emacs.package}/bin/emacsclient --eval \"(mu4e-update-index)\""
[[block]]
block = "time"
interval = 1
format = "%a %d/%m %H:%M"
''