diff --git a/hm/common.nix b/hm/common.nix index b30bcd7..5fbd7c7 100644 --- a/hm/common.nix +++ b/hm/common.nix @@ -55,7 +55,6 @@ # Imported from scripts rms = ''${pkgs.findutils}/bin/find . -name "*.sync-conflict-*" -delete''; # Remove syncthing conflict files - pw = ''${pkgs.pwgen}/bin/pwgen 32 -y''; # Generate passwords. ln((26*2+10)**32)/ln(2) ≅ 190 bits of entropy newestFile = ''${pkgs.findutils}/bin/find -type f -printf '%T+ %p\n' | sort | tail''; oldestFile = ''${pkgs.findutils}/bin/find -type f -printf '%T+ %p\n' | sort | head''; }; @@ -125,7 +124,6 @@ }; tmux.enable = true; translate-shell.enable = true; # TODO Cool config? - password-store.enable = true; }; home = { activation = { @@ -184,10 +182,6 @@ sox imagemagick numbat - - # password - pwgen - ]; sessionVariables = { # Favourite commands diff --git a/hm/default.nix b/hm/default.nix index 83c4156..85789fa 100644 --- a/hm/default.nix +++ b/hm/default.nix @@ -13,6 +13,7 @@ ./monitoring ./nix ./pager + ./password ./prompt ./rebuild ./shell diff --git a/hm/desktop/audio/default.nix b/hm/desktop/audio/default.nix new file mode 100644 index 0000000..2e80253 --- /dev/null +++ b/hm/desktop/audio/default.nix @@ -0,0 +1,22 @@ +{ pkgs, lib, config, ... }: +let + pactl = "exec ${pkgs.pulseaudio}/bin/pactl"; # TODO Use NixOS package if using NixOS + mod = config.xsession.windowManager.i3.config.modifier; +in +{ + config = lib.mkIf config.frogeye.desktop.xorg { + home.packages = with pkgs; [ + pavucontrol # Because can't use Win+F1X on Pinebook 🙃 + ]; + xsession.windowManager.i3.config.keybindings = + { + "XF86AudioRaiseVolume" = "${pactl} set-sink-mute @DEFAULT_SINK@ false; ${pactl} set-sink-volume @DEFAULT_SINK@ +5%"; + "XF86AudioLowerVolume" = "${pactl} set-sink-mute @DEFAULT_SINK@ false; ${pactl} set-sink-volume @DEFAULT_SINK@ -5%"; + "XF86AudioMute" = "${pactl} set-sink-mute @DEFAULT_SINK@ true"; + "${mod}+F7" = "${pactl} suspend-sink @DEFAULT_SINK@ 1; ${pactl} suspend-sink @DEFAULT_SINK@ 0"; # Re-synchronize bluetooth headset + "${mod}+F11" = "exec ${pkgs.pavucontrol}/bin/pavucontrol"; + "${mod}+F12" = "exec ${pkgs.pavucontrol}/bin/pavucontrol"; + # TODO Find pacmixer? + }; + }; +} diff --git a/hm/desktop/default.nix b/hm/desktop/default.nix index ff24f4b..64e0b9a 100644 --- a/hm/desktop/default.nix +++ b/hm/desktop/default.nix @@ -5,9 +5,13 @@ let in { imports = [ + ./audio ./frobar ./i3.nix + ./lock + ./mpd ./qutebrowser.nix + ./screenshots ]; config = lib.mkIf config.frogeye.desktop.xorg { xsession = { @@ -154,9 +158,6 @@ in publicShare = null; templates = null; videos = "${config.home.homeDirectory}/Vidéos"; - extraConfig = { - XDG_SCREENSHOTS_DIR = "${config.home.homeDirectory}/Screenshots"; - }; }; configFile = { "pulse/client.conf" = { @@ -222,17 +223,6 @@ in }; }; }; - mpd = { - enable = true; - network = { - listenAddress = "0.0.0.0"; # So it can be controlled from home - # TODO ... and whoever is the Wi-Fi network I'm using, which, not great - startWhenNeeded = true; - }; - extraConfig = '' - restore_paused "yes" - ''; - }; autorandr.enable = true; }; @@ -249,11 +239,6 @@ in # remote tigervnc - # music - mpc-cli - ashuffle - vimpc - # multimedia common gimp inkscape diff --git a/hm/desktop/frobar/default.nix b/hm/desktop/frobar/default.nix index 1cf4ec4..60326b5 100644 --- a/hm/desktop/frobar/default.nix +++ b/hm/desktop/frobar/default.nix @@ -1,4 +1,4 @@ -{ pkgs ? import { config = { }; overlays = [ ]; }, ... }: +{ pkgs ? import { config = { }; overlays = [ ]; }, lib, config, ... }: # Tried using pyproject.nix but mpd2 dependency wouldn't resolve, # is called pyton-mpd2 on PyPi but mpd2 in nixpkgs. let @@ -22,7 +22,7 @@ let }; in { - config = { + config = lib.mkIf config.frogeye.desktop.xorg { xsession.windowManager.i3.config.bars = [ ]; programs.autorandr.hooks.postswitch = { frobar = "${pkgs.systemd}/bin/systemctl --user restart frobar"; diff --git a/hm/desktop/i3.nix b/hm/desktop/i3.nix index 91d2459..15f13f7 100644 --- a/hm/desktop/i3.nix +++ b/hm/desktop/i3.nix @@ -1,37 +1,5 @@ { pkgs, lib, config, ... }: let - # LOCKER - # lockColors = with config.lib.stylix.colors.withHashtag; { a = base00; b = base01; d = base00; }; # Black or White, depending on current theme - # lockColors = with config.lib.stylix.colors.withHashtag; { a = base0A; b = base0B; d = base00; }; # Green + Yellow - lockColors = { a = "#82a401"; b = "#466c01"; d = "#648901"; }; # Old - lockSvg = pkgs.writeText "lock.svg" ""; - lockPng = pkgs.runCommand "lock.png" { } "${pkgs.imagemagick}/bin/convert ${lockSvg} $out"; - locker = pkgs.writeShellScript "i3-locker" '' - # Remove SSH and GPG keys from keystores - ${pkgs.openssh}/bin/ssh-add -D - echo RELOADAGENT | ${pkgs.gnupg}/bin/gpg-connect-agent - ${pkgs.coreutils}/bin/rm -rf "/tmp/cached_pass_$UID" - - ${pkgs.lightdm}/bin/dm-tool lock - # TODO Does that work for all DMs? - # TODO Might want to use i3lock on NixOS configs still? - if [ $? -ne 0 ]; then - if [ -d ${config.xdg.cacheHome}/lockpatterns ] - then - pattern=$(${pkgs.findutils} ${config.xdg.cacheHome}/lockpatterns | sort -R | head -1) - else - pattern=${lockPng} - fi - revert() { - ${pkgs.xorg.xset}/bin/xset dpms 0 0 0 - } - trap revert SIGHUP SIGINT SIGTERM - ${pkgs.xorg.xset}/bin/xset dpms 5 5 5 - ${pkgs.i3lock}/bin/i3lock --nofork --color ${builtins.substring 1 6 lockColors.d} --image=$pattern --tiling --ignore-empty-password - revert - fi - ''; - # FOCUS focus = "exec ${ pkgs.writeShellScript "i3-focus-window" '' WINDOW=`${pkgs.xdotool}/bin/xdotool getwindowfocus` @@ -75,9 +43,6 @@ in let mod = config.xsession.windowManager.i3.config.modifier; rofi = "exec --no-startup-id ${config.programs.rofi.package}/bin/rofi"; - pactl = "exec ${pkgs.pulseaudio}/bin/pactl"; # TODO Use NixOS package if using NixOS - screenshots_dir = config.xdg.userDirs.extraConfig.XDG_SCREENSHOTS_DIR; - scrot = "${pkgs.scrot}/bin/scrot --exec '${pkgs.coreutils}/bin/mv $f ${screenshots_dir}/ && ${pkgs.optipng}/bin/optipng ${screenshots_dir}/$f'"; in { # Compatibility layer for people coming from other backgrounds @@ -88,9 +53,6 @@ in "${mod}+z" = "kill"; button2 = "kill"; # Rofi - "${mod}+c" = "exec --no-startup-id ${config.programs.rofi.pass.package}/bin/rofi-pass --last-used"; - # TODO Try autopass.cr - # 23.11 config.programs.rofi.pass.package "${mod}+i" = "exec --no-startup-id ${pkgs.rofimoji}/bin/rofimoji"; "${mod}+plus" = "${rofi} -modi ssh -show ssh"; "${mod}+ù" = "${rofi} -modi ssh -show ssh -ssh-command '{terminal} -e {ssh-client} {host} -t \"sudo -s -E\"'"; @@ -107,18 +69,6 @@ in }"; "${mod}+Shift+Return" = "exec ${config.programs.urxvt.package}/bin/urxvt"; "${mod}+p" = "exec ${pkgs.xfce.thunar}/bin/thunar"; - # Volume control - "XF86AudioRaiseVolume" = "${pactl} set-sink-mute @DEFAULT_SINK@ false; ${pactl} set-sink-volume @DEFAULT_SINK@ +5%"; - "XF86AudioLowerVolume" = "${pactl} set-sink-mute @DEFAULT_SINK@ false; ${pactl} set-sink-volume @DEFAULT_SINK@ -5%"; - "XF86AudioMute" = "${pactl} set-sink-mute @DEFAULT_SINK@ true"; - "${mod}+F7" = "${pactl} suspend-sink @DEFAULT_SINK@ 1; ${pactl} suspend-sink @DEFAULT_SINK@ 0"; # Re-synchronize bluetooth headset - "${mod}+F11" = "exec ${pkgs.pavucontrol}/bin/pavucontrol"; - "${mod}+F12" = "exec ${pkgs.pavucontrol}/bin/pavucontrol"; - # TODO Find pacmixer? - # Media control - "XF86AudioPrev" = "exec ${pkgs.mpc-cli}/bin/mpc prev"; - "XF86AudioPlay" = "exec ${pkgs.mpc-cli}/bin/mpc toggle"; - "XF86AudioNext" = "exec ${pkgs.mpc-cli}/bin/mpc next"; # Backlight "XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set +5%"; "XF86MonBrightnessDown" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set 5%-"; @@ -129,11 +79,6 @@ in ${pkgs.libgnomekbd}/bin/gkbd-keyboard-display -l $layout '' }"; - # Screenshots - "Print" = "exec ${scrot} --focused"; - "${mod}+Print" = "exec ${scrot}"; - "Ctrl+Print" = "exec ${pkgs.coreutils}/bin/sleep 1 && ${scrot} --select"; - # TODO Try using bindsym --release instead of sleep # change focus "${mod}+h" = "focus left; ${focus}"; "${mod}+j" = "focus down; ${focus}"; @@ -212,11 +157,6 @@ in "${mod}+Shift+c" = "reload"; "${mod}+Shift+r" = "restart"; "${mod}+Shift+e" = "exit"; - # Screen off commands - "${mod}+F1" = "exec --no-startup-id ${pkgs.bash}/bin/sh -c \"${pkgs.coreutils}/bin/sleep .25 && ${pkgs.xorg.xset}/bin/xset dpms force off\""; - # TODO --release? - "${mod}+F4" = "exec --no-startup-id ${pkgs.xautolock}/bin/xautolock -disable"; - "${mod}+F5" = "exec --no-startup-id ${pkgs.xautolock}/bin/xautolock -enable"; # Modes "${mod}+Escape" = "mode ${mode_system}"; "${mod}+r" = "mode ${mode_resize}"; @@ -224,16 +164,17 @@ in "${mod}+t" = "mode ${mode_screen}"; "${mod}+y" = "mode ${mode_temp}"; }; + # TOOD Config option so we don't have to separate name and binding modes = let return_bindings = { "Return" = "mode default"; "Escape" = "mode default"; }; in { "${mode_system}" = { - "l" = "exec --no-startup-id exec ${locker}, mode default"; + "l" = "exec --no-startup-id exec xlock, mode default"; "e" = "exit, mode default"; - "s" = "exec --no-startup-id exec ${locker} & ${pkgs.systemd}/bin/systemctl suspend --check-inhibitors=no, mode default"; - "h" = "exec --no-startup-id exec ${locker} & ${pkgs.systemd}/bin/systemctl hibernate, mode default"; + "s" = "exec --no-startup-id exec xlock & ${pkgs.systemd}/bin/systemctl suspend --check-inhibitors=no, mode default"; + "h" = "exec --no-startup-id exec xlock & ${pkgs.systemd}/bin/systemctl hibernate, mode default"; "r" = "exec --no-startup-id ${pkgs.systemd}/bin/systemctl reboot, mode default"; "p" = "exec --no-startup-id ${pkgs.systemd}/bin/systemctl poweroff -i, mode default"; } // return_bindings; @@ -294,14 +235,11 @@ in }; floating = { criteria = [ - { title = "pacmixer"; } { window_role = "pop-up"; } { window_role = "task_dialog"; } ]; }; startup = [ - # Lock screen after 10 minutes - { notification = false; command = "${pkgs.xautolock}/bin/xautolock -time 10 -locker '${pkgs.xorg.xset}/bin/xset dpms force standby' -killtime 1 -killer ${locker}"; } { notification = false; command = "${pkgs.writeShellApplication { @@ -312,7 +250,6 @@ in # TODO Only on computers with battery }}/bin/batteryNotify"; } - # TODO There's a services.screen-locker.xautolock but not sure it can match the above command ]; workspaceLayout = "tabbed"; focus.mouseWarping = true; # i3 only supports warping to workspace, hence ${focus} diff --git a/hm/desktop/lock/default.nix b/hm/desktop/lock/default.nix new file mode 100644 index 0000000..086d2da --- /dev/null +++ b/hm/desktop/lock/default.nix @@ -0,0 +1,64 @@ +{ pkgs, lib, config, ... }: +let + # lockColors = with config.lib.stylix.colors.withHashtag; { a = base00; b = base01; d = base00; }; # Black or White, depending on current theme + # lockColors = with config.lib.stylix.colors.withHashtag; { a = base0A; b = base0B; d = base00; }; # Green + Yellow + lockColors = { a = "#82a401"; b = "#466c01"; d = "#648901"; }; # Old + lockSvg = pkgs.writeText "lock.svg" '' + + + + + ''; + lockPng = pkgs.runCommand "lock.png" { } "${pkgs.imagemagick}/bin/convert ${lockSvg} $out"; + mod = config.xsession.windowManager.i3.config.modifier; +in +{ + config = lib.mkIf config.frogeye.desktop.xorg { + home.packages = with pkgs; [ + (pkgs.writeShellApplication { + name = "xlock"; + text = '' + # Remove SSH and GPG keys from keystores + ${pkgs.openssh}/bin/ssh-add -D + echo RELOADAGENT | ${pkgs.gnupg}/bin/gpg-connect-agent + ${pkgs.coreutils}/bin/rm -rf "/tmp/cached_pass_$UID" + # TODO Should probably be an option and defined where relevant? + # TODO Maybe we could have a terminal lock? With vlock. + + # TODO Does that work for all DMs? + # TODO Might want to use i3lock on NixOS configs still? + if ! ${pkgs.lightdm}/bin/dm-tool lock + then + if [ -d ${config.xdg.cacheHome}/lockpatterns ] + then + pattern=$(${pkgs.findutils} ${config.xdg.cacheHome}/lockpatterns | sort -R | head -1) + else + pattern=${lockPng} + fi + revert() { + ${pkgs.xorg.xset}/bin/xset dpms 0 0 0 + } + trap revert SIGHUP SIGINT SIGTERM + ${pkgs.xorg.xset}/bin/xset dpms 5 5 5 + ${pkgs.i3lock}/bin/i3lock --nofork --color ${builtins.substring 1 6 lockColors.d} --image="$pattern" --tiling --ignore-empty-password + revert + fi + ''; + }) + ]; + xsession.windowManager.i3.config = { + keybindings = { + # Screen off commands + "${mod}+F1" = "exec --no-startup-id ${pkgs.bash}/bin/sh -c \"${pkgs.coreutils}/bin/sleep .25 && ${pkgs.xorg.xset}/bin/xset dpms force off\""; + # TODO --release? + "${mod}+F4" = "exec --no-startup-id ${pkgs.xautolock}/bin/xautolock -disable"; + "${mod}+F5" = "exec --no-startup-id ${pkgs.xautolock}/bin/xautolock -enable"; + }; + startup = [ + # Lock screen after 10 minutes + { notification = false; command = "${pkgs.xautolock}/bin/xautolock -time 10 -locker '${pkgs.xorg.xset}/bin/xset dpms force standby' -killtime 1 -killer xlock"; } + # TODO There's a services.screen-locker.xautolock but not sure it can match the above command + ]; + }; + }; +} diff --git a/hm/desktop/mpd/default.nix b/hm/desktop/mpd/default.nix new file mode 100644 index 0000000..618bc95 --- /dev/null +++ b/hm/desktop/mpd/default.nix @@ -0,0 +1,27 @@ +{ pkgs, lib, config, ... }: +{ + config = lib.mkIf config.frogeye.desktop.xorg { + home.packages = with pkgs; [ + ashuffle + mpc-cli + vimpc + ]; + services.mpd = { + enable = true; + network = { + listenAddress = "0.0.0.0"; # So it can be controlled from home + # TODO ... and whoever is the Wi-Fi network I'm using, which, not great + startWhenNeeded = true; + }; + extraConfig = '' + restore_paused "yes" + ''; + }; + xsession.windowManager.i3.config.keybindings = + { + "XF86AudioPrev" = "exec ${pkgs.mpc-cli}/bin/mpc prev"; + "XF86AudioPlay" = "exec ${pkgs.mpc-cli}/bin/mpc toggle"; + "XF86AudioNext" = "exec ${pkgs.mpc-cli}/bin/mpc next"; + }; + }; +} diff --git a/hm/desktop/screenshots/default.nix b/hm/desktop/screenshots/default.nix new file mode 100644 index 0000000..a9a4583 --- /dev/null +++ b/hm/desktop/screenshots/default.nix @@ -0,0 +1,17 @@ +{ pkgs, lib, config, ... }: +let + dir = config.xdg.userDirs.extraConfig.XDG_SCREENSHOTS_DIR; + scrot = "${pkgs.scrot}/bin/scrot --exec '${pkgs.coreutils}/bin/mv $f ${dir}/ && ${pkgs.optipng}/bin/optipng ${dir}/$f'"; + mod = config.xsession.windowManager.i3.config.modifier; +in +{ + config = lib.mkIf config.frogeye.desktop.xorg { + xdg.userDirs.extraConfig.XDG_SCREENSHOTS_DIR = "${config.home.homeDirectory}/Screenshots"; + xsession.windowManager.i3.config.keybindings = { + "Print" = "exec ${scrot} --focused"; + "${mod}+Print" = "exec ${scrot}"; + "Ctrl+Print" = "exec ${pkgs.coreutils}/bin/sleep 1 && ${scrot} --select"; + # TODO Try using bindsym --release instead of sleep + }; + }; +} diff --git a/hm/password/default.nix b/hm/password/default.nix new file mode 100644 index 0000000..caecc50 --- /dev/null +++ b/hm/password/default.nix @@ -0,0 +1,19 @@ +{ pkgs, lib, config, ... }: +let + mod = config.xsession.windowManager.i3.config.modifier; +in +{ + config = { + home.packages = with pkgs; [ + pwgen + ]; + programs = { + bash.shellAliases = { + pw = ''${pkgs.pwgen}/bin/pwgen 32 -y''; # Generate passwords. ln((26*2+10)**32)/ln(2) ≅ 190 bits of entropy + }; + password-store.enable = true; + }; + xsession.windowManager.i3.config.keybindings."${mod}+c" = "exec --no-startup-id ${config.programs.rofi.pass.package}/bin/rofi-pass --last-used"; + # TODO Try autopass.cr + }; +} diff --git a/os/desktop.nix b/os/desktop.nix index f361cc0..24e4dc1 100644 --- a/os/desktop.nix +++ b/os/desktop.nix @@ -39,6 +39,7 @@ hardware = { bluetooth.enable = true; pulseaudio.enable = true; + # TODO Try pipewire }; # UPST