Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

services: addsleepwatcher service#1617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
virusdave wants to merge2 commits intonix-darwin:nix-darwin-25.05
base:nix-darwin-25.05
Choose a base branch
Loading
fromvirusdave:nix-darwin-25.05

Conversation

@virusdave
Copy link
Contributor

@virusdavevirusdave commentedOct 26, 2025
edited
Loading

This service allows specification of user or system scripts to run at various system event moments, such as "system woke from sleep" or "AC power plugged in", etc.

RequiresNixOS/nixpkgs#455927 to be merged (and backported) first.

This service allows specification of user or system scriptsto run at various system event moments, such as "system wokefrom sleep" or "AC power plugged in", etc.RequiresNixOS/nixpkgs#455914 to bemerged first.
@virusdavevirusdave requested a review frombewOctober 30, 2025 18:28
Copy link
Member

@Samasaur1Samasaur1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this should targetmaster instead ofnix-darwin-25.05; it can be backported if desired.

Also I didn't leave this as an inline comment because there wasn't one place to put it, but did you consider making the scripts betypes.lines instead oftypes.nullOr types.lines and checking for"" instead ofnull? I think it would be functionally the same but seems to match our style better.

};
in
{
environment.systemPackages = [ cfg.package ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Doessleepwatcher need to be in the system path? It doesn't seem like this is useful given that the daemon is already running.

bew reacted with thumbs up emoji
{
environment.systemPackages = [ cfg.package ];

launchd.user.agents.sleepwatcher = mkIf (!cfg.run_as_system) launchdConfig;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

User agents in nix-darwin itself need to have amanagedBy attribute so that we can properly display error messages whensystem.primaryUser is unset.

Comment on lines +99 to +107
run_as_system = mkOption {
type = types.bool;
default = false;
description = ''
Whether to run sleepwatcher as a system daemon (true) or user agent (false).
System daemon runs as root and can execute system-level commands.
User agent runs as the user and is preferred for user-specific actions.
'';
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is there any case where the user might want to run both a systemwide and a per-user instance?

Comment on lines +120 to +134
ProgramArguments = [
"${cfg.package}/bin/sleepwatcher"
] ++ optionals cfg.verbose [ "--verbose" ]
++ optionalHook "sleep" cfg.on_sleep
++ optionalHook "wakeup" cfg.on_wakeup
++ optionalHook "displaysleep" cfg.on_display_sleep
++ optionalHook "displaywakeup" cfg.on_display_wakeup
++ optionalHook "displaydim" cfg.on_display_dim
++ optionalHook "displayundim" cfg.on_display_undim
++ optionals (cfg.on_idle != null && cfg.idle_time != null)
([ "--timeout" "${toString cfg.idle_time}" ] ++
(optionalHook "idle" cfg.on_idle))
++ optionalHook "idleresume" cfg.on_idle_resume
++ optionalHook "plug" cfg.on_plug
++ optionalHook "unplug" cfg.on_unplug;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We prefer that you setcommand instead ofserviceConfig.ProgramArguments so that a) the service picks up/bin/wait4path so that it doesn't fail repeatedly and be put in the penalty box when the nix store is not yet mounted; b) future changes to launchd services apply to them as well

Comment on lines +129 to +132
++ optionals (cfg.on_idle != null && cfg.idle_time != null)
([ "--timeout" "${toString cfg.idle_time}" ] ++
(optionalHook "idle" cfg.on_idle))
++ optionalHook "idleresume" cfg.on_idle_resume
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This check checks whethercfg.on_idle is null twice, which seems redundant.

Also, I imaginecfg.on_idle_resume should also be ignored ifcfg.idle_time is unset?

Comment on lines +16 to +20
verbose = mkOption {
type = types.bool;
default = true;
description = "Whether to verbosely log actions performed by sleepwatcher.";
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This option is essentially useless without settingserviceConfig.StandardOutPath and/orserviceConfig.StandardErrorPath on the service itself, as launchd just swallows the logs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'd recommend adding options for these attributes rather than hardcoding them, btw; see some other services that do that.

in optionals (hookValue != null) [ "--${longArg}" "${hookScript}" ];

launchdConfig = {
path = [ config.environment.systemPath ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What's the reasoning behind this as opposed to having people set the PATH individually on each script that needs it set?

@Samasaur1
Copy link
Member

Also note that the homepage for this software says

The options --displaydim, --displayundim, --displaysleep and --displaywakup do not work with Apple silicon Macs, this issue is still under investigation

which should be reflected somewhere in this service, probably in the description for those options.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@Samasaur1Samasaur1Samasaur1 requested changes

@bewbewAwaiting requested review from bew

Requested changes must be addressed to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@virusdave@Samasaur1@bew

[8]ページ先頭

©2009-2025 Movatter.jp