pkl packaged UTM virtual machines for macOS
#1018
mobileskyfi
started this conversation in
Show and tell
Replies: 1 comment
-
|
Hey, awesome! Thanks for sharing your project! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Tried
pklfor a more modest deployment target than k8s:desktop virtual machines using macOS UTM app
I posted it on GitHub here: https://github.com/tikoci/mikropkl
Nothing fancy, but thought I share since there are few
pklexamples in the world. To me, pkl-lang seems useful in apps as a kinda “SwiftScript™”. But the first problem is you have to learnpkl. And despite reading the manual a few months back, thought it best to try pkl-lang on something smaller, before trying to integratepklinto some Swift-based app at some point.Since I use UTM-based virtual machines for testing, I had an idea to try pkl-lang to automate UTM machine bundle creation on GitHub CI. The underlying problem is
.plistfile modifications are tough outside macOS (i.e. no “PlistBuddy” etc). So, one main advantage of pkl-lang here is it works on Linux and via the PlistRenderer, and allows “mikropkl” code to converts some.pklinto a.pliston a cross-platform basis (e.g. inside some CI system).Since UTM macOS app supports app URLs for installing VMs & virtual machines are just macOS document bundles containing a
config.plist+ disk image files — means the can be “built” outside the app. So, essentially, pkl-lang in my project is “orchestrating” the generation of one/more “UTM bundle” (i.e. a folder ending in.utm) frompkl"manifests”, with aMakefilepicking up the piecespklcannot do (i.e. copy/download large files and run shell commands).The project is agnostic on OS/images, but since my immediate need was for RouterOS, that’s what works out-of-the-box (and wanted a ginny pig I knew). But the
CHR.pklcould be an example of extending "mikropkl" UTM package building to other OSes/images. There is a README.md that explains more, and thepklsource is on GitHub.The nuts-and-bolts are:
makekicks off building UTM virtual machines from manifests by invokingpkl eval Manifests/* -m Machines …-mfor multiple output files, to construct the files contained in the UTM’s virtual machine bundle into a “Machines” directory, including:config.plistneeded, and whose structure varies depending on the virtualization engine (QEMU or Apple) used. Additionally, UTM is order-sensitive, whichpklseems to handle. Although, this makes extending/refactoring/etc more tricky - and, why there is a layer of abstraction in the "templates" directory andutmzip.pklpart of the code.pklcannot readily deal with a file system nor "shell commands".... So for large file downloads,pklgenerates a small file ending in.url, likefilename.img.url, containing the download URL inside the file, that is later processed bymakeintofilename.imgafter download. And uses additional file extensions for other operations, like a.localcpto move a "static file" fromFilesinto a UTM bundle during build.pkland part of the multiple file output. For fun, you can specify icon color as a property in a template file, thenpklwill replace inside the SVG (*as string, using XmlRenderer was left for another day).makecontinues recursively afterpklto find any “placeholder” file like.urlthat needs download or other actions. Inside theMakefilepattern matching files transform the pkl-generated placeholder files into something.pklappends an extra file extension which makes things easy onmaketo deal with “file operations” or "shell commands" that are beyondpkl.makeand build the UTM document bundles usable in autm://URL from macOS. The project'sMakefilecan run locally on macOS with machines usable from the output directory as an alternative and for adding new machines or types.Only a few minor “sour pickles”:
config.pliststores a<data>element when in Apple Virtualization mode which has a VZMacMachineIdentifier. I posted about this in How to output a `.plist`'s <data> element from a pkl file? #981 which had a workaround to generate<data>in a Plist file. And, apparently apple/pkl-evolution#14 appears to offer direct support for aBytestype that map to<data>with PlistRenderer in future.random()needs… “(see Custom Resource provider for shell commands? _or...how to get cheat Pkl and get a UUID for something_ #1006). Theconfig.plistalso uses UUIDs for disk images, and one or more MacAddress are needed. Now ideally UTM support would fill these on startup if missing, avoidingpklfor randomness… Instead, I used a hash as suggested in same discussion, which works well enough since pkl files have enough context for a unique hash.shell()nor simplepklCLI way to map a generic/"MsgPack unaware" command-line process into a valid external reader - that would have been useful. While having compiled code (i.e. Swift, Go) could fill in that gap... but, if you're usingpkloutside being the config system of an app/service, there was no "shell-friendly" analog for "external resources" when usingpklas more classic UNIX tool.Overall, my implementation could be improved*, but works well enough to share.
Beta Was this translation helpful? Give feedback.
All reactions