Distuingish between configurations and program modifications

This commit is contained in:
Charlotte Van Petegem 2020-05-03 17:40:09 +02:00
parent 964b294300
commit 1afb00a3de
27 changed files with 48 additions and 44 deletions

View file

@ -0,0 +1,9 @@
{ pkgs }:
pkgs.writeScriptBin "color_picker" ''
#!${pkgs.zsh}/bin/zsh
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"
''

View file

@ -0,0 +1,290 @@
with import <nixpkgs> { };
{ pkgs, ... }:
let
firefox = import ../../programs/firefox/default.nix { inherit pkgs; };
launcher = import ./launcher.nix { inherit pkgs stdenv; };
color-picker = import ./color-picker.nix { inherit pkgs; };
screenshot = import ./screenshot.nix { inherit pkgs; };
status-configuration = import ./status-configuration.nix { inherit pkgs; };
in
{
imports = [
./kanshi.nix
];
programs = {
sway = {
enable = true;
extraPackages = [ pkgs.xwayland ];
extraSessionCommands = ''
export XDG_SESSION_TYPE=wayland
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
'';
};
};
home-manager.users.charlotte = { pkgs, ... }: {
home.packages = [ color-picker launcher screenshot ];
xdg.configFile."sway/config".text = ''
# Config for sway
#
# Read `man 5 sway` for a complete reference.
### Variables
#
# Logo key. Use Mod1 for Alt.
set $mod Mod4
# Home row direction keys, like vim
set $left h
set $down j
set $up k
set $right l
# Your preferred terminal emulator
set $term ${pkgs.kitty}/bin/kitty
# Your preferred application launcher
# Note: it's recommended that you pass the final command to sway
set $menu $term --class launcher -e ${launcher}/bin/launcher
### Output configuration
exec_always pkill kanshi; exec ${pkgs.kanshi}/bin/kanshi
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 10 output DP-3 DP-4 DP-5 HDMI-A-1 eDP-1
### Idle configuration
#
# This will lock your screen after 300 seconds of inactivity, turn off
# your displays after another 150 seconds, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.
exec ${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'
### Notification daemon
#
exec ${pkgs.mako}/bin/mako
# User services bound to the graphical session
exec "${pkgs.systemd}/bin/systemctl --user import-environment; ${pkgs.systemd}/bin/systemctl --user start graphical-session.target"
### Window rules
# Launcher popup
for_window [app_id="launcher"] floating enable
# Start accentor as floating window
for_window [class="accentor.Main"] floating enable
### Startup programs
#
workspace 1
exec ${firefox}/bin/firefox
workspace 3
exec ${pkgs.thunderbird}/bin/thunderbird
workspace 4
exec ${pkgs.joplin-desktop}/bin/joplin-desktop
workspace 6
exec ${pkgs.teams}/bin/teams
workspace 2
### Input configuration
#
# Example configuration:
#
# input "2:14:SynPS/2_Synaptics_TouchPad" {
# dwt enabled
# tap enabled
# natural_scroll enabled
# middle_emulation enabled
# }
#
# You can get the names of your inputs by running: swaymsg -t get_inputs
# Read `man 5 sway-input` for more information about this section.
input type:keyboard {
xkb_layout "us"
xkb_variant "altgr-intl"
xkb_numlock enabled
}
input type:touchpad {
drag enabled
dwt enabled
scroll_method two_finger
tap enabled
}
### Key bindings
#
# Basics:
#
# start a terminal
bindsym $mod+Return exec $term
# kill focused window
bindsym $mod+Shift+c kill
# start your launcher
bindsym $mod+d exec $menu
# Drag floating windows by holding down $mod and left mouse button.
# Resize them with right mouse button + $mod.
# Despite the name, also works for non-floating windows.
# Change normal to inverse to use left mouse button for resizing and right
# mouse button for dragging.
floating_modifier $mod normal
# reload the configuration file
bindsym $mod+Shift+r reload
# exit sway (logs you out of your Wayland session)
bindsym $mod+Shift+e exec ${pkgs.sway}/bin/swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' '${pkgs.sway}/bin/swaymsg exit'
# lock screen
bindsym $mod+c exec ${pkgs.swaylock}/bin/swaylock -f -c 000000
# toggle the current view inhibiting idle
bindsym $mod+i inhibit_idle open; border normal; mark --add inhibiting_idle
bindsym $mod+Shift+i inhibit_idle none; border pixel; unmark inhibiting_idle
# screenshot
bindsym Print exec ${screenshot}/bin/screenshot
bindsym Alt+Print exec ${screenshot}/bin/screenshot -d
bindsym Shift+Print exec ${screenshot}/bin/screenshot -r
bindsym Alt+Shift+Print exec ${screenshot}/bin/screenshot -r -d
# audio
bindsym XF86AudioRaiseVolume exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym XF86AudioMute exec ${pkgs.pulseaudio}/bin/pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioMicMute exec ${pkgs.pulseaudio}/bin/pactl set-source-mute @DEFAULT_SOURCE@ toggle
# brightness
bindsym XF86MonBrightnessDown exec ${pkgs.brightnessctl}/bin/brightnessctl set 5%-
bindsym XF86MonBrightnessUp exec ${pkgs.brightnessctl}/bin/brightnessctl set +5%
#
# Moving around:
#
# Move your focus around
bindsym $mod+$left focus left
bindsym $mod+$down focus down
bindsym $mod+$up focus up
bindsym $mod+$right focus right
# or use $mod+[up|down|left|right]
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
# _move_ the focused window with the same, but add Shift
bindsym $mod+Shift+$left move left
bindsym $mod+Shift+$down move down
bindsym $mod+Shift+$up move up
bindsym $mod+Shift+$right move right
# ditto, with arrow keys
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right
#
# Workspaces:
#
# switch to workspace
bindsym $mod+1 workspace 1
bindsym $mod+2 workspace 2
bindsym $mod+3 workspace 3
bindsym $mod+4 workspace 4
bindsym $mod+5 workspace 5
bindsym $mod+6 workspace 6
bindsym $mod+7 workspace 7
bindsym $mod+8 workspace 8
bindsym $mod+9 workspace 9
bindsym $mod+0 workspace 10
# move focused container to workspace
bindsym $mod+Shift+1 move container to workspace 1
bindsym $mod+Shift+2 move container to workspace 2
bindsym $mod+Shift+3 move container to workspace 3
bindsym $mod+Shift+4 move container to workspace 4
bindsym $mod+Shift+5 move container to workspace 5
bindsym $mod+Shift+6 move container to workspace 6
bindsym $mod+Shift+7 move container to workspace 7
bindsym $mod+Shift+8 move container to workspace 8
bindsym $mod+Shift+9 move container to workspace 9
bindsym $mod+Shift+0 move container to workspace 10
# move workspace to output
bindsym $mod+Alt+Left move workspace to output left
bindsym $mod+Alt+Right move workspace to output right
# Note: workspaces can have any name you want, not just numbers.
# We just use 1-10 as the default.
#
# Layout stuff:
#
# You can "split" the current object of your focus with
# $mod+b or $mod+v, for horizontal and vertical splits
# respectively.
bindsym $mod+b splith
bindsym $mod+v splitv
# Switch the current container between different layout styles
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
# Make the current focus fullscreen
bindsym $mod+f fullscreen
# Toggle the current focus between tiling and floating mode
bindsym $mod+Shift+space floating toggle
# Swap focus between the tiling area and the floating area
bindsym $mod+space focus mode_toggle
# move focus to the parent container
bindsym $mod+a focus parent
#
# Status Bar:
#
# Read `man 5 sway-bar` for more information about this section.
bar {
position top
status_command ${pkgs.i3status-rust}/bin/i3status-rs ${status-configuration}
status_padding 0
font Fira Code Normal 9
colors {
statusline #535c65
background #fbffff
focused_workspace #2b7ab2 #2b7ab2 #fbffff
active_workspace #6d7782 #6d7782 #fbffff
inactive_workspace #fbffff #fbffff #535c65
urgent_workspace #ae5865 #ae5865 #fbffff
}
icon_theme Breeze
}
default_border pixel
include /etc/sway/config.d/*
'';
};
}

View file

@ -0,0 +1,22 @@
{ ... }:
{
home-manager.users.charlotte = { ... }: {
xdg.configFile."kanshi/config".text = ''
{
output "Unknown 0x2036 0x00000000" position 0,0 mode 2560x1440 scale 1.0
}
{
output "Unknown 0x2036 0x00000000" position 0,0 mode 2560x1440 scale 1.0
output "Dell Inc. DELL U2715H GH85D5B90R4S" position 2560,0 mode 2560x1440 scale 1.0
}
{
output "Chimei Innolux Corporation 0x14D3 0x00000000" position 0,0 mode 1920x1080 scale 1
}
{
output "Chimei Innolux Corporation 0x14D3 0x00000000" position 0,0 mode 1920x1080 scale 1
output "Dell Inc. DELL U2718Q FN84K83Q1KHL" position 1920,0 mode 3840x2160 scale 1.25
}
'';
};
}

View file

@ -0,0 +1,168 @@
{ pkgs, stdenv }:
let
pass = import ../../programs/pass/default.nix { inherit pkgs; };
gemoji = pkgs.buildRubyGem {
pname = "gemoji";
gemName = "gemoji";
source.sha256 = "1xv38sxql1fmaxi5lzj6v98l2aqhi6bqkhi6kqd0k38vw40l3yqc";
type = "gem";
version = "4.0.0.rc2";
};
emoji_list = 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
'';
};
in
pkgs.writeScriptBin "launcher" ''
#!${pkgs.zsh}/bin/zsh
_sighandler() {
kill -INT "$child" 2>/dev/null
}
calc_options() {
echo "calc "
}
calc() {
if [ -n "$1" ]
then
${pkgs.libqalculate}/bin/qalc "$1"
sleep 5
else
${pkgs.libqalculate}/bin/qalc
fi
}
emoji_options() {
cat ${emoji_list} | sed "s/^/emoji /"
}
emoji() {
char=$(echo -n "$1" | sed "s/^\([^ ]*\) .*/\1/")
${pkgs.sway}/bin/swaymsg exec -- "echo -n $char | ${pkgs.wl-clipboard}/bin/wl-copy --foreground"
}
pass_options(){
prefix=''${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg )
printf 'pass password %s\n' ''${''${password_files%.gpg}#$prefix/}
printf 'pass username %s\n' ''${''${password_files%.gpg}#$prefix/}
printf 'pass otp %s\n' ''${''${password_files%.gpg}#$prefix/}
printf 'pass edit %s\n' ''${''${password_files%.gpg}#$prefix/}
}
pass() {
option=$(echo $1 | sed "s/^\([^ ]*\) .*$/\1/")
passfile=$(echo $1 | sed "s/^[^ ]* \(.*$\)/\1/")
echo $option
echo $passfile
case $option in
username)
swaymsg exec -- "${pass}/bin/pass show '$passfile' | sed -n 's/^Username: *//p' | tr -d '\n' | ${pkgs.wl-clipboard}/bin/wl-copy --foreground"
;;
password)
swaymsg exec -- "${pass}/bin/pass show -c0 '$passfile'"
;;
otp)
swaymsg exec -- "${pass}/bin/pass otp -c '$passfile'"
;;
edit)
${pass}/bin/pass edit "$passfile"
;;
esac
}
record_options() {
${pkgs.sway}/bin/swaymsg -t get_outputs | ${pkgs.jq}/bin/jq -r '.[]["name"]' | sed "s/^/record /"
echo record select
}
record() {
filename="$(${pkgs.xdg-user-dirs}/bin/xdg-user-dir VIDEOS)/$(date +'screenrecording_%y-%m-%d-%H%M%S.mp4')"
trap _sighandler SIGINT
if [[ "$1" = "select" ]]
then
${pkgs.wf-recorder}/bin/wf-recorder -g "$(${pkgs.slurp}/bin/slurp)" -f "$filename" &
else
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() {
${pkgs.sway}/bin/swaymsg exec $1
}
ssh_options() {
cat $HOME/.ssh/config | grep "^Host [a-zA-Z]\+" | sed "s/Host /ssh /"
}
ssh() {
${pkgs.sway}/bin/swaymsg exec "${pkgs.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() {
${pkgs.sway}/bin/swaymsg exec "${pkgs.kitty}/bin/kitty -e ${pkgs.tmuxinator}/bin/tmuxinator start $1"
}
windows_options() {
${pkgs.sway}/bin/swaymsg -t get_tree | ${pkgs.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/')
${pkgs.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) | ${pkgs.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,38 @@
{ pkgs }:
pkgs.writeScriptBin "screenshot" ''
#!${pkgs.zsh}/bin/zsh
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 sunspear "cat > /usr/share/nginx/html/screenshots/$name"
path="https://cvpetegem.be/screenshots/$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,85 @@
{ pkgs, ... }:
let
mic-status = pkgs.writeScript "mic-status" ''
#!${pkgs.zsh}/bin/zsh
if [ "$(${pkgs.pulseaudio}/bin/pactl list sources | grep -o 'Mute: yes')" = "Mute: yes" ]
then
echo -e '\uf131'
else
echo -e '\uf130'
fi
'';
in
pkgs.writeText "configuration.toml" ''
[theme]
name = "gruvbox-light"
[theme.overrides]
idle_bg="#fbffff"
idle_fg="#535c65"
info_bg="#2b7ab2"
info_fg="#fbffff"
good_bg="#2b7ab2"
good_fg="#fbffff"
warning_bg="#2b7ab2"
warning_fg="#fbffff"
critical_bg="#2b7ab2"
critical_fg="#fbffff"
separator=""
[icons]
name = "awesome"
[[block]]
block = "focused_window"
max_width = 100
[[block]]
block = "net"
device = "wlp2s0"
ssid = true
signal_strength = true
speed_up = false
speed_down = false
hide_missing = true
hide_inactive = true
[[block]]
block = "net"
device = "wlp0s20f3"
ssid = true
signal_strength = false
speed_up = false
speed_down = false
hide_missing = true
hide_inactive = true
[[block]]
block = "net"
device = "enp0s31f6"
ip = true
speed_up = false
speed_down = false
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 = "time"
interval = 1
format = "%a %d/%m %H:%M:%S"
''