Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dunst service #58209

Closed
wants to merge 1 commit into from
Closed

Add dunst service #58209

wants to merge 1 commit into from

Conversation

xaverdh
Copy link
Contributor

@xaverdh xaverdh commented Mar 24, 2019

Motivation for this change

This is a fresh attempt at implementing #19183

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@xaverdh xaverdh requested a review from infinisil as a code owner March 24, 2019 15:11
@GrahamcOfBorg GrahamcOfBorg added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Mar 24, 2019
@infinisil
Copy link
Member

Good candidate for NixOS/rfcs#42

@xaverdh xaverdh force-pushed the dunst-config branch 3 times, most recently from aed0ede to 7a1a0b6 Compare March 25, 2019 17:47
@xaverdh
Copy link
Contributor Author

xaverdh commented Mar 25, 2019

Good candidate for NixOS/rfcs#42

Yes, the rules part is probably too verbose. I wanted to internalize it more, in order to check for naming conflicts with official section names. But I agree, there is no need to go that deep into individual options for that.
Ok, I simplified this somewhat. It no longer references individual options.

@xaverdh
Copy link
Contributor Author

xaverdh commented Mar 25, 2019

Other changes:

  • Use writeText instead of toFile to allow e.g. rules to reference storepaths properly.
  • Don't add the wrapper to systemPackages by default

I still have some problem with running scripts from the systemd services context though. that was just me being stupid..


globalConfig = mkOption {
type = types.nullOr (types.attrsOf types.string);
default = null;
Copy link
Member

Choose a reason for hiding this comment

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

Why not

type = with types; attrsOf str;
default = { };

Anyway, use types.str because

# Deprecated; should not be used because it quietly concatenates
# strings, which is usually not what you want.
string = separatedString "";


options.services.dunst = {

enable = mkOption {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
enable = mkOption {
enable = mkEnableOption {

@xaverdh
Copy link
Contributor Author

xaverdh commented Jun 15, 2019

I pushed some changes to use the upstream systemd unit file.

@ofborg ofborg bot added 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux and removed 10.rebuild-linux: 1-10 labels Jun 15, 2019
@aanderse
Copy link
Member

ping (triage)

@xaverdh
Copy link
Contributor Author

xaverdh commented Jul 16, 2019

Reading this code again after some time, I wonder if that is the right way to create the wrapper.
The problem was/is I think, that there is no sane way to reuse the upstream service file without overriding the original dunst derivation. If someone has a suggestion how to do this properly, I would very much like to hear it.

@xaverdh
Copy link
Contributor Author

xaverdh commented Jul 16, 2019

Ok, I have an alternative implementation here using symlinkJoin (similar to how the sway and way-cooler modules do things). But at the cost of not being able to reuse the upstream systemd service file.

@aanderse
Copy link
Member

@xaverdh Well it looks like you have satisfied every request in the review of this PR so far... so let us know when you make up your mind because from skimming the comments in this PR I think a merge is in order 😄

@xaverdh
Copy link
Contributor Author

xaverdh commented Jul 17, 2019

Ok, lets merge this as is then. The implementation can still be switched later on.

@aanderse
Copy link
Member

(triage) @dotlambda From the comments it looks like final word is yours. Please merge if you are satisfied.

dunst-wrapper = pkgs.dunst.overrideAttrs (oldAttrs: {
postInstall = oldAttrs.postInstall + ''
wrapProgram $out/bin/dunst \
--add-flags ${escapeShellArg wrapper-args}
Copy link
Member

Choose a reason for hiding this comment

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

All this trouble can be avoided by changing the services ExecStart somehow like this: systemd.user.services.dunst.serviceConfig.ExecStart = "${pkgs.dunst}/bin/dunst -config ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That actually leads to two ExecStart directives in the service file.

Copy link
Member

Choose a reason for hiding this comment

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

Then you can use e.g. mkOverride 900 on this entry to override the other

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't work either. Maybe because I am using the upstream service file with systemd.packages ?

Copy link
Member

Choose a reason for hiding this comment

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

Ahh right. it's a bit ugly but give ExecStart = [ "" "${pkgs.dunst... a try

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That worked, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But the socket activation seems broken with this approach somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it.

nixos/modules/services/x11/dunst.nix Show resolved Hide resolved
'';
});

environment.systemPackages = [ dunst-wrapper ];
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed?

in mkIf cfg.enable {

assertions = flip mapAttrsToList cfg.rules (name: conf: {
assertion = ! ( any (ruleName: ruleName == name) reservedSections );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assertion = ! ( any (ruleName: ruleName == name) reservedSections );
assertion = ! elem name reservedSections;

};

extraCliOptions = mkOption {
type = types.str;
Copy link
Member

Choose a reason for hiding this comment

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

I recommend types.listOf types.str, which is better for escaping

urgency_critical = cfg.urgencyConfig.critical;
} // cfg.rules;

iconPath = builtins.concatStringsSep ":" cfg.iconDirs;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
iconPath = builtins.concatStringsSep ":" cfg.iconDirs;
iconPath = concatStringsSep ":" cfg.iconDirs;

nixos/modules/services/x11/dunst.nix Show resolved Hide resolved
reservedSections = [
"global" "experimental" "frame" "shortcuts"
"urgency_low" "urgency_normal" "urgency_critical"
];
Copy link
Member

Choose a reason for hiding this comment

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

If you put this at the top of the module, you can reuse this list in the description for rules

@xaverdh
Copy link
Contributor Author

xaverdh commented Aug 9, 2019

Thanks to Infinisil for the extensive review!
I pushed some changes to apply most of your suggestions.


iconPath = concatStringsSep ":" cfg.iconDirs;

dunst-args = "-config ${pkgs.writeText "dunstrc" dunstConfig} -icon_path ${iconPath} ${concatStringsSep " " cfg.extraCliOptions}";
Copy link
Member

Choose a reason for hiding this comment

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

This should then be

{
   dunstArgs = [
     "-config" (pkgs.writeText "dunstrc" dunstConfig)
     "-icon_path" iconPath
   ] ++ extraCliOptions;
}

And you can use escapeShellArgs dunstArgs in the ExecStart

'';
};

extraCliOptions = mkOption {
Copy link
Member

Choose a reason for hiding this comment

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

I suggest renaming this to either extraArgs or extraOptions since this is a more common name for this

type = with types; listOf str;
default = [];
description = ''
This gets appended verbatim to the command line of dunst.
Copy link
Member

Choose a reason for hiding this comment

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

I suggest something like "Extra command line options for dunst" (describing what it is, not what it gets used for/does). Same for the other options

@xaverdh xaverdh force-pushed the dunst-config branch 4 times, most recently from 46d0a22 to 62f76b6 Compare August 9, 2019 18:35
@rnhmjoj
Copy link
Contributor

rnhmjoj commented Sep 10, 2019

Status? Can we get this ready in time for 19.09?

@lheckemann lheckemann added this to the 20.03 milestone Sep 10, 2019
'';
};

urgencyConfig = {
Copy link
Member

Choose a reason for hiding this comment

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

I would really like examples for this config

@disassembler disassembler modified the milestones: 20.03, 20.09 Feb 5, 2020
@dmrauh
Copy link
Contributor

dmrauh commented Jun 18, 2020

Are there any news regarding this PR's status? I'm really interested in this service 😀

systemd.user.services.dunst.serviceConfig.ExecStart = [ "" "${pkgs.dunst}/bin/dunst ${escapeShellArgs dunst-args}" ];
# [ "" ... ] is needed to overwrite the ExecStart directive from the upstream service file

systemd.packages = [ pkgs.dunst ];
Copy link
Member

Choose a reason for hiding this comment

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

Does it need to be installed for the user?

@JohnAZoidberg
Copy link
Member

It would be good if somebody could try to see if it works how they expect.

And check whether we should add some default config or at least more examples.
Upstream has a big default config file with lots of explanations: https://github.com/dunst-project/dunst/blob/master/dunstrc

@ryantm ryantm added the 2.status: merge conflict This PR has merge conflicts with the target branch label Oct 3, 2020
@FRidh FRidh modified the milestones: 20.09, 21.03 Dec 20, 2020
@RocketPuppy RocketPuppy mentioned this pull request Feb 6, 2021
10 tasks
@RocketPuppy
Copy link
Contributor

RocketPuppy commented Feb 6, 2021

I'd really like to get this in, so I picked this up and added some defaults, examples, and fixed merge conflict here: #112100

@xaverdh
Copy link
Contributor Author

xaverdh commented Feb 6, 2021

closed in favor of #112100

@xaverdh xaverdh closed this Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.