From 3e32c9874b9cc8a202eae414973d88fe07128a50 Mon Sep 17 00:00:00 2001 From: moons Date: Mon, 27 Jul 2026 16:49:48 +0900 Subject: [PATCH] add apps --- modules/applications/niri/meta.nix | 2 + modules/services/openssh/darwin.nix | 11 +++++ modules/services/openssh/nixos.nix | 12 +++++ modules/services/swayidle/home.nix | 67 +++++++++++++++++++++++++++ modules/services/swayidle/meta.nix | 5 ++ modules/services/tailscale/darwin.nix | 3 ++ modules/services/tailscale/nixos.nix | 11 +++++ modules/systems/wayland/nixos.nix | 32 +++++++++++++ 8 files changed, 143 insertions(+) create mode 100644 modules/services/openssh/darwin.nix create mode 100644 modules/services/openssh/nixos.nix create mode 100644 modules/services/swayidle/home.nix create mode 100644 modules/services/swayidle/meta.nix create mode 100644 modules/services/tailscale/darwin.nix create mode 100644 modules/services/tailscale/nixos.nix create mode 100644 modules/systems/wayland/nixos.nix diff --git a/modules/applications/niri/meta.nix b/modules/applications/niri/meta.nix index dbfd1f1..7385a22 100644 --- a/modules/applications/niri/meta.nix +++ b/modules/applications/niri/meta.nix @@ -2,5 +2,7 @@ { description = "niri Wayland compositor"; + includes = [ "systems.wayland" ]; + imports.nixos = [ inputs.niri-flake.nixosModules.niri ]; } diff --git a/modules/services/openssh/darwin.nix b/modules/services/openssh/darwin.nix new file mode 100644 index 0000000..08ab997 --- /dev/null +++ b/modules/services/openssh/darwin.nix @@ -0,0 +1,11 @@ +{ + services.openssh = { + enable = true; + extraConfig = '' + PermitRootLogin no + PasswordAuthentication no + KbdInteractiveAuthentication no + PubkeyAuthentication yes + ''; + }; +} diff --git a/modules/services/openssh/nixos.nix b/modules/services/openssh/nixos.nix new file mode 100644 index 0000000..233d543 --- /dev/null +++ b/modules/services/openssh/nixos.nix @@ -0,0 +1,12 @@ +{ + services.openssh = { + enable = true; + openFirewall = true; + settings = { + PermitRootLogin = "no"; + PasswordAuthentication = false; + KbdInteractiveAuthentication = false; + PubkeyAuthentication = "yes"; + }; + }; +} diff --git a/modules/services/swayidle/home.nix b/modules/services/swayidle/home.nix new file mode 100644 index 0000000..cddc06e --- /dev/null +++ b/modules/services/swayidle/home.nix @@ -0,0 +1,67 @@ +{ lib, pkgs, ... }: +let + brightnessctl = lib.getExe pkgs.brightnessctl; + niri = lib.getExe pkgs.niri; + rm = "${pkgs.coreutils}/bin/rm"; + systemctl = lib.getExe' pkgs.systemd "systemctl"; + brightnessState = "$XDG_RUNTIME_DIR/swayidle-brightness"; + + skipIfOnAC = '' + for supply in /sys/class/power_supply/*; do + if [ -f "$supply/type" ] \ + && [ "$(< "$supply/type")" = "Mains" ] \ + && [ -f "$supply/online" ] \ + && [ "$(< "$supply/online")" = "1" ]; then + exit 0 + fi + done + ''; + + dimScreen = pkgs.writeShellScript "swayidle-dim-screen" '' + ${skipIfOnAC} + ${brightnessctl} get > "${brightnessState}" 2>/dev/null || exit 0 + ${brightnessctl} set 10% >/dev/null 2>&1 || true + ''; + + restoreBrightness = pkgs.writeShellScript "swayidle-restore-brightness" '' + if [ -f "${brightnessState}" ]; then + saved=$(< "${brightnessState}") + ${brightnessctl} set "$saved" >/dev/null 2>&1 || true + ${rm} -f "${brightnessState}" + fi + ''; + + suspendOnBattery = pkgs.writeShellScript "swayidle-suspend-on-battery" '' + ${skipIfOnAC} + exec ${systemctl} suspend + ''; + + afterResume = pkgs.writeShellScript "swayidle-after-resume" '' + ${niri} msg action power-on-monitors + ${restoreBrightness} + ''; +in +lib.mkIf pkgs.stdenv.hostPlatform.isLinux { + services.swayidle = { + enable = true; + systemdTargets = [ "graphical-session.target" ]; + timeouts = [ + { + timeout = 300; + command = "${dimScreen}"; + resumeCommand = "${restoreBrightness}"; + } + { + timeout = 360; + command = "${suspendOnBattery}"; + } + ]; + events.after-resume = "${afterResume}"; + }; + + systemd.user.services.swayidle.Service.PassEnvironment = [ + "WAYLAND_DISPLAY" + "XDG_RUNTIME_DIR" + "DBUS_SESSION_BUS_ADDRESS" + ]; +} diff --git a/modules/services/swayidle/meta.nix b/modules/services/swayidle/meta.nix new file mode 100644 index 0000000..43176bc --- /dev/null +++ b/modules/services/swayidle/meta.nix @@ -0,0 +1,5 @@ +{ + description = "swayidle idle management for Niri"; + + includes = [ "applications.niri" ]; +} diff --git a/modules/services/tailscale/darwin.nix b/modules/services/tailscale/darwin.nix new file mode 100644 index 0000000..d886410 --- /dev/null +++ b/modules/services/tailscale/darwin.nix @@ -0,0 +1,3 @@ +{ + services.tailscale.enable = true; +} diff --git a/modules/services/tailscale/nixos.nix b/modules/services/tailscale/nixos.nix new file mode 100644 index 0000000..3177bd2 --- /dev/null +++ b/modules/services/tailscale/nixos.nix @@ -0,0 +1,11 @@ +{ + services.tailscale = { + enable = true; + openFirewall = false; + useRoutingFeatures = "client"; + extraSetFlags = [ + "--accept-dns=false" + "--accept-routes=true" + ]; + }; +} diff --git a/modules/systems/wayland/nixos.nix b/modules/systems/wayland/nixos.nix new file mode 100644 index 0000000..a077316 --- /dev/null +++ b/modules/systems/wayland/nixos.nix @@ -0,0 +1,32 @@ +{ pkgs, ... }: +{ + programs.xwayland.enable = true; + + xdg.portal = { + enable = true; + extraPortals = [ + pkgs.xdg-desktop-portal-gnome + pkgs.xdg-desktop-portal-gtk + ]; + xdgOpenUsePortal = true; + config = { + common.default = [ "gtk" ]; + gnome.default = [ + "gnome" + "gtk" + ]; + }; + }; + + environment.variables.NIXOS_OZONE_WL = "1"; + environment.sessionVariables = { + ELECTRON_OZONE_PLATFORM_HINT = "wayland"; + QT_QPA_PLATFORM = "wayland;xcb"; + NIXOS_OZONE_WL = "1"; + }; + + environment.systemPackages = [ + pkgs.xwayland-satellite + pkgs.uwsm + ]; +}