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
Upstream PLIST handling #42669
Upstream PLIST handling #42669
Conversation
This is a good way to test that plist works. Sorry for the large diff. There are a bunch of cleanups in here that needed to be done. Should make it possible to use in cross compilation.
@GrahamcOfBorg build darwin.adv_cmds |
No attempt on x86_64-linux (full log) The following builds were skipped because they don't evaluate on x86_64-linux: darwin.adv_cmds Partial log (click to expand)
|
No attempt on aarch64-linux (full log) The following builds were skipped because they don't evaluate on aarch64-linux: darwin.adv_cmds Partial log (click to expand)
|
Success on x86_64-darwin (full log) Attempted: darwin.adv_cmds Partial log (click to expand)
|
Anyone know of a package that uses xcbuild & works in linux? |
Success on x86_64-darwin (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on x86_64-linux (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on x86_64-linux (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on x86_64-darwin (full log) Attempted: xcbuild Partial log (click to expand)
|
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 all I have on reading through the generators.nix
code.
In general, the generator seems to have some duplication, so maybe it can be cleaned up a bit.
As for the indentation trick, that’s pretty smart, I once had the same problem and arrived at a different solution, that feels more combinator-like, but was a bit brittle: https://gitlab.techcultivation.org/sangha/sangha-deployment/blob/master/containers/helpers/write-script-argparse/build-script.nix#L97
(No criticism, just for the fun of the problem).
lib/generators.nix
Outdated
@@ -175,4 +175,52 @@ rec { | |||
else "<λ:{${showFnas}}>" | |||
else abort "toPretty: should never happen (v = ${v})"; | |||
|
|||
# PLIST handling | |||
|
|||
toPLIST = x: '' |
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.
toX
functions should all take an attrset before the input value, which is an attribute set of options (possibly added in the future). So
toPlist = {}: x: ''
I think plist
is normally written with small letters (going by the wiki article), so I’d camel case.
The next step is thinking about all parts of the generator and moving everything that is not fixed by the generated format into an option. For example mkINI
doesn’t specify how to format names in section headers (mainly what escaping is used, mkSectionName
) and does not fix how key-value-pairs look, only the fact that they exist (the formatting of them is relayed to mkKeyValueDefault
, another generator).
lib/generators.nix
Outdated
if isString x then pprStr ind x else | ||
if isList x then pprList ind x else | ||
if isAttrs x then pprAttrs ind x else | ||
throw "invalid plist type"; |
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 error message should mirror the other pattern matching error messages in this module, namely:
else abort "toPretty: should never happen (v = ${v})";
and
let err = t: v: abort
("generators.mkValueStringDefault: " +
"${t} not supported: ${toPretty {} v}");
And now that I see them, they can you edit factor out the error function from the second and make all say:
"generators.${name}: this value is not supported: ${toPretty {} v}"
? :)
lib/generators.nix
Outdated
|
||
attrFilter = name: value: name != "_module" && value != null; | ||
|
||
pprAttr = ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList (name: value: lib.optional (attrFilter name value) [ |
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.
Line length
lib/generators.nix
Outdated
'' + pprExpr "" x | ||
+ "\n</plist>"; | ||
|
||
pprExpr = ind: x: with builtins; |
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 pprX
definitions should go into a let
definition at the start of toPlist
, and the ppr
prefixes can be removed.
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.
Like I mentioned on the nix-darwin pr, I'm fine with moving these to nixpkgs. Didn't realise there are some places where it could be used already.
lib/generators.nix
Outdated
if isAttrs x then pprAttrs ind x else | ||
throw "invalid plist type"; | ||
|
||
pprLiteral = ind: x: ind + x; |
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 wouldn't expose these. None of those helper functions are useful except for maybe a version of toPLIST
without the header, but it should probably have a better name in that case.
Ok is all caps PLIST acceptable? We can do toPlist as well if that's preferred. |
Success on x86_64-linux (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on x86_64-darwin (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: xcbuild Partial log (click to expand)
|
lib/generators.nix
Outdated
@@ -175,4 +175,51 @@ rec { | |||
else "<λ:{${showFnas}}>" | |||
else abort "toPretty: should never happen (v = ${v})"; | |||
|
|||
# PLIST handling | |||
toPLIST = {}: v: let | |||
pprExpr = ind: x: with builtins; |
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 ppr
prefix is superfluous.
lib/generators.nix
Outdated
@@ -175,4 +175,51 @@ rec { | |||
else "<λ:{${showFnas}}>" | |||
else abort "toPretty: should never happen (v = ${v})"; | |||
|
|||
# PLIST handling | |||
toPLIST = {}: v: let |
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 torn. When I search for it, everyone else doesn’t write PLIST
, but plist
. So I’d prefer camel case in this case.
Success on x86_64-darwin (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on x86_64-linux (full log) Attempted: xcbuild Partial log (click to expand)
|
Address PR comments Refactors - Rename toPLIST -> toPlist
d98bc39
to
337b589
Compare
Ok darwin.adv_cmds still builds so I will merge for now. Will definitely accept refactors though. Also we need to make sure nix-darwin can use this successfully without issues. |
Success on x86_64-darwin (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: xcbuild Partial log (click to expand)
|
Success on x86_64-linux (full log) Attempted: xcbuild Partial log (click to expand)
|
Motivation for this change
Need to make sure this is okay with @LnL7 first, but this is the plist generator from nix-darwin. Hopefully there is no problem with upstreaming it to Nixpkgs.
@3noch has some improvements for it that are needed by reflex-platform. I want to work with him to get this included in Nixpkgs as soon as possible (LnL7/nix-darwin#78 still needs
some changes).