Skip to content

Commit

Permalink
Merge pull request avh4#559 from avh4/release-prep
Browse files Browse the repository at this point in the history
Automate updating the nix package
  • Loading branch information
avh4 authored Oct 3, 2018
2 parents 9ec7ef2 + f8ae638 commit c3be615
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
10 changes: 10 additions & 0 deletions PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,13 @@ npm dist-tag add elm-format@<new version> elm0.18.0
npm dist-tag add elm-format@<new version> elm0.19.0
npm dist-tag add elm-format@<new version> exp
```


## Nix

```
cd package/nix
./build.sh
```

Then `cd nixpkgs`, push the resulting branch, and make a PR to https://github.com/NixOS/nixpkgs with the title "elm-format: [old version] -> [new version]"
1 change: 1 addition & 0 deletions package/nix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/nixpkgs
37 changes: 37 additions & 0 deletions package/nix/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -exo pipefail

ELM_FORMAT_VERSION="$(git describe --abbrev=8)"
BRANCH="elm-format-$ELM_FORMAT_VERSION"

if [ ! -d nixpkgs ]; then
git clone https://github.com/NixOS/nixpkgs.git nixpkgs
fi

pushd nixpkgs
git fetch origin master
if git branch | grep " ${BRANCH}$"; then
git checkout "$BRANCH"
git reset --hard origin/master
else
git checkout -b "$BRANCH" origin/master
fi
popd

cabal2nix --no-check cabal://indents-0.3.3 > nixpkgs/pkgs/development/compilers/elm/packages/indents.nix
cabal2nix --no-check cabal://tasty-quickcheck-0.9.2 > nixpkgs/pkgs/development/compilers/elm/packages/tasty-quickcheck.nix
./generate_derivation.sh > nixpkgs/pkgs/development/compilers/elm/packages/elm-format.nix

pushd nixpkgs
rm -f result
nix-build -A elmPackages.elm-format
git status
result/bin/elm-format | head -n1
popd

set +x

echo
echo "Everything looks good!"
echo "You will need to make a PR from the $BRANCH branch"
43 changes: 43 additions & 0 deletions package/nix/generate_derivation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p git cabal2nix nix-prefetch-git jq

# This script generates the nix derivation for elm-format intended for nixpkgs:
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/elm/packages/elm-format.nix

# To use this script, run:
#
# $ ./generate_derivation.sh > elm-format.nix
#
# This might take a bit of time if the dependencies are not already in the nix
# store. If you already have all the dependencies installed, feel free to remove
# them from the shebang to speed up the process.

set -exo pipefail

REV="$(git rev-parse HEAD)"
VERSION="$(git describe --abbrev=8 "$REV")"
ROOTDIR="$(git rev-parse --show-toplevel)"
SHA="$(nix-prefetch-git --url "$ROOTDIR" --rev "$REV" --quiet --no-deepClone | jq --raw-output .sha256)"

PATCH=$(cat <<END
src = fetchgit {
url = "http://github.com/avh4/elm-format";
sha256 = "$SHA";
rev = "$REV";
};
postPatch = ''
sed -i "s|desc <-.*||" ./Setup.hs
sed -i "s|gitDescribe = .*|gitDescribe = \\\\\\\\\"$VERSION\\\\\\\\\"\"|" ./Setup.hs
'';
END
)

# quoteSubst from https://stackoverflow.com/a/29613573
quoteSubst() {
IFS= read -d '' -r < <(sed -e ':a' -e '$!{N;ba' -e '}' -e 's/[&/\]/\\&/g; s/\n/\\&/g' <<<"$1")
printf %s "${REPLY%$'\n'}"
}

cabal2nix --no-haddock "$ROOTDIR" |
sed "s#^{ mkDerivation#{ mkDerivation, fetchgit#" |
sed "s#\\s*src = .*;#$(quoteSubst "$PATCH")#"

0 comments on commit c3be615

Please sign in to comment.