Skip to content

Commit

Permalink
Merge pull request #200 from mjhoy/automatically-update-nixpkgs
Browse files Browse the repository at this point in the history
automatically update nixpkgs
  • Loading branch information
mjhoy authored Nov 3, 2023
2 parents 84aa819 + 4d70192 commit a213210
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v4
with:
submodules: true
- uses: cachix/install-nix-action@v22
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Update"
on:
schedule:
# Every monday at 9 UTC
- cron: '0 9 * * 1'
jobs:
update:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=${{ github.workspace }}/nixpkgs
install_url: https://releases.nixos.org/nix/nix-2.8.1/install
- run: make install
- uses: cachix/cachix-action@v12
with:
name: mjhoy
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
extraPullNames: nix-community
- run: ./scripts/build-nix-env
- run: ./scripts/update-nixpkgs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions scripts/build-nix-env
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
set -eoux pipefail

echo "Building devEnv"
nix-build --no-link --show-trace -A devEnv '<nixpkgs>'
nix-build --no-link --show-trace '<nixpkgs>' -A devEnv

echo "Building nix"
nix-build --no-link -A nix '<nixpkgs>'
nix-build --no-link '<nixpkgs>' -A nix

echo "Installing"
nix-env -iA nixpkgs.devEnv
nix-env -iA nixpkgs.nix
nix-env -f '<nixpkgs>' -i devEnv
nix-env -f '<nixpkgs>' -i nix
38 changes: 38 additions & 0 deletions scripts/update-nixpkgs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#
# This script does the following:
#
# 1. Updates `nixpkgs` reference using `niv`
# 2. Updates the commit referenced in nix/nixpkgs/overlays.nix
# 3. Commits changes and opens a github PR

set -eou pipefail

if [ -n "$(git status --porcelain)" ]; then
echo "git status dirty; exiting";
exit 1
fi

DATE=$(date "+%Y-%m-%d")

BRANCH_NAME=update-nixpkgs-$DATE

git checkout -b $BRANCH_NAME

niv update nixpkgs

git add nix/sources.json

git commit -m "update nixpkgs $DATE"

LATEST_EMACS_REF=$(gh api /repos/nix-community/emacs-overlay/git/ref/heads/master | jq -r '.object.sha')

sed -i '' -e "s|emacs-overlay/archive/.*|emacs-overlay/archive/$LATEST_EMACS_REF.tar.gz;|g" nix/nixpkgs/overlays.nix

git add nix/nixpkgs/overlays.nix

git commit -m "update emacs overlay $DATE"

git push origin $BRANCH_NAME -u

gh pr create --title "update nixpkgs $DATE" --body "generated by scripts/update-nixpkgs"

0 comments on commit a213210

Please sign in to comment.