Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/common/services/power.nix
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ in

allowSuspend = mkOption {
type = types.bool;
default = config.ghaf.profiles.graphics.allowSuspend;
defaultText = "config.ghaf.profiles.graphics.allowSuspend";
default = true;
description = ''
Whether to allow the system to suspend. This is enabled if the option config.ghaf.profiles.graphics.allowSuspend is set.
Whether to enable system suspension.

If disabled, the system will not respond to suspend requests, and all VMs with a power management profile enabled are
prohibited to perform any suspend action.
'';
Expand Down
24 changes: 21 additions & 3 deletions modules/desktop/graphics/cosmic/config/cosmic-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
lib,
pkgs,
secctx,
idle ? {
screenOffTime = 5 * 60 * 1000;
suspendOnBattery = 15 * 60 * 1000;
suspendOnAC = 15 * 60 * 1000;
},
topPanelApplets ? {
left = [ ];
center = [ ];
Expand Down Expand Up @@ -99,6 +104,15 @@ let
''
);

idleConfig =
builtins.mapAttrs
(name: value: pkgs.writeText name (if value == 0 then "None" else "Some(${toString value})"))
{
screen_off_time = idle.screenOffTime;
suspend_on_battery_time = idle.suspendOnBattery;
suspend_on_ac_time = idle.suspendOnAC;
};

ghaf-volume = pkgs.writeShellApplication {
name = "ghaf-volume";

Expand Down Expand Up @@ -194,6 +208,12 @@ pkgs.stdenv.mkDerivation {

install -Dm0644 ${securityContextConfig} $out/share/cosmic/com.system76.CosmicComp/v1/security_context
''
+ lib.concatStringsSep "\n" (
lib.mapAttrsToList (n: v: ''
install -Dm0644 ${v} \
$out/share/cosmic/com.system76.CosmicIdle/v1/${n}
'') idleConfig
)
+ ''
install -Dm0644 ${topPanelAppletsCenterConfig} $out/share/cosmic/com.system76.CosmicPanel.Panel/v1/plugins_center
install -Dm0644 ${topPanelAppletsWingsConfig} $out/share/cosmic/com.system76.CosmicPanel.Panel/v1/plugins_wings
Expand Down Expand Up @@ -237,9 +257,7 @@ pkgs.stdenv.mkDerivation {
postInstall = ''
substituteInPlace $out/share/cosmic/com.system76.CosmicSettings.Shortcuts/v1/system_actions \
--replace-fail 'VolumeLower: ""' 'VolumeLower: "${lib.getExe ghaf-volume} down"' \
--replace-fail 'VolumeRaise: ""' 'VolumeRaise: "${lib.getExe ghaf-volume} up"' \
--replace-fail 'BrightnessUp: ""' 'BrightnessUp: "${lib.getExe pkgs.brightnessctl} set +5% > /dev/null 2>&1"' \
--replace-fail 'BrightnessDown: ""' 'BrightnessDown: "${lib.getExe pkgs.brightnessctl} set 5%- > /dev/null 2>&1"'
--replace-fail 'VolumeRaise: ""' 'VolumeRaise: "${lib.getExe ghaf-volume} up"'
''
+ lib.optionalString (extraShortcuts != [ ]) ''
if [ -f "$out/share/cosmic/com.system76.CosmicSettings.Shortcuts/v1/defaults" ]; then
Expand Down
10 changes: 8 additions & 2 deletions modules/desktop/graphics/cosmic/config/cosmic-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,11 @@ com.system76.CosmicSettings.Shortcuts:
/// Opens the application library
AppLibrary: "cosmic-app-library",
/// Decreases screen brightness
BrightnessDown: "",
BrightnessDown: "busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon DecreaseDisplayBrightness",
/// Increases screen brightness
BrightnessUp: "",
BrightnessUp: "busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon IncreaseDisplayBrightness",
/// Toggles display mode
DisplayToggle: "cosmic-osd display",
/// Switch between input sources
InputSourceSwitch: "busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon InputSourceSwitch",
/// Opens the home folder in a system default file browser
Expand Down Expand Up @@ -366,6 +368,10 @@ com.system76.CosmicSettings.Shortcuts:
PowerOff: "cosmic-osd shutdown",
/// Takes a screenshot
Screenshot: "cosmic-screenshot",
/// Suspend the system
Suspend: "systemctl suspend",
/// Toggles the screen reader
ScreenReader: "busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon ScreenReader",
/// Opens the system default terminal
Terminal: "cosmic-term",
/// Toggles touchpad on/off
Expand Down
80 changes: 41 additions & 39 deletions modules/desktop/graphics/cosmic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ let
cfg = config.ghaf.graphics.cosmic;
graphicsProfileCfg = config.ghaf.profiles.graphics;

ghaf-powercontrol = pkgs.ghaf-powercontrol.override { ghafConfig = config.ghaf; };

ghaf-cosmic-config = import ./config/cosmic-config.nix {
inherit lib pkgs;
inherit (cfg) topPanelApplets bottomPanelApplets;
idle =
let
ms = v: if cfg.idleManagement.enable then v * 1000 else 0;
in
{
screenOffTime = ms cfg.idleManagement.screenOffTime;
suspendOnBattery = ms cfg.idleManagement.suspendOnBattery;
suspendOnAC = ms cfg.idleManagement.suspendOnAC;
};
secctx = cfg.securityContext;
extraShortcuts = lib.optionals cfg.screenRecorder.enable [
{
Expand All @@ -50,17 +57,6 @@ let
# The following fixes a cross-compilation issue
inherit (pkgs.buildPackages) papirus-folders;
};

swayidleConfig = ''
timeout ${
toString (builtins.floor (cfg.idleManagement.duration * 0.8))

} '${lib.optionalString graphicsProfileCfg.allowSuspend ''notify-send -a System -u normal -t 10000 -i system "Automatic suspend" "The system will suspend soon due to inactivity.";''} brightnessctl -q -s; brightnessctl -q -m | { IFS=',' read -r _ _ _ brightness _ && [ "''${brightness%\%}" -le 25 ] || brightnessctl -q set 25% ;}' resume "brightnessctl -q -r || brightnessctl -q set 100%"
timeout ${toString cfg.idleManagement.duration} "loginctl lock-session" resume "brightnessctl -q -r || brightnessctl -q set 100%"
${lib.optionalString graphicsProfileCfg.allowSuspend ''timeout ${
toString (builtins.floor (cfg.idleManagement.duration * 3))
} "systemctl suspend"''}
'';
in
{
options.ghaf.graphics.cosmic = {
Expand All @@ -72,16 +68,43 @@ in
default = graphicsProfileCfg.idleManagement.enable;
defaultText = literalExpression "config.ghaf.profiles.graphics.idleManagement.enable";
description = ''
Wether to override cosmic-idle system idle management using swayidle.
Whether to enable idle management.

When enabled, the system will automatically manage screen blanking and suspension
based on user inactivity.

When enabled, swayidle will handle automatic screen dimming, locking, and suspending.
If disabled, the default timeouts will be set to 'Never'.
However, users can still manually configure the settings via COSMIC Settings to override this behavior.

If 'config.ghaf.services.power-manager.allowSuspend' is false, suspension will not occur
regardless of this setting.
'';
};
screenOffTime = mkOption {
type = types.int;
default =
if cfg.idleManagement.enable then
300 # 5 minutes by default
else
0;
description = ''
Time in seconds of inactivity before the screen is turned off and the session is locked.
'';
};
suspendOnBattery = mkOption {
type = types.int;
default = cfg.idleManagement.screenOffTime * 3; # 15 minutes by default
defaultText = literalExpression "config.ghaf.graphics.cosmic.idleManagement.screenOffTime * 3";
description = ''
Time in seconds of inactivity before the system suspends when on battery power.
'';
};
duration = mkOption {
suspendOnAC = mkOption {
type = types.int;
default = 300;
default = cfg.idleManagement.screenOffTime * 3; # 15 minutes by default
defaultText = literalExpression "config.ghaf.graphics.cosmic.idleManagement.screenOffTime * 3";
description = ''
Timeout for idle suspension in seconds.
Time in seconds of inactivity before the system suspends when on AC power.
'';
};
};
Expand Down Expand Up @@ -299,9 +322,6 @@ in
#TEMPLATES=Templates
#DESKTOP=Desktop
'';
}
// lib.optionalAttrs cfg.idleManagement.enable {
"swayidle/config".text = swayidleConfig;
};
};

Expand Down Expand Up @@ -408,24 +428,6 @@ in
Environment = mkIf graphicsProfileCfg.bluetooth.applet.useDbusProxy "DBUS_SYSTEM_BUS_ADDRESS=unix:path=/tmp/dbusproxy_snd.sock";
};
};

swayidle = {
inherit (cfg.idleManagement) enable;
description = "Ghaf system idle handler";
path = with pkgs; [
brightnessctl
systemd
ghaf-powercontrol
libnotify
wlopm
];
serviceConfig = {
Type = "simple";
ExecStart = "${getExe pkgs.swayidle} -w -C /etc/swayidle/config";
};
partOf = [ "cosmic-session.target" ];
wantedBy = [ "cosmic-session.target" ];
};
};

systemd.user.targets.ghaf-session = {
Expand Down
10 changes: 0 additions & 10 deletions modules/microvm/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ let
};
};

# Graphics profiles module
graphics = {
config.ghaf.profiles.graphics = {
inherit (configHost.ghaf.profiles.graphics) allowSuspend;
idleManagement = {
inherit (configHost.ghaf.profiles.graphics.idleManagement) enable;
};
};
};
# Bluetooth module
bluetooth = optionalAttrs cfg.audiovm.audio { config.ghaf.services.bluetooth.enable = true; };

Expand Down Expand Up @@ -255,7 +246,6 @@ in
kernelConfigs.guivm
firmwareModule
qemuModules.guivm
serviceModules.graphics
serviceModules.fprint
serviceModules.yubikey
serviceModules.audit
Expand Down
18 changes: 8 additions & 10 deletions modules/profiles/graphics.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ in
type = types.bool;
default = true;
description = ''
Enable or disable system idle management using swayidle.
Whether to enable idle management.

When enabled, this will handle automatic screen dimming, locking, and suspending.
When enabled, the system will automatically manage screen blanking and suspension
based on user inactivity.

Disabling this option is the same as setting all idle timeouts to '0'.

If 'config.ghaf.services.power-manager.allowSuspend' is false, suspension will not occur
regardless of this setting.
'';
};
};
allowSuspend = mkOption {
type = types.bool;
default = true;
description = ''
Allow the system to suspend. When enabled, the system will suspend via either the suspend icon,
lid close, or button press.
'';
};
autoLogin = {
enable = mkOption {
type = types.bool;
Expand Down
6 changes: 3 additions & 3 deletions modules/profiles/orin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ in
ghaf = {
profiles.graphics = {
enable = true;
idleManagement.enable = false;
# Disable suspend by default, not working as intended
allowSuspend = false;
# Explicitly enable auto-login for Orins
autoLogin = {
enable = true;
Expand All @@ -40,6 +37,9 @@ in
networkManager.applet.enable = false;
};

# Disable suspend by default, not working as intended
services.power-manager.allowSuspend = false;

graphics.cosmic = {
# Crucial for Orin devices to use the correct render device
# Also needs 'mesa' to be in hardware.graphics.extraPackages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"page-display"
"page-input"
"page-region"
# "page-power"
"page-power"
"page-sound"
# "page-users"
"page-legacy-applications"
Expand Down
2 changes: 1 addition & 1 deletion packages/ghaf-powercontrol/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ writeShellApplication {
;;
suspend)
${
if ghafConfig.profiles.graphics.allowSuspend then
if ghafConfig.services.power-manager.allowSuspend then
''
systemctl suspend
''
Expand Down
10 changes: 4 additions & 6 deletions targets/laptop/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ let
ghaf = {
reference.profiles.mvp-user-trial.enable = true;
partitioning.disko.enable = true;
profiles.graphics.idleManagement.enable = false;
profiles.graphics.allowSuspend = false;
services.power-manager.allowSuspend = false;
};
}
]))
Expand Down Expand Up @@ -206,8 +205,7 @@ let
ghaf = {
reference.profiles.mvp-user-trial.enable = true;
partitioning.disko.enable = true;
profiles.graphics.idleManagement.enable = true;
profiles.graphics.allowSuspend = false; # Suspension is broken (SSRCSP-7016)
services.power-manager.allowSuspend = false; # Suspension is broken (SSRCSP-7016)

virtualization.microvm.guivm.extraModules = [
{
Expand All @@ -233,7 +231,7 @@ let
reference.profiles.mvp-user-trial.enable = true;
partitioning.disko.enable = true;
profiles.graphics.idleManagement.enable = true;
profiles.graphics.allowSuspend = false; # Suspension is broken (SSRCSP-7016)
services.power-manager.allowSuspend = false; # Suspension is broken (SSRCSP-7016)

# Enable storeOnDisk for all VMs
virtualization.microvm.storeOnDisk = true;
Expand Down Expand Up @@ -396,7 +394,7 @@ let
reference.profiles.mvp-user-trial.enable = true;
partitioning.disko.enable = true;
profiles.graphics.idleManagement.enable = true;
profiles.graphics.allowSuspend = false; # Suspension is broken (SSRCSP-7016)
services.power-manager.allowSuspend = false; # Suspension is broken (SSRCSP-7016)

virtualization.microvm.guivm.extraModules = [
{
Expand Down
Loading