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

melpaBuild: allow nix unstable version format #316726

Merged
merged 1 commit into from
Jun 3, 2024
Merged
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
24 changes: 21 additions & 3 deletions pkgs/build-support/emacs/melpa.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ in
Default: pname
*/
, ename ? pname
/*
version: Either a stable version such as "1.2" or an unstable version.
An unstable version can use either Nix format (preferred) such as
"1.2-unstable-2024-06-01" or MELPA format such as "20240601.1230".
*/
, version
/*
commit: Optional package history commit.
Expand Down Expand Up @@ -71,6 +76,19 @@ genericBuild ({

inherit packageBuild commit ename recipe;

melpaVersion =
let
parsed = lib.flip builtins.match version
# match <version>-unstable-YYYY-MM-DD format
"^.*-unstable-([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})$";
unstableVersionInNixFormat = parsed != null; # heuristics
date = builtins.concatStringsSep "" parsed;
time = "0"; # unstable version in nix format lacks this info
in
if unstableVersionInNixFormat
then date + "." + time
else version;

preUnpack = ''
mkdir -p "$NIX_BUILD_TOP/recipes"
if [ -n "$recipe" ]; then
Expand All @@ -96,17 +114,17 @@ genericBuild ({
-L "$NIX_BUILD_TOP/package-build" \
-l "$melpa2nix" \
-f melpa2nix-build-package \
$ename $version $commit
$ename $melpaVersion $commit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really work? I am impressed!

Copy link
Contributor Author

@jian-lin jian-lin Jun 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you comment at this line. But yes, the whole PR works. You can try it out yourself :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mostly a reaction of 50% skeptic plus 50% amazed.


runHook postBuild
'';

installPhase = ''
runHook preInstall

archive="$NIX_BUILD_TOP/packages/$ename-$version.el"
archive="$NIX_BUILD_TOP/packages/$ename-$melpaVersion.el"
if [ ! -f "$archive" ]; then
archive="$NIX_BUILD_TOP/packages/$ename-$version.tar"
archive="$NIX_BUILD_TOP/packages/$ename-$melpaVersion.tar"
fi

emacs --batch -Q \
Expand Down