From ac16cc25c6151f9f90fff440f8dd9a5343b438f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Schwarz=C3=A4ugl?= Date: Sat, 11 Oct 2025 14:25:28 +0200 Subject: [PATCH] autotiling: init module --- .../misc/news/2025/10/2025-10-11_14-06-00.nix | 9 +++ modules/services/autotiling.nix | 70 +++++++++++++++++++ tests/flake.lock | 27 +++++++ .../autotiling/autotiling-basic-config.nix | 40 +++++++++++ tests/modules/services/autotiling/default.nix | 5 ++ 5 files changed, 151 insertions(+) create mode 100644 modules/misc/news/2025/10/2025-10-11_14-06-00.nix create mode 100644 modules/services/autotiling.nix create mode 100644 tests/flake.lock create mode 100644 tests/modules/services/autotiling/autotiling-basic-config.nix create mode 100644 tests/modules/services/autotiling/default.nix diff --git a/modules/misc/news/2025/10/2025-10-11_14-06-00.nix b/modules/misc/news/2025/10/2025-10-11_14-06-00.nix new file mode 100644 index 000000000..441794242 --- /dev/null +++ b/modules/misc/news/2025/10/2025-10-11_14-06-00.nix @@ -0,0 +1,9 @@ +{ pkgs, ... }: +{ + time = "2025-10-11T14:06:00+00:00"; + condition = pkgs.stdenv.hostPlatform.isLinux; + message = '' + A new service is available: 'services.autotiling'. + autotiling is a script for Sway and i3 to automatically switch the horizontal / vertical window split orientation. + ''; +} diff --git a/modules/services/autotiling.nix b/modules/services/autotiling.nix new file mode 100644 index 000000000..8a931ec37 --- /dev/null +++ b/modules/services/autotiling.nix @@ -0,0 +1,70 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + inherit (lib) + mkOption + types + ; + + cfg = config.services.autotiling; + +in +{ + meta.maintainers = [ lib.hm.maintainers.swarsel ]; + + options.services.autotiling = { + enable = lib.mkEnableOption "enable autotiling service"; + package = lib.mkPackageOption pkgs "autotiling" { }; + + extraArgs = mkOption { + type = with types; listOf str; + default = [ ]; + example = [ + "--workspaces" + "8" + "9" + ]; + description = '' + Extra arguments to pass to autotiling. + ''; + }; + + systemdTarget = mkOption { + type = types.str; + default = "graphical-session.target"; + description = '' + Systemd target to bind to. + ''; + }; + + }; + + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.autotiling" pkgs lib.platforms.linux) + ]; + + systemd.user.services.autotiling = { + Unit = { + Description = "Split orientation manager"; + PartOf = [ cfg.systemdTarget ]; + After = [ cfg.systemdTarget ]; + }; + + Service = { + Type = "simple"; + Restart = "always"; + ExecStart = "${lib.getExe cfg.package} ${lib.escapeShellArgs cfg.extraArgs}"; + }; + + Install = { + WantedBy = [ cfg.systemdTarget ]; + }; + }; + }; +} diff --git a/tests/flake.lock b/tests/flake.lock new file mode 100644 index 000000000..a96353867 --- /dev/null +++ b/tests/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1760038930, + "narHash": "sha256-Oncbh0UmHjSlxO7ErQDM3KM0A5/Znfofj2BSzlHLeVw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0b4defa2584313f3b781240b29d61f6f9f7e0df3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/tests/modules/services/autotiling/autotiling-basic-config.nix b/tests/modules/services/autotiling/autotiling-basic-config.nix new file mode 100644 index 000000000..317ad4fe5 --- /dev/null +++ b/tests/modules/services/autotiling/autotiling-basic-config.nix @@ -0,0 +1,40 @@ +{ config, ... }: + +{ + services.autotiling = { + enable = true; + package = config.lib.test.mkStubPackage { outPath = "@autotiling@"; }; + extraArgs = [ + "--outputs" + "DP-1" + "--workspaces" + "8" + "9" + "--limit" + "2" + ]; + }; + + nmt.script = '' + serviceFile=home-files/.config/systemd/user/autotiling.service + + assertFileExists "$serviceFile" + + serviceFileNormalized="$(normalizeStorePaths "$serviceFile")" + + assertFileContent "$serviceFileNormalized" ${builtins.toFile "expected.service" '' + [Install] + WantedBy=graphical-session.target + + [Service] + ExecStart=@autotiling@/bin/dummy --outputs DP-1 --workspaces 8 9 --limit 2 + Restart=always + Type=simple + + [Unit] + After=graphical-session.target + Description=Split orientation manager + PartOf=graphical-session.target + ''} + ''; +} diff --git a/tests/modules/services/autotiling/default.nix b/tests/modules/services/autotiling/default.nix new file mode 100644 index 000000000..0a2ef0108 --- /dev/null +++ b/tests/modules/services/autotiling/default.nix @@ -0,0 +1,5 @@ +{ lib, pkgs, ... }: + +lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + autotiling-basic-config = ./autotiling-basic-config.nix; +}