Skip to content
Permalink
Browse files

Merge pull request #419 from input-output-hk/rvl/auto-regenerate

nix: Add script for auto-regenerating and fix the build
  • Loading branch information...
KtorZ committed Jul 12, 2019
2 parents 596103b + c8757ff commit 39050fd491e36ca0c40e5519fcb5e402d44b0bc3
Showing with 90 additions and 11 deletions.
  1. +1 −1 .buildkite/pipeline.yml
  2. +1 −2 .gitattributes
  3. +1 −0 .gitignore
  4. +0 −3 cabal.project
  5. +3 −1 default.nix
  6. +79 −0 nix/check-nix-tools.nix
  7. +5 −4 nix/update-iohk-nix.sh
@@ -5,6 +5,6 @@ steps:
system: x86_64-linux

- label: Check auto-generated Nix
command: 'nix-build -A iohkLib.check-nix-tools -o check-nix-tools.sh && ./check-nix-tools.sh'
command: 'nix-build -A checks.check-nix-tools -o check-nix-tools.sh && ./check-nix-tools.sh'
agents:
system: x86_64-linux
@@ -2,5 +2,4 @@
# Hide nix/.stack.nix/*.nix
# That is stuff that is generated by nix-tools stack-to-nix

nix/.stack.nix/*.nix linguist-generated=true
.stack-to-nix.cache linguist-generated=true
nix/.stack.nix/*.nix linguist-generated=true merge=union
@@ -26,3 +26,4 @@ cabal.project.local~

### Nix ###
result*
.stack-to-nix.cache
@@ -2,7 +2,4 @@ packages:
cardano-wallet.cabal
lib/*/*.cabal

benchmarks: True
tests: True

flags: +development
@@ -49,7 +49,9 @@ in {
text-class
];
buildInputs =
with pkgs.haskellPackages; [ cabal-install hlint stylish-haskell weeder ghcid ]
with pkgs.haskellPackages; [ hlint stylish-haskell weeder ghcid ]
++ [ cardano-http-bridge jormungandr cardano-sl-node pkgs.pkgconfig pkgs.sqlite-interactive ];
};

checks.check-nix-tools = pkgs.callPackage ./nix/check-nix-tools.nix {};
}
@@ -0,0 +1,79 @@
# This is a a CI check script that runs nix/regenerate.sh in the
# project repository. If anything changes, then it uploads the patch
# to Buildkite. If run on a PR branch, and there is a SSH key present,
# it will attempt to push the changes back to the PR.

{ stdenv, writeScript, coreutils, nixStable, git, gawk }:

with stdenv.lib;

writeScript "check-nix-tools.sh" ''
#!${stdenv.shell}
set -euo pipefail
export PATH="${makeBinPath [ stdenv.shellPackage coreutils nixStable git gawk ]}:$PATH"
cd $(git rev-parse --show-toplevel)
# The regenerate script is here by convention
./nix/regenerate.sh
# The generated files will appear somewhere under ./nix
git add -A nix
# Check if there are changes staged for commit.
if git diff-index --cached --quiet HEAD --; then
echo "Generated Nix code is up-to-date."
exit 0
else
echo "Committing changes..."
commit_message="Regenerate nix"
# If on a PR branch, search for a previous regen commit to fix up.
commit_fixup=""
if [ -n "''${BUILDKITE_PULL_REQUEST_BASE_BRANCH:-}" ]; then
git fetch -v origin $BUILDKITE_PULL_REQUEST_BASE_BRANCH
commit_fixup=$(git log --pretty=oneline --no-decorate origin/$BUILDKITE_PULL_REQUEST_BASE_BRANCH..HEAD | awk "/$commit_message/ { print \$1; }")
fi
# Create the commit
export GIT_COMMITTER_NAME="IOHK"
export GIT_COMMITTER_EMAIL="devops+nix-tools@iohk.io"
export GIT_AUTHOR_NAME="$GIT_COMMITTER_NAME"
export GIT_AUTHOR_EMAIL="$GIT_COMMITTER_EMAIL"
if [ -n "$commit_fixup" ]; then
git commit --no-gpg-sign --fixup "$commit_fixup"
else
git commit --no-gpg-sign --message "$commit_message"
fi
# If running in Buildkite...
if [ -n "''${BUILDKITE_JOB_ID:-}" ]; then
# Upload the patch as a Buildkite artifact
patch="$BUILDKITE_PIPELINE_SLUG-nix-$BUILDKITE_BUILD_NUMBER.patch"
git format-patch --stdout -1 HEAD > "$patch"
buildkite-agent artifact upload "$patch" --job "$BUILDKITE_JOB_ID"
# Push the changes back to the pull request
if [ -n "''${BUILDKITE_PULL_REQUEST_REPO:-}" ]; then
sshkey="/run/keys/buildkite-$BUILDKITE_PIPELINE_SLUG-ssh-private"
if [ -e $sshkey ]; then
echo "Authenticating using SSH with $sshkey"
export GIT_SSH_COMMAND="ssh -i $sshkey -F /dev/null"
remote=$(echo $BUILDKITE_PULL_REQUEST_REPO | sed -e 's=^[a-z]*://github.com/=git@github.com:=')
git push $remote HEAD:$BUILDKITE_BRANCH
exit 0
else
echo "There is no SSH key at $sshkey"
echo "The updates can't be pushed."
echo "Apply the patch $patch from the build artifacts"
fi
fi
fi
exit 1
fi
''
@@ -1,9 +1,10 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix-prefetch-git
#!nix-shell -i bash -p nix-prefetch-git coreutils

set -euo pipefail

NIX_DIR=`dirname $0`
nix_dir=$(dirname $0)
json="$nix_dir/iohk-nix-src.json"

nix-prefetch-git https://github.com/input-output-hk/iohk-nix \
> $NIX_DIR/iohk-nix-src.json
nix-prefetch-git --quiet --url https://github.com/input-output-hk/iohk-nix | tee "$json"
echo "Updated $json"

0 comments on commit 39050fd

Please sign in to comment.
You can’t perform that action at this time.