diff --git a/flake.nix b/flake.nix index e69dde9..84253a3 100644 --- a/flake.nix +++ b/flake.nix @@ -146,6 +146,7 @@ homes.modules = with inputs; [ impermanence.homeManagerModules.impermanence + nix-flatpak.homeManagerModules.nix-flatpak ]; templates = import ./templates {}; diff --git a/homes/x86_64-linux/andrej/default.nix b/homes/x86_64-linux/andrej/default.nix index 449e71f..2bf4991 100644 --- a/homes/x86_64-linux/andrej/default.nix +++ b/homes/x86_64-linux/andrej/default.nix @@ -13,6 +13,9 @@ in { custom = { programs.librewolf.enable = true; }; + services.flatpak.packages = [ + "org.vinegarhq.Sober" + ]; home = { packages = with pkgs; [ zapzap diff --git a/modules/nixos/hardware/framework12/default.nix b/modules/nixos/hardware/framework12/default.nix index 64c078c..b927248 100644 --- a/modules/nixos/hardware/framework12/default.nix +++ b/modules/nixos/hardware/framework12/default.nix @@ -19,11 +19,14 @@ in { enable = mkBoolOpt false "Enable hardware support for framework 12. P.s. you still need to import inputs.nixos-hardware.nixosModules.framework-12-13th-gen-intel yourself"; }; config = mkIf cfg.enable { - ${namespace}.hardware.battery = { - enable = true; - batteryName = "BAT1"; - remainingEnergy = "charge_now"; - powerUsage = "current_now"; + ${namespace}.hardware = { + tablet.enable = true; + battery = { + enable = true; + batteryName = "BAT1"; + remainingEnergy = "charge_now"; + powerUsage = "current_now"; + }; }; # Ensure that the `pinctrl_tigerlake` kernel module is loaded before `soc_button_array`. # This is required for correcly switching to tablet mode when the display is folded back. diff --git a/modules/nixos/hardware/tablet/default.nix b/modules/nixos/hardware/tablet/default.nix new file mode 100644 index 0000000..f2daa9c --- /dev/null +++ b/modules/nixos/hardware/tablet/default.nix @@ -0,0 +1,88 @@ +{ + lib, + pkgs, + inputs, + namespace, + system, + target, + format, + virtual, + systems, + config, + ... +}: +with lib; +with lib.${namespace}; let + cfg = config.${namespace}.hardware.tablet; +in { + options.${namespace}.hardware.tablet = with types; { + enable = mkBoolOpt false "Enable tablet module for hardware that supports it"; + path = mkOpt path "/run/tablet-mode-state" "Path with a file, where it's stated, whether tablet mode 'on' or 'off'"; + inputDevice = mkOpt' str "/dev/input/event4"; + onTabletModeEnable = mkOpt (listOf (attrsOf str)) [] "Actions to do when entering tablet mode"; + onTabletModeDisable = mkOpt (listOf (attrsOf str)) [] "Actions to do when exiting tablet mode"; + }; + + config = mkIf cfg.enable { + # 1. System service for watching + systemd.services = + { + tablet-mode-watcher = { + description = "Watch for tablet mode changes"; + serviceConfig = { + ExecStart = "${pkgs.writeShellScript "tablet-mode-eventd" '' +in_tablet_mode=$(${pkgs.coreutils}/bin/cat "${cfg.path}" 2>/dev/null || $(echo 0 > "${cfg.path}" && echo 0)) + +stdbuf -oL -eL ${lib.getExe pkgs.libinput} debug-events --device "${cfg.inputDevice}" | while read -r line; do + if [[ "$line" =~ switch\ tablet-mode\ state\ ([01]) ]]; then + d="''${BASH_REMATCH[1]}" + if [ "$d" -ne "$in_tablet_mode" ]; then + in_tablet_mode=$d + if [ "$d" -eq 1 ]; then + systemctl start tablet-on.target + echo "Tablet mode ON" + echo 1 > "${cfg.path}" + else + systemctl start tablet-off.target + echo "Tablet mode OFF" + echo 0 > "${cfg.path}" + fi + fi + fi +done + ''}"; + Restart = "always"; + }; + wantedBy = ["graphical.target"]; + }; + } + // (lib.listToAttrs (map (cmd: { + name = "tablet-action-on-${cmd.name}"; + value = { + Unit.PartOf = ["tablet-on.target"]; + Service = { + Type = "oneshot"; + ExecStart = "sh -c ${cmd.command}"; + }; + Install.WantedBy = ["tablet-on.target"]; + }; + }) + cfg.onTabletModeEnable)) + // (lib.listToAttrs (map (cmd: { + name = "tablet-action-off-${cmd.name}"; + value = { + Unit.PartOf = ["tablet-off.target"]; + Service = { + Type = "oneshot"; + ExecStart = "sh -c ${cmd.command}"; + }; + Install.WantedBy = ["tablet-off.target"]; + }; + }) + cfg.onTabletModeDisable)); + + # 2. System targets + systemd.targets.tablet-on = {}; + systemd.targets.tablet-off = {}; + }; +} diff --git a/systems/x86_64-linux/kylekrein-framework12/default.nix b/systems/x86_64-linux/kylekrein-framework12/default.nix index 630e440..dc0cd34 100644 --- a/systems/x86_64-linux/kylekrein-framework12/default.nix +++ b/systems/x86_64-linux/kylekrein-framework12/default.nix @@ -57,6 +57,7 @@ in }; environment.systemPackages = with pkgs; [ blender + video-downloader ]; #Chat host networking.firewall.allowedTCPPorts = [80 443 22 8448 9993 8081];