Using Nix to consolidate an environment

I use thumbsup to manage my gallery site. Since the site is entirely static, I use exiftool to store the description and tags as metadata in the images themselves. To simplify managing the metadata I wrote a small Symfony application that writes and updates the metadata from CSV files.

The workflow is straightforward enough, but the code deployment on my laptop looked like a messy bedroom. The Symfony application lived in one directory. My fork of thumbsup, supporting custom album covers, was hanging out within .nvm, tied to given versions of NodeJS. My customization of the cards theme lived in a separate directory, passed by argument to the Symfony application. This was messy and unsustainable.

I’ve used Nix for several other projects, and this felt like a good use case for getting everything in once place. In this case, I would centralize in the Symfony directory. First step: adding all the relevant packages:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
outputs = { self, nixpkgs, flake-utils, phps }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
php71 = (phps.packages.${system}.php71.buildEnv {
extensions = ({ enabled, all }: enabled ++ (with all; [
]));
});
in
{
devShell = pkgs.mkShell {
buildInputs = [
php71
php71.packages.composer
pkgs.exiftool
pkgs.nodejs_18
pkgs.yarn
pkgs.graphicsmagick
];
shellHook = ''
yarn
php -v
'';
};
}
);

Next, I create a stub package.json to define the dependencies for thumbsup and the cards theme:

1
2
3
4
5
6
7
{
"name": "exif-tagger",
"dependencies": {
"@thumbsup/theme-cards": "git+ssh://path/to/private/repository",
"thumbsup": "https://github.com/mackensen/thumbsup#237-covers"
}
}

Finally, I modified the Symfony application to use the locally-installed thumbsup instead of the globally-installed thumbsup:

1
2
3
$command = "npx thumbsup";
...
$command .= " --cleanup --embed-exif --theme-path ./node_modules/@thumbsup/theme-cards --photo-download copy";

Now, when I run nix develop, it will set up PHP, NodeJS, yarn, exiftool, and GraphicsMagick, and clone my custom respositories locally. Next step is getting on to a higher version of PHP and Symfony, but it’ll be in a clean environment.