mirror of
https://github.com/nmattia/snack.git
synced 2024-09-11 11:55:36 +03:00
Implement proper Nix verioning
This commit is contained in:
parent
237cbdb15f
commit
0f90cca1d2
@ -2,7 +2,10 @@ let
|
||||
pkgs = import ../nix {};
|
||||
specJson = pkgs.writeTextFile
|
||||
{ name = "spec-json";
|
||||
text = builtins.readFile ../nix/nixpkgs/nixpkgs-src.json;
|
||||
text =
|
||||
let
|
||||
versions = builtins.fromJSON (builtins.readFile ../nix/versions.json);
|
||||
in builtins.toJSON versions.nixpkgs;
|
||||
destination = "/spec.json";
|
||||
};
|
||||
lib64 = pkgs.runCommand "lib64" {}
|
||||
|
@ -1,4 +1,5 @@
|
||||
{ nixpkgs ? import ./nixpkgs }:
|
||||
with { fetch = import ./fetch.nix; };
|
||||
{ nixpkgs ? fetch.nixpkgs }:
|
||||
import nixpkgs {
|
||||
config = { };
|
||||
overlays = [
|
||||
|
26
nix/fetch.nix
Normal file
26
nix/fetch.nix
Normal file
@ -0,0 +1,26 @@
|
||||
# A record, from name to path, of the third-party packages
|
||||
let
|
||||
versions = builtins.fromJSON (builtins.readFile ./versions.json);
|
||||
fetchTarball =
|
||||
# fetchTarball version that is compatible between all the versions of
|
||||
# Nix
|
||||
{ url, sha256 }@attrs:
|
||||
let
|
||||
inherit (builtins) lessThan nixVersion fetchTarball;
|
||||
in
|
||||
if lessThan nixVersion "1.12" then
|
||||
fetchTarball { inherit url; }
|
||||
else
|
||||
fetchTarball attrs;
|
||||
mapAttrs = builtins.mapAttrs or
|
||||
(f: set: with builtins;
|
||||
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
|
||||
in
|
||||
mapAttrs (_: spec:
|
||||
fetchTarball {
|
||||
url =
|
||||
with spec;
|
||||
"https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
|
||||
sha256 = spec.sha256;
|
||||
}
|
||||
) versions
|
@ -1,6 +0,0 @@
|
||||
let
|
||||
spec = builtins.fromJSON (builtins.readFile ./nixpkgs-src.json);
|
||||
rev = spec.rev;
|
||||
url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
|
||||
in
|
||||
builtins.fetchTarball url
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "584270e39743020d8aa056b40eea00fcaa2b595f",
|
||||
"sha256": "1p8hrz7xz73gzcqw62f3zfkmf3pkwwn1b41xzs7ayxafkmzsh0hw"
|
||||
}
|
24
nix/update
24
nix/update
@ -1,24 +0,0 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p bash nix curl jq
|
||||
# vim: filetype=sh
|
||||
# Updates the nixpkgs.json to the latest release
|
||||
# See https://gist.github.com/zimbatm/de5350245874361762b6a4dfe5366530
|
||||
set -euo pipefail
|
||||
|
||||
branch=master
|
||||
|
||||
owner=NixOS
|
||||
repo=nixpkgs
|
||||
rev=$(curl -sfL https://api.github.com/repos/$owner/$repo/git/refs/heads/$branch | jq -r .object.sha)
|
||||
url=https://github.com/$owner/$repo/archive/$rev.tar.gz
|
||||
|
||||
release_sha256=$(nix-prefetch-url --unpack "$url")
|
||||
|
||||
cat <<NIXPKGS | tee nix/nixpkgs/nixpkgs-src.json
|
||||
{
|
||||
"owner": "$owner",
|
||||
"repo": "$repo",
|
||||
"rev": "$rev",
|
||||
"sha256": "$release_sha256"
|
||||
}
|
||||
NIXPKGS
|
9
nix/versions.json
Normal file
9
nix/versions.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"nixpkgs": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"branch": "master",
|
||||
"rev": "584270e39743020d8aa056b40eea00fcaa2b595f",
|
||||
"sha256": "1p8hrz7xz73gzcqw62f3zfkmf3pkwwn1b41xzs7ayxafkmzsh0hw"
|
||||
}
|
||||
}
|
102
script/update
Executable file
102
script/update
Executable file
@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p bash nix curl jq --pure
|
||||
# vim: filetype=sh
|
||||
set -euo pipefail
|
||||
|
||||
banner() {
|
||||
echo
|
||||
echo "--- $*"
|
||||
echo
|
||||
}
|
||||
|
||||
|
||||
update() {
|
||||
local versions="$1"
|
||||
local package="$2"
|
||||
echo "Versions file: $versions"
|
||||
echo "Package to update: $package"
|
||||
local owner=$(cat $versions | jq -r ".[\"$package\"].owner")
|
||||
local repo=$(cat $versions | jq -r ".[\"$package\"].repo")
|
||||
local branch=$(cat $versions | jq -r ".[\"$package\"].branch")
|
||||
local rev=$(cat $versions | jq -r ".[\"$package\"].rev")
|
||||
local sha256=$(cat $versions | jq -r ".[\"$package\"].sha256")
|
||||
|
||||
echo "Owner: $owner"
|
||||
echo "Repository: $repo"
|
||||
echo "Branch: $branch"
|
||||
|
||||
|
||||
case "$PREFETCH_ONLY" in
|
||||
TRUE)
|
||||
local new_rev=$rev
|
||||
echo "Using existing revision"
|
||||
;;
|
||||
FALSE)
|
||||
local new_rev=$(curl -sfL \
|
||||
https://api.github.com/repos/$owner/$repo/git/refs/heads/$branch \
|
||||
| jq -r .object.sha)
|
||||
echo "Fetching latest revision on branch $branch"
|
||||
;;
|
||||
esac
|
||||
echo "The following revision will be used:"
|
||||
echo " $new_rev"
|
||||
|
||||
local url=https://github.com/$owner/$repo/archive/$new_rev.tar.gz
|
||||
local new_sha256=$(nix-prefetch-url --unpack "$url")
|
||||
|
||||
echo "The following url will be used:"
|
||||
echo " $url"
|
||||
|
||||
echo "The following sha256 will be used:"
|
||||
echo " $new_sha256"
|
||||
|
||||
res=$(cat $versions \
|
||||
| jq -rM ".[\"$package\"].rev = \"$new_rev\"" \
|
||||
| jq -rM ".[\"$package\"].sha256 = \"$new_sha256\""
|
||||
)
|
||||
|
||||
echo "New versions file:"
|
||||
echo "$res"
|
||||
|
||||
echo "$res" > $versions
|
||||
}
|
||||
|
||||
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. >/dev/null && pwd )"
|
||||
VERSIONS_DEF="$ROOT/nix/versions.json"
|
||||
PACKAGES_DEF="$(cat $VERSIONS_DEF | jq -r 'keys | .[]')"
|
||||
|
||||
VERSIONS="$VERSIONS_DEF"
|
||||
echo "Using versions file ${VERSIONS}"
|
||||
|
||||
PREFETCH_ONLY="FALSE"
|
||||
PACKAGES=""
|
||||
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
key="$1"
|
||||
|
||||
case $key in
|
||||
--prefetch)
|
||||
PREFETCH_ONLY="TRUE"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
PACKAGES="$key $PACKAGES"
|
||||
shift # past value
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$PACKAGES" ];
|
||||
then
|
||||
PACKAGES="$PACKAGES_DEF"
|
||||
fi
|
||||
|
||||
echo "Using packages:"
|
||||
for p in $PACKAGES; do echo " - $p"; done
|
||||
|
||||
for p in $PACKAGES; do
|
||||
banner "$p"
|
||||
update "$VERSIONS" "$p"
|
||||
done
|
@ -1,5 +1,7 @@
|
||||
let
|
||||
spec = builtins.fromJSON (builtins.readFile ../../../nix/nixpkgs/nixpkgs-src.json);
|
||||
spec =
|
||||
let versions = builtins.fromJSON (builtins.readFile ../../../nix/versions.json);
|
||||
in versions.nixpkgs;
|
||||
nixpkgs =
|
||||
(builtins.fetchTarball
|
||||
{ url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
|
||||
|
Loading…
Reference in New Issue
Block a user