Merge pull request #101083 from fgaz/unstable-updater
This commit is contained in:
commit
a0efbc1b68
@ -10,7 +10,7 @@ die() {
|
|||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $scriptName <attr> <version> [<new-source-hash>] [<new-source-url>]"
|
echo "Usage: $scriptName <attr> <version> [<new-source-hash>] [<new-source-url>]"
|
||||||
echo " [--version-key=<version-key>] [--system=<system>] [--file=<file-to-update>]"
|
echo " [--version-key=<version-key>] [--system=<system>] [--file=<file-to-update>] [--rev=<revision>]"
|
||||||
echo " [--ignore-same-hash] [--print-changes]"
|
echo " [--ignore-same-hash] [--print-changes]"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +30,9 @@ for arg in "$@"; do
|
|||||||
die "Could not find provided file $nixFile"
|
die "Could not find provided file $nixFile"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
--rev=*)
|
||||||
|
newRevision="${arg#*=}"
|
||||||
|
;;
|
||||||
--ignore-same-hash)
|
--ignore-same-hash)
|
||||||
ignoreSameHash="true"
|
ignoreSameHash="true"
|
||||||
;;
|
;;
|
||||||
@ -111,6 +114,13 @@ if [[ "$oldVersion" = "$newVersion" ]]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$newRevision" ]]; then
|
||||||
|
oldRevision=$(nix-instantiate $systemArg --eval -E "with import ./. {}; $attr.src.rev" | tr -d '"')
|
||||||
|
if [[ -z "$oldRevision" ]]; then
|
||||||
|
die "Couldn't evaluate source revision from '$attr.src'!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Escape regex metacharacter that are allowed in store path names
|
# Escape regex metacharacter that are allowed in store path names
|
||||||
oldVersionEscaped=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g')
|
oldVersionEscaped=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g')
|
||||||
oldUrlEscaped=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g')
|
oldUrlEscaped=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g')
|
||||||
@ -174,6 +184,15 @@ if cmp -s "$nixFile" "$nixFile.bak"; then
|
|||||||
die "Failed to replace source hash of '$attr' to a temporary hash!"
|
die "Failed to replace source hash of '$attr' to a temporary hash!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Replace new revision, if given
|
||||||
|
if [[ -n "$newRevision" ]]; then
|
||||||
|
sed -i "$nixFile" -re "s|\"$oldRevision\"|\"$newRevision\"|"
|
||||||
|
|
||||||
|
if cmp -s "$nixFile" "$nixFile.bak"; then
|
||||||
|
die "Failed to replace source revision '$oldRevision' to '$newRevision' in '$attr'!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# If new hash not given on the command line, recalculate it ourselves.
|
# If new hash not given on the command line, recalculate it ourselves.
|
||||||
if [[ -z "$newHash" ]]; then
|
if [[ -z "$newHash" ]]; then
|
||||||
nix-build $systemArg --no-out-link -A "$attr.src" 2>"$attr.fetchlog" >/dev/null || true
|
nix-build $systemArg --no-out-link -A "$attr.src" 2>"$attr.fetchlog" >/dev/null || true
|
||||||
|
44
pkgs/common-updater/unstable-updater.nix
Normal file
44
pkgs/common-updater/unstable-updater.nix
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{ stdenv
|
||||||
|
, writeShellScript
|
||||||
|
, coreutils
|
||||||
|
, git
|
||||||
|
, nix
|
||||||
|
, common-updater-scripts
|
||||||
|
}:
|
||||||
|
|
||||||
|
# This is an updater for unstable packages that should always use the latest
|
||||||
|
# commit.
|
||||||
|
{ url ? null # The git url, if empty it will be set to src.url
|
||||||
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
updateScript = writeShellScript "unstable-update-script.sh" ''
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
url="$1"
|
||||||
|
|
||||||
|
# By default we set url to src.url
|
||||||
|
if [[ -z "$url" ]]; then
|
||||||
|
url="$(${nix}/bin/nix-instantiate $systemArg --eval -E \
|
||||||
|
"with import ./. {}; $UPDATE_NIX_ATTR_PATH.src.url" \
|
||||||
|
| tr -d '"')"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get info about HEAD from a shallow git clone
|
||||||
|
tmpdir="$(${coreutils}/bin/mktemp -d)"
|
||||||
|
${git}/bin/git clone --bare --depth=1 "$url" "$tmpdir"
|
||||||
|
pushd "$tmpdir"
|
||||||
|
commit_date="$(${git}/bin/git show -s --pretty='format:%cs')"
|
||||||
|
commit_sha="$(${git}/bin/git show -s --pretty='format:%H')"
|
||||||
|
popd
|
||||||
|
${coreutils}/bin/rm -rf "$tmpdir"
|
||||||
|
|
||||||
|
# update the nix expression
|
||||||
|
${common-updater-scripts}/bin/update-source-version \
|
||||||
|
"$UPDATE_NIX_ATTR_PATH" \
|
||||||
|
"unstable-$commit_date" \
|
||||||
|
--rev="$commit_sha"
|
||||||
|
'';
|
||||||
|
|
||||||
|
in [ updateScript url ]
|
||||||
|
|
@ -1,6 +1,9 @@
|
|||||||
{ stdenv, fetchgit }:
|
{ stdenv
|
||||||
|
, fetchgit
|
||||||
|
, unstableGitUpdater
|
||||||
|
}:
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation rec {
|
||||||
pname = "qbe";
|
pname = "qbe";
|
||||||
version = "unstable-2019-07-11";
|
version = "unstable-2019-07-11";
|
||||||
|
|
||||||
@ -11,6 +14,9 @@ stdenv.mkDerivation {
|
|||||||
};
|
};
|
||||||
|
|
||||||
makeFlags = [ "PREFIX=$(out)" ];
|
makeFlags = [ "PREFIX=$(out)" ];
|
||||||
|
|
||||||
|
passthru.updateScript = unstableGitUpdater { };
|
||||||
|
|
||||||
meta = with stdenv.lib; {
|
meta = with stdenv.lib; {
|
||||||
homepage = "https://c9x.me/compile/";
|
homepage = "https://c9x.me/compile/";
|
||||||
description = "A small compiler backend written in C";
|
description = "A small compiler backend written in C";
|
||||||
|
@ -94,6 +94,8 @@ in
|
|||||||
|
|
||||||
genericUpdater = callPackage ../common-updater/generic-updater.nix { };
|
genericUpdater = callPackage ../common-updater/generic-updater.nix { };
|
||||||
|
|
||||||
|
unstableGitUpdater = callPackage ../common-updater/unstable-updater.nix { };
|
||||||
|
|
||||||
nix-update-script = callPackage ../common-updater/nix-update.nix { };
|
nix-update-script = callPackage ../common-updater/nix-update.nix { };
|
||||||
|
|
||||||
### Push NixOS tests inside the fixed point
|
### Push NixOS tests inside the fixed point
|
||||||
|
Loading…
Reference in New Issue
Block a user