-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
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
nixos/dockd: add new service #49734
nixos/dockd: add new service #49734
Conversation
@GrahamcOfBorg eval |
''; | ||
}; | ||
|
||
dockedConfPath = mkOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate the effort you took to make this configurable, but I don't think it's necessary to maintain this solution. Most services simply define a configuration in etc.
Of course your solution is more powerful, because it allows the possibility to have a mutable config file, but is that worth the overhead of a different solution?
I may well be wrong, because I don't know anything about operating dockd
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comment.
About the configs... dockd has two config files
-
The
docked.conf
this file has to be writable to be set withdockd --config docked
(executed by the user running under the graphical session), this command captures the current monitor/screens configuration inxrandr
and create an ini file with those values. (on a predefined location hard coded in the executable) -
The
undocked.conf
this file has to be writable to be set withdockd --config undocked
(executed by the user running under the graphical session), this command captures the current monitor/screens configuration inxrandr
and create an ini file with those values (on a predefined location hard coded in the executable). Basically this is the same as (1) but the result will be written into another path.
And two hooks/executables:
-
The
dock.hook
script/executable, it will be executed when the laptop gets removed from the dock, you can put any arbitrary command in this file. -
The
undock.hook
script/executable, it will be executed when the laptop gets removed from the dock, you can put any arbitrary command in this file.
I'm not familiar with the options to manage an etc file.. but that seems like a potential good solution, the only problem is that, if you want to change the configuration (dockd --config docked|undocked
) the user would need to copy those new values into the configuration.nix
otherwise the changes will be overridden on the next nixos-rebuild
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's more of configuration management tool. That makes sense. Could you add this information in the option descriptions?
pkgs.dockd.override { | ||
inherit (cfg) dockedConfPath undockedConfPath; | ||
dockHookPath = (if cfg.dockHook != "" | ||
then pkgs.writeScript "dock.hook" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 yeah
then pkgs.writeScript "undock.hook" cfg.undockHook | ||
else cfg.undockHookPath); | ||
}; | ||
in mkIf cfg.enable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add two assertions that check that only one of undockHook
and undockHookPath
(and some for dock
) is set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, intended to add the link https://nixos.org/nixos/manual/index.html#sec-assertions-assertions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really appreciate the effort you put into improving the module, but it seems that some things are a bit more complicated than necessary now.
It'd be really nice if you could explain the two modes of operation (mutable/immutable) for this module and what the implications are.
Path to the executable to run when the ThinkPad is placed on the dock. | ||
If set, make sure the file exists and is executable by the user of the session. | ||
|
||
Example: "/etc/dockd/dock.hook" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For examples, you can use a mkOption
argument attribute like example = "/etc/dockd/dock.hook";
undockHook = if cfg.undockHook == null then "exit 0" else cfg.undockHook; | ||
inherit(pkgs) writeScript; | ||
in | ||
pkgs.dockd.override { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to build the package differently based on configuration? This is generally not needed and will cause user systems to download the build dependencies and build the package unnecessarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that the real fix needs to be addressed in the upstream project. The path to the executable is hard-coded in the cpp source code https://github.com/libthinkpad/dockd/blob/master/hooks.cpp. And the hack that this package does is to patch the source code to replace the hard-coded path to the one specified in the dockd package. The "improvement" is that if you want, you can have a script also in the nix store or in any other place in the system not just /etc/dockd/{dock,undock}.hook
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I though the patch was to replace it with getenv
but I must have been thinking about another package. Sorry about that. Using getenv
would be an improvement, but considering the relative importance and size of dockd
, I think your solution is already sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using getenv
might be a better idea 🤔 . I'll consider it this weekend. Thanks again.
# set to null, specified that the user is not interested on doing nothing | ||
# with the hooks | ||
let | ||
dockHook = if cfg.dockHook == null then "exit 0" else cfg.dockHook; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty string is a perfectly fine script, equivalent to exit 0
, so you don't need to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also means you can simplify the type to disallow null
again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The need to have null
there as a valid option, was because I wanted to distinguish between an explicit null
to intent "I don't care" and a string. But yes, I can just remove the possibility for null
. Originally I added that because if I didn't provide a default it would cause some issues on my if
expressions when deciding on using the xHookPath
vs xHook
. Issues about the attribute not existing, even if the assertions that I made should have "prevented" that situation, but apparently the evaluation of the asserts are not done prior the full evaluation.... Anyway, I agree I can make it simpler.
# verify that only one of (dockHook | dockHookPath) is defined | ||
{ | ||
assertion = | ||
if ((cfg.dockHook != null && cfg.dockHook != "") && (cfg.dockHookPath != "")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to assertion = dockHook == "" || dockHookPath == "";
(same for undock)
(removing null as suggested and simplify)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the original approach, but changed because of the idea of null
intending "I don't care" and a string that you want to evaluate this as a script. I can make as it was before.
{ | ||
assertion = | ||
if cfg.dockHookPath != "" then | ||
(builtins.pathExists cfg.dockHookPath) else true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builtins.pathExists
will check the path on the machine that evaluates the configuration, which may not be the machine that runs the configuration.
This would break for example a setup where a company has CI for its fleet of laptops. Also, it doesn't work in restrict-eval
enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 yeah, I never considered that when I added this assertion.
@roberth I can simplify the expression, but getting back to the idea of adding |
Thanks :) |
Are there any updates on this pull request, please? |
@mmahut I'm no longer using NixOS in the particular thinkpad where Also the upstream Still, I can put the work on a additional overlay to be included by those who don't really care about anything and just enjoy the pleasures of automatically adjust into the additional monitors when is docked. With enough 👏s and 🎉s I can make it happen. @roberth would it be better if I just close this PR? To at least make it |
Hey @cyraxjoe, |
Thank you for your contributions.
|
Motivation for this change
Adds the dockd service for nixos and all the dependencies, libthinkpad and the daemon itself "dockd".
Dockd is a dock management daemon for the Lenovo Thinkpads, very helpful if you are running minimal wm, like i3. It allows you to configure for example, a set of multiple monitors when you dock you laptop.
https://github.com/libthinkpad/dockd
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)