Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emacsPackages: clean the bulk-updating scripts #351056

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"elpa": {
"overlay_url": "https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos/elpa/elpa-generated.nix",
"generated_file": "elpa-generated.nix",
"nix_attribute": "emacsPackages.elpaPackages"
},
"elpa-devel": {
"overlay_url": "https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos/elpa/elpa-devel-generated.nix",
"generated_file": "elpa-devel-generated.nix",
"nix_attribute": "emacsPackages.elpaDevelPackages"
},
"melpa": {
"overlay_url": "https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos/melpa/recipes-archive-melpa.json",
"generated_file": "recipes-archive-melpa.json",
"nix_attribute": "emacsPackages.melpaPackages"
},
"melpa-stable": {
"overlay_url": "https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos/melpa/recipes-archive-melpa.json",
"generated_file": "recipes-archive-melpa.json",
"nix_attribute": "emacsPackages.melpaStablePackages"
},
"nongnu": {
"overlay_url": "https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos/nongnu/nongnu-generated.nix",
"generated_file": "nongnu-generated.nix",
"nix_attribute": "emacsPackages.nongnuPackages"
},
"nongnu-devel": {
"overlay_url": "https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos/nongnu/nongnu-devel-generated.nix",
"generated_file": "nongnu-devel-generated.nix",
"nix_attribute": "emacsPackages.nongnuDevelPackages"
}
}
6 changes: 0 additions & 6 deletions pkgs/applications/editors/emacs/elisp-packages/update-elpa

This file was deleted.

This file was deleted.

52 changes: 11 additions & 41 deletions pkgs/applications/editors/emacs/elisp-packages/update-from-overlay
Original file line number Diff line number Diff line change
@@ -1,49 +1,19 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p curl nix coreutils
set -euxo pipefail
set -euo 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
# This script relies on the automatic code generation done by the emacs overlay
# kept by nix-community
# You can use this to avoid running time-consuming code generation jobs locally

export NIXPKGS_ALLOW_BROKEN=1
source ./update-scripts-library.sh

download_change() {
local FILE_LOCATION="$1"
# The loops are unrolled as follows because either all packagesets should be
# updated, or none of them should. Therefore, if any of them fails, all the
# process should be aborted as soon as possible.

local BASEURL="https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos"
download_packagesets "elpa" "elpa-devel" "melpa" "nongnu" "nongnu-devel"

curl -s -O "${BASEURL}/${FILE_LOCATION}"
}
test_packagesets "elpa" "elpa-devel" "melpa" "melpa-stable" "nongnu" "nongnu-devel"

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"
}

download_change "elpa/elpa-generated.nix"
download_change "elpa/elpa-devel-generated.nix"
download_change "melpa/recipes-archive-melpa.json"
download_change "nongnu/nongnu-generated.nix"
download_change "nongnu/nongnu-devel-generated.nix"

test_packageset "nongnuPackages"
test_packageset "nongnuDevelPackages"
test_packageset "elpaPackages"
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_packagesets "elpa" "elpa-devel" "melpa" "nongnu" "nongnu-devel"
6 changes: 0 additions & 6 deletions pkgs/applications/editors/emacs/elisp-packages/update-nongnu

This file was deleted.

This file was deleted.

54 changes: 54 additions & 0 deletions pkgs/applications/editors/emacs/elisp-packages/update-package-sets
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#! /usr/bin/env nix-shell
#! nix-shell --show-trace ./emacs2nix.nix -i bash

usage(){
cat<<-EOF
Usage: update-package-sets args
args can be at least one from: elpa-devel, elpa, nongnu-devel, nongnu.
EOF
}

update_set(){
local PKGSET="$1"

local output="${PKGSET}-generated.nix"
local script="${PKGSET}-packages.sh"

eval "${script} --names ${EMACS2NIX}/names.nix -o ${output}"
nixfmt "${output}"
}

main(){
local SETS=( )

while (( $# )); do
case $1 in
"elpa-devel" | "elpa" | "nongnu-devel" | "nongnu")
# Do not include duplicates
if [[ ! ${SETS[@]} =~ $1 ]]; then
SETS+=( "$1" )
fi
shift
;;
"melpa" | "melpa-stable")
# Let's warn the user of the correct script and go on
echo "This script does not generate the MELPA package set."
echo "Use update-melpa script instead."
shift
;;
*)
echo "Unknown package set: $1"
usage
exit 1
;;
esac
done

for SET in "${SETS[@]}"; do
echo "${SET}: updating..."
update_set "${SET}"
echo "${SET}: updated"
done
}

main "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env bash

# This is a basic library that concentrates the main tasks of bulk updating.
# It is meant to be `source`d, so that it can be used in both
# batch and interactive environments.

# TODO: Bail out if any dependency is not found
# TODO: should we make this a nix-shell script?
# DEPENDENCIES=( "curl" "jq" "git" "nix" )

# Classic "where I am" block
# https://www.binaryphile.com/bash/2020/01/12/determining-the-location-of-your-script-in-bash.html
SCRIPT_DIR=$(cd $(dirname ${BASH_SOURCE[0]}); cd -P $(dirname $(readlink ${BASH_SOURCE[0]} || echo .)); pwd)

# Since Bash is meager on data structures, let's use a JSON file and jq!
# The format is straightforward:
# archive_name : { overlay_url, generated_file, nix_attribute }
JSON_ARCHIVE_TABLE="${SCRIPT_DIR}/elisp-archives-table.json"

function download_packagesets {
# Silent early-return when no argument is passed
if [[ "$#" == "0" ]]; then
return 0
fi

declare -a ARCHIVE_LIST

# collect the command line arguments, bailing out when any of them is not recognized
while (( "$#" )); do
ARCHIVE_NAME="$1"
if [[ "$(jq "has(\"${ARCHIVE_NAME}\")" ${JSON_ARCHIVE_TABLE})" == "false" ]]; then
echo "${FUNCNAME[0]}: unknown package archive: ${ARCHIVE_NAME}"
return 1
else
ARCHIVE_LIST+=( "${ARCHIVE_NAME}" )
fi
shift
done

pushd "${SCRIPT_DIR}" > /dev/null
for ARCHIVE_NAME in "${ARCHIVE_LIST[@]}"; do
URL=$(jq --raw-output ".\"${ARCHIVE_NAME}\".overlay_url" "${JSON_ARCHIVE_TABLE}")
echo "${FUNCNAME[0]}: ${ARCHIVE_NAME}..."
curl --silent --remote-name "${URL}"
echo "${FUNCNAME[0]}: ${ARCHIVE_NAME}: done!"
done
popd > /dev/null
}

function test_packagesets {
# Silent early-return when no argument is passed
if [[ "$#" == "0" ]]; then
return 0
fi

declare -a ARCHIVE_LIST

# collect the command line arguments, bailing out when any of them is not recognized
while (( "$#" )); do
ARCHIVE_NAME="$1"
if [[ "$(jq "has(\"${ARCHIVE_NAME}\")" ${JSON_ARCHIVE_TABLE})" == "false" ]]; then
echo "${FUNCNAME[0]}: unknown package archive: ${ARCHIVE_NAME}"
return 1
else
ARCHIVE_LIST+=( "${ARCHIVE_NAME}" )
fi
shift
done

pushd "${SCRIPT_DIR}" > /dev/null
for ARCHIVE_NAME in "${ARCHIVE_LIST[@]}"; do
ATTRIBUTE=$(jq --raw-output ".\"${ARCHIVE_NAME}\".nix_attribute" "${JSON_ARCHIVE_TABLE}")
echo "${FUNCNAME[0]}: ${ATTRIBUTE}..."
NIXPKGS_ALLOW_BROKEN=1 nix-instantiate --show-trace ../../../../../ -A "${ATTRIBUTE}"
echo "${FUNCNAME[0]}: ${ATTRIBUTE}: done!"
done
popd > /dev/null
}

function commit_packagesets {
# Silent early-return when no argument is passed
if [[ "$#" == "0" ]]; then
return 0
fi

declare -a ARCHIVE_LIST

while (( "$#" )); do
ARCHIVE_NAME="$1"
if [[ "$(jq "has(\"${ARCHIVE_NAME}\")" ${JSON_ARCHIVE_TABLE})" == "false" ]]; then
echo "${FUNCNAME[0]}: unknown package archive: ${ARCHIVE_NAME}"
return 1
else
ARCHIVE_LIST+=( "${ARCHIVE_NAME}" )
fi
shift
done

pushd "${SCRIPT_DIR}" > /dev/null
for ARCHIVE_NAME in "${ARCHIVE_LIST[@]}"; do
ATTRIBUTE=$(jq --raw-output ".\"${ARCHIVE_NAME}\".nix_attribute" "${JSON_ARCHIVE_TABLE}")
FILE=$(jq --raw-output ".\"${ARCHIVE_NAME}\".generated_file" "${JSON_ARCHIVE_TABLE}")
if [[ "$(git diff --exit-code "${FILE}" > /dev/null)" == "0" ]]; then
echo "${FUNCNAME[0]}: ${FILE}..."
git commit -m "${ATTRIBUTE}: updated at $(date --iso)" -- "${FILE}"
echo "${FUNCNAME[0]}: ${FILE}: done!"
else
echo "${FUNCNAME[0]}: ${FILE} was not modified"
fi
done
popd > /dev/null
}