melpaBuild: allow nix unstable version format
Before, an unstable version of melpaBuild has to be in MELPA format,
which has some disadvantages:
- existing update scripts cannot be reused[1]
- it causes inconsistence.
This patch fixes that by allowing an unstable version to be in Nix
format.
We heuristically detect if it is an unstable version in Nix format.
If so, we convert it to MELPA format.
This does not bring evaluation performance overhead. Here is my
benchmark result using hyperfine-1.18.0 and nix-2.18.1.
Without this patch:
Benchmark 1: NIXPKGS_ALLOW_BROKEN=1 nix eval --include nixpkgs=$PWD --file . emacs.pkgs.melpaPackages --apply 'pkgSet: map (drv: drv.drvPath) (builtins.filter (p: p.type or null == "derivation") (builtins.attrValues pkgSet))' --no-eval-cache >/dev/null
Time (mean ± σ): 9.126 s ± 0.048 s [User: 6.531 s, System: 0.997 s]
Range (min … max): 9.056 s … 9.186 s 10 runs
With this patch applied:
Benchmark 1: NIXPKGS_ALLOW_BROKEN=1 nix eval --include nixpkgs=$PWD --file . emacs.pkgs.melpaPackages --apply 'pkgSet: map (drv: drv.drvPath) (builtins.filter (p: p.type or null == "derivation") (builtins.attrValues pkgSet))' --no-eval-cache >/dev/null
Time (mean ± σ): 9.124 s ± 0.057 s [User: 6.522 s, System: 1.011 s]
Range (min … max): 9.040 s … 9.220 s 10 runs
[1]: 177c9eddad/pkgs/applications/editors/emacs/elisp-packages/manual-packages/lsp-bridge/default.nix (L93-L108)
This commit is contained in:
parent
1774db69ca
commit
ee46aa8a13
@ -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.
|
||||
@ -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
|
||||
@ -96,7 +114,7 @@ genericBuild ({
|
||||
-L "$NIX_BUILD_TOP/package-build" \
|
||||
-l "$melpa2nix" \
|
||||
-f melpa2nix-build-package \
|
||||
$ename $version $commit
|
||||
$ename $melpaVersion $commit
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
@ -104,9 +122,9 @@ genericBuild ({
|
||||
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 \
|
||||
|
Loading…
Reference in New Issue
Block a user