From 33befa88a13a7529f5cf75addd2b255bd7482103 Mon Sep 17 00:00:00 2001 From: Anthony Roussel Date: Sun, 15 Feb 2026 21:32:46 +0100 Subject: [PATCH] nixosTests.autosuspend: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/autosuspend.nix | 30 +++++++++++++++++++++++++ pkgs/by-name/au/autosuspend/package.nix | 5 +++++ 3 files changed, 36 insertions(+) create mode 100644 nixos/tests/autosuspend.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 0ad508dd87ec..3432558f8afd 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -257,6 +257,7 @@ in authelia = runTest ./authelia.nix; auto-cpufreq = runTest ./auto-cpufreq.nix; autobrr = runTest ./autobrr.nix; + autosuspend = runTest ./autosuspend.nix; avahi = runTest { imports = [ ./avahi.nix ]; _module.args.networkd = false; diff --git a/nixos/tests/autosuspend.nix b/nixos/tests/autosuspend.nix new file mode 100644 index 000000000000..ef78e3215dc8 --- /dev/null +++ b/nixos/tests/autosuspend.nix @@ -0,0 +1,30 @@ +{ lib, pkgs, ... }: + +{ + name = "autosuspend"; + meta.maintainers = [ lib.maintainers.anthonyroussel ]; + + nodes = { + machine = { + services.autosuspend = { + enable = true; + + settings = { + interval = 5; + idle_time = 5; + suspend_cmd = "${pkgs.coreutils}/bin/touch /tmp/suspended"; + }; + + # Return exit code 1 to trigger suspend + checks.ExternalCommand.command = "exit 1"; + }; + }; + }; + + testScript = '' + start_all() + + machine.wait_for_unit("autosuspend.service") + machine.wait_for_file("/tmp/suspended") + ''; +} diff --git a/pkgs/by-name/au/autosuspend/package.nix b/pkgs/by-name/au/autosuspend/package.nix index f03d0d0e9de0..bc8dfbc8a694 100644 --- a/pkgs/by-name/au/autosuspend/package.nix +++ b/pkgs/by-name/au/autosuspend/package.nix @@ -2,6 +2,7 @@ lib, dbus, fetchFromGitHub, + nixosTests, python3, sphinxHook, withDocs ? true, @@ -87,6 +88,10 @@ python3.pkgs.buildPythonApplication (finalAttrs: { "test_multiple_sessions" ]; + passthru.tests = { + inherit (nixosTests) autosuspend; + }; + meta = { description = "Daemon to automatically suspend and wake up a system"; homepage = "https://autosuspend.readthedocs.io";