Declarative Homebrew Casks on Darwin

Hi,

I didn’t find anything like that so I decided to try it myself, and after a little hacking I am happy to anounce a new project: nixcasks.

The idea is to use Homebrew Cask definitions to declaratively manage macOS applications, many of which (among them Firefox, VLC, LibreOffice…) are not supported in Nixpkgs.

I’m using Homebrew Casks JSON file as the source of package data (versions, URLs, checksums) which is then used in mkDerivation to download binaries and install them into the Nix Store.

I have been able to install several packages this way already, and I was lucky enough that between the start of this project and first barely usable version MPV’s cask was updated by the Homebrew folks, so I can show a little how it works:

# Installed via Nixpkgs
~ via nix impure (shell)
✦ > ls -l Applications/Home\ Manager\ Apps/mpv.app
lrwxr-xr-x 1 root wheel 88 Jan  1  1970 'Applications/Home Manager Apps/mpv.app' -> /nix/store/w8gpl79980ip3kypsvlgq9gph9v039js-mpv-with-scripts-0.35.1/Applications/mpv.app

# Installed via Nixcasks
~ via nix impure (shell)
✦ > ls -l Applications/Home\ Manager\ Apps/mpv.app
lrwxr-xr-x 1 root wheel 75 Jan  1  1970 'Applications/Home Manager Apps/mpv.app' -> /nix/store/4kddwv6zhxcbgnw3djmj68lp0d1dyn6w-mpv-0.35.1/Applications/mpv.app

# After nix flake lock --update-input nixcasks && home-manager switch
~ via nix impure (shell)
✦ > ls -l Applications/Home\ Manager\ Apps/mpv.app
lrwxr-xr-x 1 root wheel 75 Jan  1  1970 'Applications/Home Manager Apps/mpv.app' -> /nix/store/a4bx75r4sl3hh0b0qjvg16fd2qbqrsqx-mpv-0.36.0/Applications/mpv.app

As Homebrew Cask is now a plain Nix store entry, an “upgrade” does not remove the application from the store, only updates the links.

Obviously there’s much more work to do but even as this is now, it seems usable for programs which are “normally” installed by “dragging icon to /Applications”. I have already “tested”, i.e. started and opened some file/page - MPV, LibreOffice, Tor Browser and Pinta. That’s not much, given that there are 2845 maybe-installable packages :wink:

If you’re interested, the project is here: GitHub - jacekszymanski/nixcasks: Homebrew casks, nixified

Now it’s a quick and dirty hack, but I hope to improve it. Comments (and contributions :slight_smile:) welcome.

EDIT: How it is different from homebrew.cask.* in nix-darwin: in short, nix-darwin runs brew cask to install/uninstall/update software, but it’s still controlled by homebrew; this project aims to bring software available as Homebrew Casks (and perhaps later as brews) to Nix, with reproducibility, garbage collection etc.

Cheers,
Jacek

3 Likes

Hi,
I was surprised this is not toggled on by default but after toggling it on myself I realised it’s intended and that’s actually very good!

To allow Nix to uninstall anything that’s not present within your casks list, you have to set the flag homebrew.onActivation.cleanup within your flake.nix, this is what I found in man configuration.nix (if you wanna find out more, you can check that one out)

Having that toggled on, and a list with homebrew.casks it’ll make sure only casks within that list will be present on your workstation, the rest will be explicitly purged, I’ve witnessed this myself lol

Hope I got your question right.