Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

[DEVOPS-1045] pkgs/generate.sh: Fix purity of script #3677

Merged
merged 2 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ scripts/haskell/dependencies.hi
scripts/haskell/dependencies.o
scripts/haskell/dependencies

# 'pkgs/stack2nix' is a symlink into the nix store, it can safely be ignored
pkgs/stack2nix
# Cache for pkgs/generate.sh
/pkgs/.cabal/
/pkgs/.stack/
# in case generate.sh clones nixpkgs in here
nixpkgs
pkgs/result

# explorer
explorer-node.log.*
Expand Down
39 changes: 4 additions & 35 deletions pkgs/generate.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash cabal2nix stack cabal-install ghc
#!/usr/bin/env bash

# Regenerate the `pkgs/default.nix` file based on the current
# contents of cardano-sl.cabal and stack.yaml, with a hackage snapshot.

# Update this if you need a package version recently uploaded to hackage.
# Any timestamp works.
hackageSnapshot="2018-07-17T09:58:14Z"

function runInShell {
local inputs="$1"
shift
nix-shell -j 4 -E "with import (import $scriptDir/../fetch-nixpkgs.nix) {}; runCommand \"shell\" { buildInputs = [ $inputs ]; } \"\"" --run "LANG=en_US.utf-8 NIX_REMOTE=$NIX_REMOTE $*"
}

set -xe
set -v

# Ensure that nix 1.11 (used by cabal2nix) works in multi-user mode.
if [ ! -w /nix/store ]; then
export NIX_REMOTE=${NIX_REMOTE:-daemon}
fi

# Get relative path to script directory
scriptDir="$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")"

echo "Using hackage snapshot from ${hackageSnapshot}"

pushd "${scriptDir}"

# https://github.com/NixOS/cabal2nix/issues/146
runInShell "cabal2nix glibcLocales" cabal2nix --system x86_64-darwin --revision 25a53d417d7c7a8fc3116b63e3ba14ca7c8f188f \
https://github.com/luite/hfsevents.git > hfsevents.nix

# Generate cardano-sl package set
runInShell "cabal2nix glibcLocales" "$(nix-build -A stack2nix --no-out-link -Q ../)/bin/stack2nix" --platform x86_64-linux --hackage-snapshot "${hackageSnapshot}" -j8 --test --bench --no-indent ./.. > default.nix.new
mv default.nix.new default.nix
popd
set -euo pipefail
cd "$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")"
exec $(nix-build --no-out-link regen.nix) "$@"
53 changes: 53 additions & 0 deletions pkgs/regen.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
let
localLib = import ../lib.nix;
jemallocOverlay = self: super: {
# jemalloc has a bug that caused cardano-sl-db to fail to link (via
# rocksdb, which can use jemalloc).
# https://github.com/jemalloc/jemalloc/issues/937
# Using jemalloc 510 with the --disable-initial-exec-tls flag seems to
# fix it.
jemalloc = self.callPackage ../nix/jemalloc/jemalloc510.nix {};
};
in
{ system ? builtins.currentSystem
, config ? {}
, pkgs ? (import (localLib.fetchNixPkgs) { inherit system config; overlays = [ jemallocOverlay ]; })
rvl marked this conversation as resolved.
Show resolved Hide resolved

# Update this if you need a package version recently uploaded to hackage.
# Any timestamp works.
, hackageSnapshot ? "2018-07-17T09:58:14Z"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if we run it without hackageSnapshot? I'm just wondering, because the LTS is specified in stack.yaml. Is this if the default in nixpkgs doesn't have that LTS version in it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timestamp is provided as an option to stack2nix. It needs to be there so that stack2nix has reproducible results (without it, latest hackage snapshot would be used).

}:

with pkgs;

let
iohkPkgs = import ../. { inherit system config pkgs; };
deps = [ nixStable coreutils git findutils cabal2nix glibcLocales stack cabal-install iohkPkgs.stack2nix ];
in
writeScript "generate.sh" ''
#!${stdenv.shell}
set -euo pipefail
export PATH=${lib.makeBinPath deps}
export HOME=$(pwd)

echo "Using hackage snapshot from ${hackageSnapshot}"

# Ensure that nix 1.11 (used by cabal2nix) works in multi-user mode.
rvl marked this conversation as resolved.
Show resolved Hide resolved
if [ ! -w /nix/store ]; then
export NIX_REMOTE=''${NIX_REMOTE:-daemon}
fi

function cleanup {
rm -rf hfsevents.nix.new default.nix.new
}
trap cleanup EXIT

# https://github.com/NixOS/cabal2nix/issues/146
cabal2nix --system x86_64-darwin --revision 25a53d417d7c7a8fc3116b63e3ba14ca7c8f188f \
https://github.com/luite/hfsevents.git > hfsevents.nix.new
mv hfsevents.nix.new hfsevents.nix

# Generate cardano-sl package set
stack2nix --platform x86_64-linux --hackage-snapshot "${hackageSnapshot}" -j8 --test --bench --no-indent ./.. > default.nix.new
mv default.nix.new default.nix
''
6 changes: 2 additions & 4 deletions scripts/check-stack2nix.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p git bash
#!nix-shell -i bash -p git bash nixStable

# check and warn if `pkgs/default.nix` is out of date

Expand All @@ -20,8 +20,6 @@ fail_stack2nix_check() {
# Get relative path to script directory
scriptDir=$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")

# shellcheck source=/dev/null
source "${scriptDir}/../pkgs/generate.sh"

"${scriptDir}/../pkgs/generate.sh"

git diff -w --text --exit-code || fail_stack2nix_check