Thoughts on enhancing Chocolatey portable packages

Filed under: Software

Chocolatey, a windows package management tool is great for installing apps and tools for most Windows devices.

For developers and power users, it supports this concept of portable packages where a package that installs the app does not use installers like .msi, Microsoft Installer, files to install an app. Instead, it copies files either from a zip package or files embedded within the package to the local system. This is great for those that have limited permissions like non-admin users or those that really dislike cluttering up the path and registry.

The weak point of portable packages is limited support for side by side (multiple) installs and giving thought to backing up files like logs and configurations between installs and upgrades. These items would particularly useful for people who want to use multiple versions of software like nginx, php, ruby, python, mysql. Chocolately has support for side by side installs using the -m or -multiple flag, but it lacks built-in swapping between versions for path variables.

I took a stab at this before by building an extension that was loaded into chocolatey. Chocolately allows you to install powershell extensions. The downside to this approach is requiring an extra dependency for each package that you create. Furthermore, loading an assembly can lead to trouble with the assembly file being locked.

For my next attempt at this, I’m going to build a packaging system around chocolatey takes a json file and creates a nupkg file and then generates pieces and includes of functionality needed for the install scripts that will help to manage symlinks, swapping between versions of an app, and holding onto key files like configs between installs.

The advantage to using the json file is that you can use an editor like VSCode and give it a json schema. Then you can easily edit the file without having to create a full on plugin. You can also add keys in the json that chocolatey doesn’t support and use that as part of the install process rather than constantly changing the code in the chocolateyInstall.ps1 file. Additionally, the packaging system that will run this can also use that file to only include extra functionality that is needed to dynamically build out the install scripts.

The other aspect to this is enabling portable installs even when only an msi and exe is available. Many .exe files can be extracted using 7zip and .msi files can be extracted, even with non-admin permissions using the -a, administrative, flag.

I’m currently working on this in the Full Metal Gnome project on gitlab. The first go will be vanilla, where I build some packages using powershell for items like nginx, mysql, wordpress, and a few others.

Then go back and write code that will generate those same files based on a .json config, including the nuspec files used to create the chocolately package.

Comments

comments

Nerdy Mishka