From 578f05b4f16e2aed4a1a862e764c981081aff72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Wed, 12 Jan 2022 17:39:16 +0100 Subject: [PATCH 01/13] Always hibernate --- .../config/config.d/custom-keybindings.conf | 4 +--- modules/sway/swayidle.service.nix | 8 +++----- pkgs/default.nix | 1 - pkgs/swaylock-bg.nix | 20 ------------------- 4 files changed, 4 insertions(+), 29 deletions(-) delete mode 100644 pkgs/swaylock-bg.nix diff --git a/modules/sway/config/config.d/custom-keybindings.conf b/modules/sway/config/config.d/custom-keybindings.conf index 6218d900..46fae96d 100644 --- a/modules/sway/config/config.d/custom-keybindings.conf +++ b/modules/sway/config/config.d/custom-keybindings.conf @@ -33,12 +33,10 @@ set $menu exec alacritty --class launcher -e env TERMINAL_COMMAND="alacritty -e" bindsym $mod+Space exec $menu # Set shut down, restart and locking features -set $mode_system (l)ock, (e)xit, (s)uspend, (h)ibernate, (r)eboot, (Shift+s)hutdown +set $mode_system (e)xit, (h)ibernate, (r)eboot, (Shift+s)hutdown bindsym $mod+0 mode "$mode_system" mode "$mode_system" { - bindsym l exec swaylock-bg, mode "default" bindsym e exec swaymsg exit, mode "default" - bindsym s exec systemctl suspend, mode "default" bindsym h exec systemctl hibernate, mode "default" bindsym r exec systemctl reboot, mode "default" bindsym Shift+s exec systemctl poweroff, mode "default" diff --git a/modules/sway/swayidle.service.nix b/modules/sway/swayidle.service.nix index 597a8779..549f153f 100644 --- a/modules/sway/swayidle.service.nix +++ b/modules/sway/swayidle.service.nix @@ -9,12 +9,10 @@ pkgs: }; Service = { Type = "simple"; - Environment = "PATH=/run/current-system/sw/bin:${pkgs.sway}/bin:${pkgs.swaylock}/bin:${pkgs.swaylock-bg}/bin"; + Environment = "PATH=/run/current-system/sw/bin:${pkgs.sway}/bin"; ExecStart = ''${pkgs.swayidle}/bin/swayidle -w \ - timeout 600 'swaylock-bg' \ - timeout 900 'swaymsg "output * dpms off"' \ - resume 'swaymsg "output * dpms on"' \ - before-sleep 'swaylock-bg' + timeout 300 'swaymsg "output * dpms off"' \ + timeout 600 'systemctl hibernate' \ ''; }; Install = { diff --git a/pkgs/default.nix b/pkgs/default.nix index 312e685f..d8a86fd7 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -12,7 +12,6 @@ with final; { s = writeShellScriptBin "s" (import ./s.nix final); sway-launcher = writeScriptBin "sway-launcher" (import ./sway-launcher.nix final); sway-service = writeShellScriptBin "sway-service" (import ./sway-service.nix final); - swaylock-bg = writeScriptBin "swaylock-bg" (import ./swaylock-bg.nix final); toggle-kbd-layout = writeShellScriptBin "toggle-kbd-layout" (import ./toggle-kbd-layout.nix final); uhk-agent = import ./uhk-agent.nix final; wcwd = writeShellScriptBin "wcwd" (import ./wcwd.nix final); diff --git a/pkgs/swaylock-bg.nix b/pkgs/swaylock-bg.nix deleted file mode 100644 index b55c32ae..00000000 --- a/pkgs/swaylock-bg.nix +++ /dev/null @@ -1,20 +0,0 @@ -self: with self; '' - # Dependencies: - # swaylock - - # Make sure we aren't running twice - RUNNING=$(ps -A | grep swaylock | wc -l) - if [ $RUNNING -ne 0 ]; then - exit 0 - fi - - IMAGE=$XDG_CONFIG_HOME/wallpaper.jpg - LOCKARGS="" - - for OUTPUT in `${sway}/bin/swaymsg -t get_outputs | jq -r '.[].name'` - do - LOCKARGS="''${LOCKARGS} --image ''${OUTPUT}:''${IMAGE}" - IMAGES="''${IMAGES} ''${IMAGE}" - done - exec ${swaylock}/bin/swaylock $LOCKARGS -'' From d2f8a2d837904cecc978bbc3b5a77026e73b9bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sat, 30 Apr 2022 23:56:02 +0200 Subject: [PATCH 02/13] Remove swaylock-bg from install list --- modules/sway/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/sway/default.nix b/modules/sway/default.nix index 83f407e4..88426536 100644 --- a/modules/sway/default.nix +++ b/modules/sway/default.nix @@ -75,7 +75,6 @@ in xsettingsd ydotool - swaylock-bg sway-launcher import-gtk-settings s From 4b828cd91f8063047efcfce3c453465300c6e527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 1 May 2022 17:04:29 +0200 Subject: [PATCH 03/13] Shorten time until hibernate --- modules/sway/swayidle.service.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sway/swayidle.service.nix b/modules/sway/swayidle.service.nix index 549f153f..61f32591 100644 --- a/modules/sway/swayidle.service.nix +++ b/modules/sway/swayidle.service.nix @@ -11,8 +11,8 @@ pkgs: Type = "simple"; Environment = "PATH=/run/current-system/sw/bin:${pkgs.sway}/bin"; ExecStart = ''${pkgs.swayidle}/bin/swayidle -w \ - timeout 300 'swaymsg "output * dpms off"' \ - timeout 600 'systemctl hibernate' \ + timeout 150 'swaymsg "output * dpms off"' \ + timeout 300 'systemctl hibernate' \ ''; }; Install = { From 0c4987ede101bd0348e599409626e74314f43ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 1 May 2022 17:29:21 +0200 Subject: [PATCH 04/13] Add resume device --- .../config/config.d/custom-keybindings.conf | 2 +- modules/x-os/boot.nix | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/modules/sway/config/config.d/custom-keybindings.conf b/modules/sway/config/config.d/custom-keybindings.conf index 157ae8ee..172b7e53 100644 --- a/modules/sway/config/config.d/custom-keybindings.conf +++ b/modules/sway/config/config.d/custom-keybindings.conf @@ -23,7 +23,7 @@ bindsym $mod+F5 exec $term -e 'mocp -C $XDG_CONFIG_DIR/mocp/config' bindsym $mod+Shift+m exec mu bindsym $mod+Shift+h exec xdg-open /usr/share/doc/manjaro/i3_help.pdf -# Screenshofts +# Screenshots bindsym $mod+Ctrl+p exec grim -g "$(slurp -d -b \#ffffff11)" ~/Pictures/Screenshots/$(date +%Y%m%d_%Hh%Mm%Ss)_grim.png bindsym $mod+Shift+p exec grim ~/Pictures/Screenshots/$(date +%Y%m%d_%Hh%Mm%Ss)_grim.png bindsym $mod+Ctrl+f exec "( pkill flameshot || true && flameshot & ) && ( sleep 0.5s && flameshot gui )" diff --git a/modules/x-os/boot.nix b/modules/x-os/boot.nix index 0633bec4..268f1547 100644 --- a/modules/x-os/boot.nix +++ b/modules/x-os/boot.nix @@ -10,18 +10,22 @@ in description = "Feature flag for iso builds"; }; config = { - # Enable plymouth for better experience of booting - boot.plymouth.enable = true; + boot = { + # Enable plymouth for better experience of booting + plymouth.enable = true; - # Mount / luks device in initrd - # Allow fstrim to work on it. - # The ! makes this enabled by default - boot.initrd = mkIf (!cfg.iso-options.enable) { - luks.devices."cryptroot" = { - allowDiscards = true; + # Mount / luks device in initrd + # Allow fstrim to work on it. + # The ! makes this enabled by default + initrd = mkIf (!cfg.iso-options.enable) { + luks.devices."cryptroot" = { + allowDiscards = true; + }; }; - }; - boot.loader.systemd-boot.enable = true; + resumeDevice = "/swapfile"; + + loader.systemd-boot.enable = true; + }; }; } From 4c0991c7e1a7670526ec2331c0def1a5ae46e918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 17:10:30 +0200 Subject: [PATCH 05/13] Put always hibernate behind a flag Hibernation is now a core option: ``` pub-solar.core.hibernation.enable = true; ``` And there's a paranoia mode, that keeps the disk encrypted as much as possible by enabling hibernation and removing the options for sleep, screen locking. Idle locking now hibernates, and it does it on very short notice. --- modules/core/boot.nix | 10 ++++- modules/paranoia/default.nix | 24 +++++++++++ .../config/config.d/custom-keybindings.conf | 19 --------- .../sway/config/config.d/mode_system.conf.nix | 21 ++++++++++ modules/sway/default.nix | 40 ++++++++++--------- modules/sway/gammastep.service.nix | 2 +- modules/sway/libinput-gestures.service.nix | 2 +- modules/sway/mako.service.nix | 2 +- modules/sway/sway-session.target.nix | 2 +- modules/sway/sway.service.nix | 2 +- modules/sway/swayidle.service.nix | 15 +++++-- modules/sway/waybar.service.nix | 2 +- modules/sway/xsettingsd.service.nix | 2 +- modules/sway/ydotool.service.nix | 2 +- pkgs/default.nix | 1 + pkgs/swaylock-bg.nix | 20 ++++++++++ 16 files changed, 115 insertions(+), 51 deletions(-) create mode 100644 modules/paranoia/default.nix create mode 100644 modules/sway/config/config.d/mode_system.conf.nix create mode 100644 pkgs/swaylock-bg.nix diff --git a/modules/core/boot.nix b/modules/core/boot.nix index 99b6d76c..6f93fabf 100644 --- a/modules/core/boot.nix +++ b/modules/core/boot.nix @@ -16,6 +16,14 @@ in description = "Whether it should be assumed that there is a cryptroot device"; }; + options.pub-solar.core.hibernation = { + enable = mkOption { + type = types.bool; + default = false; + description = "Whether the device can hibernate. This creates a swapfile at /swapfile."; + }; + }; + config = { boot = { # Enable plymouth for better experience of booting @@ -30,7 +38,7 @@ in }; }; - resumeDevice = "/swapfile"; + resumeDevice = mkIf cfg.core.hibernation.enable "/swapfile"; loader.systemd-boot.enable = true; diff --git a/modules/paranoia/default.nix b/modules/paranoia/default.nix new file mode 100644 index 00000000..ec530fc3 --- /dev/null +++ b/modules/paranoia/default.nix @@ -0,0 +1,24 @@ +{ config, lib, ... }: + +with lib; +let + psCfg = config.pub-solar; + cfg = config.pub-solar.paranoia; +in +{ + options.pub-solar.paranoia = { + enable = mkOption { + description = '' + Only offer hibernation instead of screen locking and sleeping. This only makes sense + if your hard drive is encrypted, and ensures that the contents of your drive are + encrypted if you are not actively using the device. + ''; + default = false; + type = types.bool; + }; + }; + + config = mkIf cfg.enable { + pub-solar.core.allow-hibernation = true; + }; +} diff --git a/modules/sway/config/config.d/custom-keybindings.conf b/modules/sway/config/config.d/custom-keybindings.conf index fdeac97a..659a4660 100644 --- a/modules/sway/config/config.d/custom-keybindings.conf +++ b/modules/sway/config/config.d/custom-keybindings.conf @@ -31,22 +31,3 @@ bindsym $mod+Ctrl+f exec "( pkill flameshot || true && flameshot & ) && ( sleep # Launcher set $menu exec alacritty --class launcher -e env TERMINAL_COMMAND="alacritty -e" sway-launcher bindsym $mod+Space exec $menu - -# Set shut down, restart and locking features -set $mode_system (e)xit, (h)ibernate, (r)eboot, (Shift+s)hutdown -bindsym $mod+0 mode "$mode_system" -mode "$mode_system" { - bindsym e exec swaymsg exit, mode "default" -#======= - bindsym l exec swaylock-bg, mode "default" - bindsym e exec systemctl --user stop graphical-session.target, mode "default" - bindsym s exec systemctl suspend, mode "default" -#>>>>>>> main - bindsym h exec systemctl hibernate, mode "default" - bindsym r exec systemctl reboot, mode "default" - bindsym Shift+s exec systemctl poweroff, mode "default" - - # exit system mode: "Enter" or "Escape" - bindsym Return mode "default" - bindsym Escape mode "default" -} diff --git a/modules/sway/config/config.d/mode_system.conf.nix b/modules/sway/config/config.d/mode_system.conf.nix new file mode 100644 index 00000000..ef11a461 --- /dev/null +++ b/modules/sway/config/config.d/mode_system.conf.nix @@ -0,0 +1,21 @@ +{ psCfg, ... }: '' +# Set shut down, restart and locking features +set $mode_system (e)xit, (h)ibernate, (r)eboot, (Shift+s)hutdown +bindsym $mod+0 mode "$mode_system" +mode "$mode_system" { + bindsym e exec swaymsg exit, mode "default" +'' + (if !psCfg.core.allow-hibernation then '' + bindsym h exec systemctl hibernate, mode "default" +'' else "") + + (if !psCfg.paranoia.enable then '' + bindsym l exec swaylock-bg, mode "default" + bindsym s exec systemctl suspend, mode "default" +'' else "") + '' + bindsym r exec systemctl reboot, mode "default" + bindsym Shift+s exec systemctl poweroff, mode "default" + + # exit system mode: "Enter" or "Escape" + bindsym Return mode "default" + bindsym Escape mode "default" +} +'' diff --git a/modules/sway/default.nix b/modules/sway/default.nix index 59b6ff09..2872a3b3 100644 --- a/modules/sway/default.nix +++ b/modules/sway/default.nix @@ -2,25 +2,26 @@ with lib; let psCfg = config.pub-solar; - cfg = config.pub-solar.sway; in { options.pub-solar.sway = { enable = mkEnableOption "Life in boxes"; - }; - options.pub-solar.sway.terminal = mkOption { - type = types.nullOr types.str; - default = "alacritty"; - description = "Choose sway's default terminal"; - }; - options.pub-solar.sway.v4l2loopback.enable = mkOption { - type = types.bool; - default = true; - description = "WebCam streaming tool"; + + terminal = mkOption { + type = types.nullOr types.str; + default = "alacritty"; + description = "Choose sway's default terminal"; + }; + + v4l2loopback.enable = mkOption { + type = types.bool; + default = true; + description = "WebCam streaming tool"; + }; }; - config = mkIf cfg.enable (mkMerge [ - (mkIf (cfg.v4l2loopback.enable) { + config = mkIf psCfg.sway.enable (mkMerge [ + (mkIf (psCfg.sway.v4l2loopback.enable) { boot.extraModulePackages = with config.boot.kernelPackages; [ v4l2loopback ]; boot.kernelModules = [ "v4l2loopback" ]; boot.extraModprobeConfig = '' @@ -84,18 +85,19 @@ in programs.waybar.enable = true; #programs.waybar.systemd.enable = true; - systemd.user.services.mako = import ./mako.service.nix pkgs; - systemd.user.services.sway = import ./sway.service.nix pkgs; - systemd.user.services.swayidle = import ./swayidle.service.nix pkgs; - systemd.user.services.xsettingsd = import ./xsettingsd.service.nix pkgs; - systemd.user.services.waybar = import ./waybar.service.nix pkgs; - systemd.user.targets.sway-session = import ./sway-session.target.nix pkgs; + systemd.user.services.mako = import ./mako.service.nix { inherit pkgs psCfg; }; + systemd.user.services.sway = import ./sway.service.nix { inherit pkgs psCfg; }; + systemd.user.services.swayidle = import ./swayidle.service.nix { inherit pkgs psCfg; }; + systemd.user.services.xsettingsd = import ./xsettingsd.service.nix { inherit pkgs psCfg; }; + systemd.user.services.waybar = import ./waybar.service.nix { inherit pkgs psCfg; }; + systemd.user.targets.sway-session = import ./sway-session.target.nix { inherit pkgs psCfg; }; xdg.configFile."sway/config".text = import ./config/config.nix { inherit config pkgs; }; xdg.configFile."sway/config.d/colorscheme.conf".source = ./config/config.d/colorscheme.conf; xdg.configFile."sway/config.d/theme.conf".source = ./config/config.d/theme.conf; xdg.configFile."sway/config.d/gaps.conf".source = ./config/config.d/gaps.conf; xdg.configFile."sway/config.d/custom-keybindings.conf".source = ./config/config.d/custom-keybindings.conf; + xdg.configFile."sway/config.d/mode_system.conf".text = import ./config/config.d/mode_system.config.nix { inherit psCfg; }; xdg.configFile."sway/config.d/applications.conf".source = ./config/config.d/applications.conf; xdg.configFile."sway/config.d/systemd.conf".source = ./config/config.d/systemd.conf; }; diff --git a/modules/sway/gammastep.service.nix b/modules/sway/gammastep.service.nix index f59edf02..3960d1ae 100644 --- a/modules/sway/gammastep.service.nix +++ b/modules/sway/gammastep.service.nix @@ -1,4 +1,4 @@ -pkgs: +{ pkgs, ... }: { Unit = { Description = "set color temperature of display according to time of day"; diff --git a/modules/sway/libinput-gestures.service.nix b/modules/sway/libinput-gestures.service.nix index c4c860da..798d10d6 100644 --- a/modules/sway/libinput-gestures.service.nix +++ b/modules/sway/libinput-gestures.service.nix @@ -1,4 +1,4 @@ -pkgs: +{ pkgs, ... }: { Unit = { Description = "Actions gestures on your touchpad using libinput"; diff --git a/modules/sway/mako.service.nix b/modules/sway/mako.service.nix index 190b986d..b155e148 100644 --- a/modules/sway/mako.service.nix +++ b/modules/sway/mako.service.nix @@ -1,4 +1,4 @@ -pkgs: +{ pkgs, ... }: { Unit = { Description = "Lightweight Wayland notification daemon"; diff --git a/modules/sway/sway-session.target.nix b/modules/sway/sway-session.target.nix index 3eb4d24c..7b25376a 100644 --- a/modules/sway/sway-session.target.nix +++ b/modules/sway/sway-session.target.nix @@ -1,4 +1,4 @@ -pkgs: +{ pkgs, ... }: { Unit = { Description = "sway compositor session"; diff --git a/modules/sway/sway.service.nix b/modules/sway/sway.service.nix index 95efc3e6..0d0d782c 100644 --- a/modules/sway/sway.service.nix +++ b/modules/sway/sway.service.nix @@ -1,4 +1,4 @@ -pkgs: +{ pkgs, ... }: { Unit = { Description = "sway - SirCmpwn's Wayland window manager"; diff --git a/modules/sway/swayidle.service.nix b/modules/sway/swayidle.service.nix index 61f32591..3b87c610 100644 --- a/modules/sway/swayidle.service.nix +++ b/modules/sway/swayidle.service.nix @@ -1,4 +1,4 @@ -pkgs: +{ pkgs, psCfg, ... }: { Unit = { Description = "Idle manager for Wayland"; @@ -10,9 +10,16 @@ pkgs: Service = { Type = "simple"; Environment = "PATH=/run/current-system/sw/bin:${pkgs.sway}/bin"; - ExecStart = ''${pkgs.swayidle}/bin/swayidle -w \ - timeout 150 'swaymsg "output * dpms off"' \ - timeout 300 'systemctl hibernate' \ + ExecStart = if psCfg.paranoia.enable then '' + ${pkgs.swayidle}/bin/swayidle -w \ + timeout 120 'swaymsg "output * dpms off"' \ + timeout 150 'systemctl hibernate' \ + '' else '' + ${pkgs.swayidle}/bin/swayidle -w \ + timeout 600 'swaylock-bg' \ + timeout 900 'swaymsg "output * dpms off"' \ + resume 'swaymsg "output * dpms on"' \ + before-sleep 'swaylock-bg' ''; }; Install = { diff --git a/modules/sway/waybar.service.nix b/modules/sway/waybar.service.nix index ee5e8938..98b8ed35 100644 --- a/modules/sway/waybar.service.nix +++ b/modules/sway/waybar.service.nix @@ -1,4 +1,4 @@ -pkgs: +{ pkgs, ... }: { Unit = { Description = "Highly customizable Wayland bar for Sway and Wlroots based compositors."; diff --git a/modules/sway/xsettingsd.service.nix b/modules/sway/xsettingsd.service.nix index 0d729cb2..db3e842c 100644 --- a/modules/sway/xsettingsd.service.nix +++ b/modules/sway/xsettingsd.service.nix @@ -1,4 +1,4 @@ -pkgs: +{ pkgs, ... }: { Unit = { Description = "X Settings Daemon"; diff --git a/modules/sway/ydotool.service.nix b/modules/sway/ydotool.service.nix index d53bfcd7..24b64432 100644 --- a/modules/sway/ydotool.service.nix +++ b/modules/sway/ydotool.service.nix @@ -1,4 +1,4 @@ -pkgs: +{ pkgs, ... }: { Unit = { Description = "ydotool - Generic command-line automation tool (no X!)"; diff --git a/pkgs/default.nix b/pkgs/default.nix index 1b04f378..28e513b7 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -12,6 +12,7 @@ with final; { s = writeShellScriptBin "s" (import ./s.nix final); sway-launcher = writeScriptBin "sway-launcher" (import ./sway-launcher.nix final); sway-service = writeShellScriptBin "sway-service" (import ./sway-service.nix final); + swaylock-bg = writeShellScriptBin "swaylock-bg" (import ./swaylock-bg.nix final); toggle-kbd-layout = writeShellScriptBin "toggle-kbd-layout" (import ./toggle-kbd-layout.nix final); uhk-agent = import ./uhk-agent.nix final; wcwd = writeShellScriptBin "wcwd" (import ./wcwd.nix final); diff --git a/pkgs/swaylock-bg.nix b/pkgs/swaylock-bg.nix new file mode 100644 index 00000000..b55c32ae --- /dev/null +++ b/pkgs/swaylock-bg.nix @@ -0,0 +1,20 @@ +self: with self; '' + # Dependencies: + # swaylock + + # Make sure we aren't running twice + RUNNING=$(ps -A | grep swaylock | wc -l) + if [ $RUNNING -ne 0 ]; then + exit 0 + fi + + IMAGE=$XDG_CONFIG_HOME/wallpaper.jpg + LOCKARGS="" + + for OUTPUT in `${sway}/bin/swaymsg -t get_outputs | jq -r '.[].name'` + do + LOCKARGS="''${LOCKARGS} --image ''${OUTPUT}:''${IMAGE}" + IMAGES="''${IMAGES} ''${IMAGE}" + done + exec ${swaylock}/bin/swaylock $LOCKARGS +'' From 762e78677b39b722dbd12990025d9d3b5e943df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 17:15:50 +0200 Subject: [PATCH 06/13] Fix hibernation enabling in paranoia mode --- modules/paranoia/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/paranoia/default.nix b/modules/paranoia/default.nix index ec530fc3..19c470ad 100644 --- a/modules/paranoia/default.nix +++ b/modules/paranoia/default.nix @@ -19,6 +19,6 @@ in }; config = mkIf cfg.enable { - pub-solar.core.allow-hibernation = true; + pub-solar.core.hibernate.enable = true; }; } From ca4262b84f341b97cd4a179bde3740d42bc61052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 17:20:09 +0200 Subject: [PATCH 07/13] Fix hibernation enabling in paranoia mode --- modules/paranoia/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/paranoia/default.nix b/modules/paranoia/default.nix index 19c470ad..bb319767 100644 --- a/modules/paranoia/default.nix +++ b/modules/paranoia/default.nix @@ -19,6 +19,6 @@ in }; config = mkIf cfg.enable { - pub-solar.core.hibernate.enable = true; + pub-solar.core.hibernation.enable = true; }; } From 043178172b96ad23ef9c62bd406c43652b342bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 18:03:32 +0200 Subject: [PATCH 08/13] Improve help and screen recording keybindings in sway This commit shuffles around some sway keybindings and improves the screen recording experience by adding a small wrapper around `slurp` and `wf-recorder` conveniently called `record-screen`. * `$mod+F5` now reload the sway configuration, * `$mod+Ctrl+r` starts a screen recording (to stop it, go to workspace 7 and kill the process), * `record-screen` and the firefox sharing indicator are both on workspace 7 now, making it the "trash" workspace, * `$mod+F1` and `$mod+Shift+h` now open Firefox with the docs of our repository availabe under `help.local`. * To not infuriate `qMasterPassword` users, that is now available under `$mod+Shift+m` instead of `$mod+F1`. --- doc/book.toml | 2 +- modules/core/networking.nix | 16 ++++++++---- .../sway/config/config.d/applications.conf | 11 +++++--- .../config/config.d/custom-keybindings.conf | 15 +++++++---- modules/sway/config/config.nix | 2 +- modules/sway/default.nix | 1 + pkgs/default.nix | 2 ++ pkgs/psos-docs.nix | 26 +++++++++++++++++++ pkgs/psos.nix | 4 +++ pkgs/record-screen.nix | 10 +++++++ 10 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 pkgs/psos-docs.nix create mode 100644 pkgs/record-screen.nix diff --git a/doc/book.toml b/doc/book.toml index 373d26fd..f9dca6a3 100644 --- a/doc/book.toml +++ b/doc/book.toml @@ -3,4 +3,4 @@ authors = ["Timothy DeHerrera"] language = "en" multilingual = false src = "." -title = "devos docs" +title = "PubSolarOS documentation" diff --git a/modules/core/networking.nix b/modules/core/networking.nix index ce3248d8..95db64e3 100644 --- a/modules/core/networking.nix +++ b/modules/core/networking.nix @@ -34,20 +34,26 @@ in # These entries get added to /etc/hosts networking.hosts = { - "127.0.0.1" = [ "cups.local" ]; + "127.0.0.1" = [ "cups.local" "help.local" "caddy.local" ]; }; # Caddy reverse proxy for local services like cups services.caddy = { enable = true; globalConfig = '' + default_bind 127.0.0.1 auto_https off ''; extraConfig = '' - cups.local:80 - bind 127.0.0.1 - request_header Host localhost:631 - reverse_proxy unix//run/cups/cups.sock + cups.local:80 { + request_header Host localhost:631 + reverse_proxy unix//run/cups/cups.sock + } + + help.local:80 { + root * ${pkgs.psos-docs}/lib/html + file_server + } ''; }; }; diff --git a/modules/sway/config/config.d/applications.conf b/modules/sway/config/config.d/applications.conf index 3bab265d..00eecef3 100644 --- a/modules/sway/config/config.d/applications.conf +++ b/modules/sway/config/config.d/applications.conf @@ -14,8 +14,9 @@ assign [app_id="telegramdesktop"] $ws4 # Launcher for_window [app_id="launcher" title="Alacritty"] floating enable, border pixel 10, sticky enable +for_window [app_id="pavucontrol"] floating enable, border pixel 10, sticky enable + # Floating menus -for_window [app_id="pavucontrol"] floating enable for_window [app_id="blueman-manager"] floating enable # Open specific applications in floating mode @@ -60,10 +61,14 @@ for_window [window_type="dialog"] floating enable for_window [window_type="menu"] floating enable for_window [title="About Mozilla Firefox"] floating enable for_window [title="Password Required - Mozilla Firefox"] floating enable -for_window [title="Firefox — Sharing Indicator"] move to workspace $ws7, floating enable -no_focus [title="Firefox — Sharing Indicator"] for_window [title="Extension: (Open in Browser)*"] floating enable +# Technical media stuff happens on ws7 +for_window [app_id="screen-recorder" title="Alacritty"] move to workspace $ws7, floating disable +no_focus [app_id="screen-recorder"] +for_window [title="Firefox — Sharing Indicator"] move to workspace $ws7, floating disable +no_focus [title="Firefox — Sharing Indicator"] + # qMasterPassword floating menu for_window [title="qMasterPassword"] focus for_window [title="qMasterPassword"] floating enable diff --git a/modules/sway/config/config.d/custom-keybindings.conf b/modules/sway/config/config.d/custom-keybindings.conf index bb452ddc..39a0353e 100644 --- a/modules/sway/config/config.d/custom-keybindings.conf +++ b/modules/sway/config/config.d/custom-keybindings.conf @@ -13,21 +13,26 @@ bindsym $mod+Ctrl+m exec pavucontrol ################################################################################################ # Quickstart application shortcuts -bindsym $mod+F1 exec qMasterPassword +bindsym $mod+F1 exec psos help +bindsym $mod+Shift+h exec psos help + bindsym $mod+F2 exec firefox + bindsym $mod+F3 exec $term -e vifm bindsym $mod+Shift+F3 exec gksu $term -e vifm + bindsym $mod+F4 exec nautilus -w bindsym $mod+Shift+F4 exec signal-desktop --use-tray-icon -bindsym $mod+F5 exec $term -e 'mocp -C $XDG_CONFIG_DIR/mocp/config' -bindsym $mod+Shift+m exec mu -bindsym $mod+Shift+h exec xdg-open /usr/share/doc/manjaro/i3_help.pdf -# Screenshofts +bindsym $mod+Shift+m exec qMasterPassword + +# Screenshots and screen recordings bindsym $mod+Ctrl+p exec grim -g "$(slurp -d -b \#ffffff11)" ~/Pictures/Screenshots/$(date +%Y%m%d_%Hh%Mm%Ss)_grim.png bindsym $mod+Shift+p exec grim ~/Pictures/Screenshots/$(date +%Y%m%d_%Hh%Mm%Ss)_grim.png bindsym $mod+Ctrl+f exec "( pkill flameshot || true && flameshot & ) && ( sleep 0.5s && flameshot gui )" +bindsym $mod+Ctrl+r exec record-screen + # Launcher set $menu exec alacritty --class launcher -e env TERMINAL_COMMAND="alacritty -e" sway-launcher bindsym $mod+Space exec $menu diff --git a/modules/sway/config/config.nix b/modules/sway/config/config.nix index 8e21ec02..2375d616 100644 --- a/modules/sway/config/config.nix +++ b/modules/sway/config/config.nix @@ -50,7 +50,7 @@ floating_modifier $mod normal # Reload the configuration file - bindsym $mod+Ctrl+r reload + bindsym $mod+F5 reload # # Moving around: diff --git a/modules/sway/default.nix b/modules/sway/default.nix index 35013dd2..b8abb402 100644 --- a/modules/sway/default.nix +++ b/modules/sway/default.nix @@ -77,6 +77,7 @@ in swaylock-bg sway-launcher + record-screen import-gtk-settings s wcwd diff --git a/pkgs/default.nix b/pkgs/default.nix index ecac30a3..6d392772 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -9,6 +9,7 @@ with final; { mopidy-jellyfin = import ./mopidy-jellyfin.nix final; mu = writeShellScriptBin "mu" (import ./mu.nix final); psos = writeShellScriptBin "psos" (import ./psos.nix final); + psos-docs = import ./psos-docs.nix final; s = writeShellScriptBin "s" (import ./s.nix final); sway-launcher = writeScriptBin "sway-launcher" (import ./sway-launcher.nix final); sway-service = writeShellScriptBin "sway-service" (import ./sway-service.nix final); @@ -17,6 +18,7 @@ with final; { uhk-agent = import ./uhk-agent.nix final; wcwd = writeShellScriptBin "wcwd" (import ./wcwd.nix final); drone-docker-runner = writeShellScriptBin "drone-docker-runner" (import ./drone-docker-runner.nix final); + record-screen = writeShellScriptBin "record-screen" (import ./record-screen.nix final); # ps-fixes } diff --git a/pkgs/psos-docs.nix b/pkgs/psos-docs.nix new file mode 100644 index 00000000..112e39bc --- /dev/null +++ b/pkgs/psos-docs.nix @@ -0,0 +1,26 @@ +self: with self; +stdenv.mkDerivation rec { + pname = "psos-docs"; + version = "0.0.1"; + buildInputs = [ + mdbook + mdbook-pdf + ]; + + src = ../docs/..; # wut + + phases = [ "buildPhase" "installPhase" ]; + + buildPhase = '' + cp -r $src/doc ./doc + cp $src/README.md ./README.md + chmod ug+w -R . + ls -la . + mdbook build doc + ''; + + installPhase = '' + mkdir -p $out/lib/ + cp -r doc/book $out/lib/html + ''; +} diff --git a/pkgs/psos.nix b/pkgs/psos.nix index a60bad6d..eb050bfb 100644 --- a/pkgs/psos.nix +++ b/pkgs/psos.nix @@ -14,6 +14,10 @@ self: with self; '' shift; exec nixos-option -I nixpkgs=/etc/nixos/lib/compat $@ ;; + help) + shift; + exec xdg-open http://help.local/ + ;; *) if [[ "$@" != "" ]]; then echo "Unknown command: psos $@" diff --git a/pkgs/record-screen.nix b/pkgs/record-screen.nix new file mode 100644 index 00000000..d8d7f4a3 --- /dev/null +++ b/pkgs/record-screen.nix @@ -0,0 +1,10 @@ +self: with self; '' + mkdir -p "$HOME/Videos/Screenrecordings" + GEOMETRY="$(slurp -d -b \#ffffff11)" + RESOLUTION="$(echo $GEOMETRY | awk '{print $2}')" + FILE_LOCATION="$HOME/Videos/Screenrecordings/$(${coreutils}/bin/date +%Y%m%d_%Hh%Mm%Ss)_$RESOLUTION.mp4" + echo "Recording $GEOMETRY into $FILE_LOCATION" + ${alacritty}/bin/alacritty \ + --class screen-recorder \ + -e ${wf-recorder}/bin/wf-recorder -g "$GEOMETRY" -f "$FILE_LOCATION" +'' From aabe96a3357e35056f7f5a68f023d10ec820ecfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 18:11:25 +0200 Subject: [PATCH 09/13] Fix hibernation config --- modules/core/boot.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/boot.nix b/modules/core/boot.nix index 6f93fabf..1512289c 100644 --- a/modules/core/boot.nix +++ b/modules/core/boot.nix @@ -38,7 +38,7 @@ in }; }; - resumeDevice = mkIf cfg.core.hibernation.enable "/swapfile"; + resumeDevice = mkIf cfg.hibernation.enable "/swapfile"; loader.systemd-boot.enable = true; From ba6dfdcf533c690333b4fc31e76a41d722b0ff8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 19:48:45 +0200 Subject: [PATCH 10/13] Fix sway mode_system config import --- modules/sway/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sway/default.nix b/modules/sway/default.nix index 469e5cfb..dd0e6055 100644 --- a/modules/sway/default.nix +++ b/modules/sway/default.nix @@ -98,7 +98,7 @@ in xdg.configFile."sway/config.d/theme.conf".source = ./config/config.d/theme.conf; xdg.configFile."sway/config.d/gaps.conf".source = ./config/config.d/gaps.conf; xdg.configFile."sway/config.d/custom-keybindings.conf".source = ./config/config.d/custom-keybindings.conf; - xdg.configFile."sway/config.d/mode_system.conf".text = import ./config/config.d/mode_system.config.nix { inherit psCfg; }; + xdg.configFile."sway/config.d/mode_system.conf".text = import ./config/config.d/mode_system.conf.nix { inherit psCfg; }; xdg.configFile."sway/config.d/applications.conf".source = ./config/config.d/applications.conf; xdg.configFile."sway/config.d/systemd.conf".source = ./config/config.d/systemd.conf; }; From 46992c46d6521dd74c81a937ad1c1465578cbe30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 19:59:01 +0200 Subject: [PATCH 11/13] Add parameter for swapfile offset --- modules/core/boot.nix | 21 +++++++++++- .../sway/config/config.d/mode_system.conf.nix | 32 +++++++++---------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/modules/core/boot.nix b/modules/core/boot.nix index 1512289c..9df859e2 100644 --- a/modules/core/boot.nix +++ b/modules/core/boot.nix @@ -22,6 +22,18 @@ in default = false; description = "Whether the device can hibernate. This creates a swapfile at /swapfile."; }; + + resumeDevice = mkOption { + type = types.str; + default = "/swapfile"; + description = "The location of the hibernation resume swap file."; + }; + + resumeOffset = mkOption { + type = types.nullOr types.number; + default = null; + description = "The swap file offset. Can be found by running `filefrag -v $swap_file_location`. See https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file"; + }; }; config = { @@ -38,7 +50,14 @@ in }; }; - resumeDevice = mkIf cfg.hibernation.enable "/swapfile"; + + resumeDevice = mkIf cfg.hibernation.enable cfg.hibernation.resumeDevice; + kernelParams = mkIf cfg.hibernation.enable [ + "resume=${cfg.hibernation.resumeDevice}" + ] ++ ( + if (cfg.hibernation.resumeOffset == null) then builtins.abort "config.pub-solar.hibernation.resumeOffset has to be set if config.pub-solar.hibernation.enable is true." + else [ "resume_offset=${cfg.hibernation.resumeOffset}" ] + ); loader.systemd-boot.enable = true; diff --git a/modules/sway/config/config.d/mode_system.conf.nix b/modules/sway/config/config.d/mode_system.conf.nix index ef11a461..c505a9f5 100644 --- a/modules/sway/config/config.d/mode_system.conf.nix +++ b/modules/sway/config/config.d/mode_system.conf.nix @@ -1,21 +1,21 @@ { psCfg, ... }: '' -# Set shut down, restart and locking features -set $mode_system (e)xit, (h)ibernate, (r)eboot, (Shift+s)hutdown -bindsym $mod+0 mode "$mode_system" -mode "$mode_system" { - bindsym e exec swaymsg exit, mode "default" -'' + (if !psCfg.core.allow-hibernation then '' - bindsym h exec systemctl hibernate, mode "default" + # Set shut down, restart and locking features + set $mode_system (e)xit, (h)ibernate, (r)eboot, (Shift+s)hutdown + bindsym $mod+0 mode "$mode_system" + mode "$mode_system" { + bindsym e exec swaymsg exit, mode "default" +'' + (if !psCfg.core.hibernation.enable then '' + bindsym h exec systemctl hibernate, mode "default" '' else "") - + (if !psCfg.paranoia.enable then '' - bindsym l exec swaylock-bg, mode "default" - bindsym s exec systemctl suspend, mode "default" ++ (if !psCfg.paranoia.enable then '' + bindsym l exec swaylock-bg, mode "default" + bindsym s exec systemctl suspend, mode "default" '' else "") + '' - bindsym r exec systemctl reboot, mode "default" - bindsym Shift+s exec systemctl poweroff, mode "default" + bindsym r exec systemctl reboot, mode "default" + bindsym Shift+s exec systemctl poweroff, mode "default" - # exit system mode: "Enter" or "Escape" - bindsym Return mode "default" - bindsym Escape mode "default" -} + # exit system mode: "Enter" or "Escape" + bindsym Return mode "default" + bindsym Escape mode "default" + } '' From f9b7c9e3c9181debb9ad6fe944a4bf94a4d0e0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 20:09:38 +0200 Subject: [PATCH 12/13] Fix build --- modules/core/boot.nix | 29 --------------------------- modules/core/default.nix | 1 + modules/core/hibernation.nix | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 modules/core/hibernation.nix diff --git a/modules/core/boot.nix b/modules/core/boot.nix index 9df859e2..10f67dc4 100644 --- a/modules/core/boot.nix +++ b/modules/core/boot.nix @@ -16,26 +16,6 @@ in description = "Whether it should be assumed that there is a cryptroot device"; }; - options.pub-solar.core.hibernation = { - enable = mkOption { - type = types.bool; - default = false; - description = "Whether the device can hibernate. This creates a swapfile at /swapfile."; - }; - - resumeDevice = mkOption { - type = types.str; - default = "/swapfile"; - description = "The location of the hibernation resume swap file."; - }; - - resumeOffset = mkOption { - type = types.nullOr types.number; - default = null; - description = "The swap file offset. Can be found by running `filefrag -v $swap_file_location`. See https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file"; - }; - }; - config = { boot = { # Enable plymouth for better experience of booting @@ -50,15 +30,6 @@ in }; }; - - resumeDevice = mkIf cfg.hibernation.enable cfg.hibernation.resumeDevice; - kernelParams = mkIf cfg.hibernation.enable [ - "resume=${cfg.hibernation.resumeDevice}" - ] ++ ( - if (cfg.hibernation.resumeOffset == null) then builtins.abort "config.pub-solar.hibernation.resumeOffset has to be set if config.pub-solar.hibernation.enable is true." - else [ "resume_offset=${cfg.hibernation.resumeOffset}" ] - ); - loader.systemd-boot.enable = true; # Use latest LTS linux kernel by default diff --git a/modules/core/default.nix b/modules/core/default.nix index 7b168268..80ca4926 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -8,6 +8,7 @@ in { imports = [ ./boot.nix + ./hibernation.nix ./fonts.nix ./i18n.nix ./networking.nix diff --git a/modules/core/hibernation.nix b/modules/core/hibernation.nix new file mode 100644 index 00000000..c0e912f1 --- /dev/null +++ b/modules/core/hibernation.nix @@ -0,0 +1,38 @@ +{ config, pkgs, lib, ... }: +with lib; +let + cfg = config.pub-solar.core.hibernation; +in +{ + options.pub-solar.core.hibernation = { + enable = mkOption { + type = types.bool; + default = false; + description = "Whether the device can hibernate. This creates a swapfile at /swapfile."; + }; + + resumeDevice = mkOption { + type = types.str; + default = "/swapfile"; + description = "The location of the hibernation resume swap file."; + }; + + resumeOffset = mkOption { + type = types.nullOr types.int; + default = null; + description = "The swap file offset. Can be found by running `filefrag -v $swap_file_location`. See https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file"; + }; + }; + + config = { + boot = mkIf cfg.enable { + resumeDevice = cfg.resumeDevice; + kernelParams = [ + "resume=${cfg.resumeDevice}" + ] ++ ( + if (cfg.resumeOffset == null && cfg.enable) then builtins.abort "config.pub-solar.resumeOffset has to be set if config.pub-solar.enable is true." + else [ "resume_offset=${cfg.resumeOffset}" ] + ); + }; + }; +} From c63c3da345aff2bc1239687abc6729b2bf293b75 Mon Sep 17 00:00:00 2001 From: teutat3s Date: Wed, 24 Aug 2022 00:53:38 +0200 Subject: [PATCH 13/13] nix: set nix.package to force overlays/ overrides.nix to apply use nix as default version alias in devshell as well --- modules/core/nix.nix | 2 ++ shell/devos.nix | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/core/nix.nix b/modules/core/nix.nix index 38b70cfc..f7ff5fa4 100644 --- a/modules/core/nix.nix +++ b/modules/core/nix.nix @@ -2,6 +2,8 @@ { nix = { + # Use default version alias for nix package + package = pkgs.nix; # Improve nix store disk usage autoOptimiseStore = true; gc.automatic = true; diff --git a/shell/devos.nix b/shell/devos.nix index bd3399a1..9aefcc6f 100644 --- a/shell/devos.nix +++ b/shell/devos.nix @@ -6,7 +6,7 @@ let cachix editorconfig-checker mdbook - nixUnstable + nix nixpkgs-fmt nvfetcher ;