-
-
Notifications
You must be signed in to change notification settings - Fork 482
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 git, gnutar and gzip to lorri's path #242
Conversation
Hmm, seems like this got lost in #222 (comment). Looks good if you take a look at the test. |
got it! |
tests/services-lorri.nix
Outdated
@@ -6,11 +6,19 @@ let | |||
actual = pkgs.runCommand "convert-plist-to-json" { buildInputs = [ pkgs.xcbuild ]; } | |||
"plutil -convert json -o $out ${plistPath}"; | |||
actualJson = builtins.fromJSON (builtins.readFile "${actual.out}"); | |||
expectedPathItems = map (x: "${x}/bin") |
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'm not sure if this is the best way to get this done, I'm still learning nix
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, this test is is a bit overly specific.
No need to discard the string context tho since the packages will be referenced by the build anyway. To get rid of the dependencies in the test an overlay is needed in this case, but unlike eg. lorri they're pretty standard in this case so it's not a big deal. I mostly use this to avoid having to download a bunch of unnecessary stuff for the tests or in case the package in nixpkgs breaks I don't really want that to influence these tests.
{
nixpkgs.overlays = [
(self: super:
{
git = super.runCommand "git-0.0.0" {} "mkdir $out";
gnutar = super.runCommand "gnutar-0.0.0" {} "mkdir $out";
gzip = super.runCommand "gzip-0.0.0" {} "mkdir $out";
})
];
}
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.
thanks for the feedback! I tried adding the nixpkgs.overlays
section to the expression at [1] while removing the calls to builtins.unsafeDiscardStringContext
, but I got an error related to tar
[2]. I probably need to place the overlays somewhere else, but I'm a bit lost now.
EDIT: to be clear, this is what tests/services-lorri.nix
looks like after the changes I mentioned: https://github.com/akrmn/nix-darwin/commit/42b0afb59f3c5f60650080fe182a9daebaf3d047#
[1]
nix-darwin/tests/services-lorri.nix
Lines 36 to 42 in ee9e120
{ | |
services.lorri.enable = true; | |
test = '' | |
${pkgs.xcbuild}/bin/plutil -lint ${plistPath} | |
[ ${testResult} ]; | |
''; | |
} |
[2]
builder for '/nix/store/0rz1d1d2qfy17y37gflkp0pswpp565fm-perl-5.32.0.drv' failed with exit code 1; last 4 log lines:
unpacking sources
unpacking source archive /nix/store/bl6b2p0aw8phljjn0s3xzyghbbzawl2r-perl-5.32.0.tar.gz
/nix/store/9zhvxgmqwph7cd2mc9fwg9y39nziqdaz-stdenv-darwin/setup: line 847: tar: command not found
do not know how to unpack source archive /nix/store/bl6b2p0aw8phljjn0s3xzyghbbzawl2r-perl-5.32.0.tar.gz
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 this was more an example for reference. These dependencies specifically are very low level and used by many other things so actually replacing them breaks various things like you noticed.
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.
gotcha! is it fine then to keep the builtins.unsafeDiscardStringContext
calls? is there anything else you'd like to see on this pr?
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.
Oh I see now, this was there already
Exactly, it was there before :)
it's ok to leave that as is if you don't want to spend time on that.
I'm more interested in getting it right :)
Using an attrset instead of going through fromJSON would fix that
However, I got a bit stuck trying to avoid the fromJSON
conversion. If I use an attrset and then convert that with builtins.toJSON
to compare with the actual value, it turns out that the toJSON
conversion only goes one level deep.
simply checking some specific keys in the build with eg. jq
This made me think that perhaps the way is avoiding JSON completely and working directly with the plist, but it seems there's very little support for that. The plutil
command is fairly limited, it seems to lack a simple way to read out a key. I also tried defaults read
, but it doesn't work with nested dictionaries. My last hope was PlistBuddy
, which I learned about online. It seems to be part of macOS but it's absent from the PATH; it needs to be run directly as /usr/libexec/PlistBuddy
. This one is very complete, but I'm not sure if there's a "nix way" to invoke it, and I couldn't find it under pkgs
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 would suggest moving the checks to the build instead like most of the other tests do, but unlike there use the plutil to check specific keys instead just using grep like the other cases do. Checking the entire content is a bit overkill anyway.
So for example something like this:
# ...
{
services.lorri.enable = true;
test = ''
export PATH=${lib.makeBinPath [ pkgs.xcbuild pkgs.jq ]}
plutil -convert json -o service.json ${service}
[ $(jq -r '.ProgramArguments[-1]' service.json) = "exec ${pkgs.lorri}/bin/lorri daemon" ]
'';
}
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.
aha! that makes a lot of sense, thanks! I'll work on it later today
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.
done in d037dfa :) please let me know what you think. Thanks for the help!
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.
That's great, thanks!
When trying to use lorri, I kept getting errors similar to those mentioned by @wentasah on target/lorri#385 (comment). I compared the relevant NixOS setting (shared by @curiousleo here target/lorri#385 (comment)) with the equivalent
darwin-nix
expression and I noticed that the one here lackedgit gnutar gzip
, so I added them.