GitHub actions to update your Nixpkgs fork with PRs' patches

Motivation

After a few small dissatisfactions from nixpkgs-patcher by @gepbird, and after encountering substantial issues with nix-patcher, I created a setup that avoids many of the drawbacks of the above two solutions.

This solution is based upon a periodic GH action that runs on your fork of Nixpkgs. It updates a branch on your fork called channel/personal-stable (name can be changed of course) with commits from PRs listed in the GH action’s workflow yml file. With this branch, you can use the following in your NixOS flake.nix:

inputs.nixpkgs.url = "https://github.com/$GITHUB_NAMESPACE/nixpkgs/channel/personal-stable

Full Details & Instructions

  • Create a channel/fork-master branch on your fork:
git checkout master
# Assuming branch `master` follows `origin/master` and `origin` is `NixOS/nixpkgs`:
git pull
git checkout -b channel/fork-master
# Assuming $GITHUB_NAMESPACE is the remote name for your fork:
git push -u $GITHUB_NAMESPACE
  • Now add the workflow file. Use the following as a basis (put yours in the same directory as well):
  • Commit the above file to the already checked out channel/fork-master branch, and push it.
  • Make channel/fork-master the default branch of your fork. Use the link: https://github.com/$GITHUB_NAMESPACE/nixpkgs/settings.
  • nix flake update your NixOS configurations repository’s flake.lock file pointing to your channel/personal-stable branch.

Implementation Details

  • This workflow implementation uses the hash and date of the nixos-unstable branch on the fork to decide whether to apply the PRs’ commits to the channel/personal-stable branch.
  • The above means that if the nixos-unstable branch on the fork is pointing to the same commit as nixos-unstable on the NixOS namespace, the channel/personal-stable branch won’t be updated at all.
  • To force the workflow to update the channel/personal-stable branch, you can use this action:

Which is also triggered by editing the PR_URLS list in the update-personal-stable.yml, once pushed to the channel/fork-master branch.

Related Discussions:

With nix-patcher I encountered substantial issues I didn’t bother reporting as it seems the project as abandoned.