Skip to content

Commit

Permalink
emacsPackages: factor out the functions from update-from-overlay
Browse files Browse the repository at this point in the history
The functions are useful for other purposes too. So, let's put them on
`lib-update-scripts.sh`.
  • Loading branch information
AndersonTorres committed Oct 26, 2024
1 parent 5483039 commit 0b7aacf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

# This script is a basic library that concentrates the main tasks of bulk updating:
# - download from Emacs overlay
# - test the packageset
# - commit the changes

SOURCE=${BASH_SOURCE[0]}
# resolve $SOURCE until the file is no longer a symlink
while [ -L "$SOURCE" ]; do
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
# if $SOURCE was a relative symlink, we need to resolve it relative to the
# path where the symlink file was located
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE
done
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )

download_change() {
local FILE_LOCATION="$1"

local BASEURL="https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos"

curl -s -O "${BASEURL}/${FILE_LOCATION}"
}

commit_change() {
local MESSAGE="$1"
local FILENAME="$2"
local FROM="$3"

git diff --exit-code "${FILENAME}" > /dev/null || \
git commit -m "${MESSAGE}: updated at $(date --iso) (from ${FROM})" -- "${FILENAME}"
}

test_packageset(){
local PKGSET="$1"

NIXPKGS_ALLOW_BROKEN=1 nix-instantiate --show-trace ${DIR}/../../../../../ -A "emacsPackages.$PKGSET"
}
34 changes: 6 additions & 28 deletions pkgs/applications/editors/emacs/elisp-packages/update-from-overlay
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,7 @@ set -euxo pipefail
# This script piggybacks on the automatic code generation done by the nix-community emacs overlay
# You can use this to avoid running lengthy code generation jobs locally

export NIXPKGS_ALLOW_BROKEN=1

download_change() {
local FILE_LOCATION="$1"

local BASEURL="https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos"

curl -s -O "${BASEURL}/${FILE_LOCATION}"
}

commit_change() {
local MESSAGE="$1"
local FILENAME="$2"

git diff --exit-code "${FILENAME}" > /dev/null || \
git commit -m "${MESSAGE}: updated $(date --iso) (from overlay)" -- "${FILENAME}"
}

test_packageset(){
local PKGSET="$1"

nix-instantiate --show-trace ../../../../../ -A "emacs.pkgs.$PKGSET"
}
source ./lib-update-scripts.sh

download_change "elpa/elpa-generated.nix"
download_change "elpa/elpa-devel-generated.nix"
Expand All @@ -42,8 +20,8 @@ test_packageset "elpaDevelPackages"
test_packageset "melpaStablePackages"
test_packageset "melpaPackages"

commit_change "elpa-packages" "elpa-generated.nix"
commit_change "elpa-devel-packages" "elpa-devel-generated.nix"
commit_change "melpa-packages" "recipes-archive-melpa.json"
commit_change "nongnu-packages" "nongnu-generated.nix"
commit_change "nongnu-devel-packages" "nongnu-devel-generated.nix"
commit_change "emacsPackages.elpaPackages" "elpa-generated.nix" "nix-community/emacs-overlay"
commit_change "emacsPackages.elpaDevelPackages" "elpa-devel-generated.nix" "nix-community/emacs-overlay"
commit_change "emacsPackages.melpaPackages" "recipes-archive-melpa.json" "nix-community/emacs-overlay"
commit_change "emacsPackages.nongnuPackages" "nongnu-generated.nix" "nix-community/emacs-overlay"
commit_change "emacsPackages.nongnuDevelPackages" "nongnu-devel-generated.nix" "nix-community/emacs-overlay"

0 comments on commit 0b7aacf

Please sign in to comment.