feat(nix): add flake.nix for macOS builds#153
Conversation
- Add flake.nix to define build and bundle outputs for macOS using Nix - Update .gitignore to exclude Nix build result directory
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates Nix support for building and installing the Glide application on macOS. It provides a Nix-native method for users to obtain and manage Glide, offering an alternative to existing installation paths like Homebrew. The changes are additive, focusing on enhancing build and distribution options for Nix users without affecting current workflows. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces Nix support for building Glide on macOS via a flake.nix file. The implementation is solid and covers package outputs for both bundled and unbundled versions, as well as a nix run app. I've provided a couple of suggestions to improve the maintainability and efficiency of the Nix expression by using more idiomatic patterns.
| forAllSystems = f: | ||
| lib.genAttrs supportedSystems ( | ||
| system: f (import nixpkgs { inherit system; }) | ||
| ); |
There was a problem hiding this comment.
Using import nixpkgs { inherit system; } inside lib.genAttrs can be inefficient as it re-evaluates the nixpkgs import for each system. A more idiomatic and efficient approach in flakes is to use nixpkgs.legacyPackages.${system}.
forAllSystems = f:
lib.genAttrs supportedSystems (
system: f nixpkgs.legacyPackages.${system}
);
| mkGlideBundle = pkgs: unbundled: | ||
| pkgs.runCommand "${cargoToml.package.name}-app-${version}" { | ||
| meta = with pkgs.lib; { | ||
| description = "${cargoToml.package.description} (${bundleName})"; | ||
| homepage = cargoToml.package.homepage; | ||
| license = [ | ||
| licenses.asl20 | ||
| licenses.mit | ||
| ]; | ||
| mainProgram = "glide"; | ||
| platforms = platforms.darwin; | ||
| }; | ||
| } '' | ||
| bundle="$out/Applications/${bundleName}" | ||
|
|
||
| mkdir -p "$bundle/Contents/MacOS" "$out/bin" | ||
|
|
||
| install -m755 ${unbundled}/bin/glide "$bundle/Contents/MacOS/glide" | ||
| install -m755 ${unbundled}/bin/glide_server "$bundle/Contents/MacOS/glide_server" | ||
|
|
||
| printf '%s\n' \ | ||
| '<?xml version="1.0" encoding="UTF-8"?>' \ | ||
| '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' \ | ||
| '<plist version="1.0">' \ | ||
| ' <dict>' \ | ||
| ' <key>CFBundleDevelopmentRegion</key>' \ | ||
| ' <string>en</string>' \ | ||
| ' <key>CFBundleExecutable</key>' \ | ||
| ' <string>glide_server</string>' \ | ||
| ' <key>CFBundleIdentifier</key>' \ | ||
| ' <string>${bundleIdentifier}</string>' \ | ||
| ' <key>CFBundleInfoDictionaryVersion</key>' \ | ||
| ' <string>6.0</string>' \ | ||
| ' <key>CFBundleName</key>' \ | ||
| ' <string>${productName}</string>' \ | ||
| ' <key>CFBundlePackageType</key>' \ | ||
| ' <string>APPL</string>' \ | ||
| ' <key>CFBundleShortVersionString</key>' \ | ||
| ' <string>${version}</string>' \ | ||
| ' <key>CFBundleVersion</key>' \ | ||
| ' <string>${version}</string>' \ | ||
| ' <key>NSPrincipalClass</key>' \ | ||
| ' <string>NSApplication</string>' \ | ||
| ' </dict>' \ | ||
| '</plist>' \ | ||
| > "$bundle/Contents/Info.plist" | ||
|
|
||
| printf 'APPL????' > "$bundle/Contents/PkgInfo" | ||
|
|
||
| ln -s "../Applications/${bundleName}/Contents/MacOS/glide" "$out/bin/glide" | ||
| ln -s "../Applications/${bundleName}/Contents/MacOS/glide_server" "$out/bin/glide_server" | ||
|
|
||
| printf '%s\n' \ | ||
| '#!/bin/sh' \ | ||
| "exec \"$out/bin/glide\" launch \"\$@\"" \ | ||
| > "$out/bin/glide-launch" | ||
| chmod +x "$out/bin/glide-launch" | ||
| ''; |
There was a problem hiding this comment.
The mkGlideBundle function can be made more robust and maintainable by using some standard Nix helper functions.
- Explicitly declare
nativeBuildInputslikemakeWrapperandcoreutilsfor tools used in the script. - Generate the
Info.plistfile usingpkgs.writeTextoutside the script to separate data from logic. - Use
pkgs.makeWrapperto create theglide-launchscript, which is the standard way to create wrapper scripts in Nix.
Here's a suggested refactoring that applies these improvements:
mkGlideBundle = pkgs: unbundled:
let
infoPlist = pkgs.writeText "Info.plist" ''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>glide_server</string>
<key>CFBundleIdentifier</key>
<string>${bundleIdentifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${productName}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${version}</string>
<key>CFBundleVersion</key>
<string>${version}</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
'';
in
pkgs.runCommand "${cargoToml.package.name}-app-${version}" {
nativeBuildInputs = [ pkgs.makeWrapper pkgs.coreutils ];
meta = with pkgs.lib; {
description = "${cargoToml.package.description} (${bundleName})";
homepage = cargoToml.package.homepage;
license = [
licenses.asl20
licenses.mit
];
mainProgram = "glide";
platforms = platforms.darwin;
};
} ''
bundle="$out/Applications/${bundleName}"
mkdir -p "$bundle/Contents/MacOS" "$out/bin"
install -m755 ${unbundled}/bin/glide "$bundle/Contents/MacOS/glide"
install -m755 ${unbundled}/bin/glide_server "$bundle/Contents/MacOS/glide_server"
cp ${infoPlist} "$bundle/Contents/Info.plist"
printf 'APPL????' > "$bundle/Contents/PkgInfo"
ln -s "../Applications/${bundleName}/Contents/MacOS/glide" "$out/bin/glide"
ln -s "../Applications/${bundleName}/Contents/MacOS/glide_server" "$out/bin/glide_server"
makeWrapper "$out/bin/glide" "$out/bin/glide-launch" --add-flags "launch"
'';
|
This seems like it duplicates stuff like the plist generation which I already have a tool (cargo packager) doing. I don't want to maintain two different ways of creating the plist. I'm also not sure about the user experience - I think you would have to add permissions again every time you update, unless you are running the glide server in the terminal (in which case you have to give accessibility permissions to your terminal). |
This adds a
flake.nixso Glide can be built and run directly with Nix on macOS.It exposes:
packages.<system>.defaultas the app bundlepackages.<system>.bundleas the same bundled outputpackages.<system>.unbundledfor the raw binariesapps.<system>.defaultfornix runMotivation
I've been using Glide and have had a great experience with it.
I wanted a Nix-native way to build and install it, and I think it can also be useful for users who want to track upstream directly without depending on Homebrew cask update timing.
Notes
This is an additive change for Nix users and does not change the existing Homebrew or manual installation paths.
For instance, https://github.com/openai/codex provides itself via
flake.nix. Furthermore, Codex declaratively manages its development environment using a Nix mechanism calleddevShells, and we believe that incorporatingdevShellsin the future would further improve the workflow.