dev-env: Use nix-shell for scripts instead of sourcing dade-common. (#10088)

* Introduce shell.nix to expose the Nix tooling, if required.

* dev-env: Rewrite the ghcide script to use nix-shell.

* language-support/hs: Use `nix-shell` for export-package.sh.

* Nix: Add a shebang to the Bazel wrapper script.

CHANGELOG_BEGIN
CHANGELOG_END

* dev-env: Standardize the `set` header in `ghcide`.
This commit is contained in:
Samir Talwar 2021-06-23 11:39:00 +02:00 committed by GitHub
parent 682c096d4f
commit e32856ecf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 35 deletions

View File

@ -1,4 +1,7 @@
#!/usr/bin/env bash
DADE_CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DADE_CURRENT_SCRIPT_DIR/../lib/dade-common"
bazel build @ghcide-exe//ghcide && bazel-bin/external/ghcide/ghcide-0.7.2.0/_install/bin/ghcide "$@"
#!/usr/bin/env nix-shell
#!nix-shell -i bash ../../shell.nix
set -euo pipefail
bazel build @ghcide-exe//ghcide
exec ./bazel-bin/external/ghcide/ghcide-0.7.2.0/_install/bin/ghcide "$@"

View File

@ -48,12 +48,17 @@ Also, in the instructions below we export the `daml-ledger` package to `/tmp` wh
make
make prefix=/usr/local/grpc install
## Install Nix
Follow the instructions from the [Nix manual][].
[Nix manual]: https://nixos.org/manual/nix/
## Clone daml repo, and export the daml-ledger package
cd /tmp
git clone https://github.com/digital-asset/daml.git
cd daml
eval $(dev-env/bin/dade-assist)
language-support/hs/bindings/export-package.sh /tmp
## Write a Daml Ledger App in Haskell (or copy one!), and build it

View File

@ -1,13 +1,15 @@
#!/usr/bin/env bash
#!/usr/bin/env nix-shell
#!nix-shell -i bash ../../../shell.nix
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
set -eou pipefail
if [ "$#" -ne 1 ]; then
echo "Expected exactly one argument."
echo "Usage: ${BASH_SOURCE[0]} TARGET_DIR"
exit 1
echo "Expected exactly one argument."
echo "Usage: ${BASH_SOURCE[0]} TARGET_DIR"
exit 1
fi
TARGET_DIR=$(realpath $1)

View File

@ -7,7 +7,7 @@ description: Haskell bindings for a DAML Ledger
license: Apache-2.0
author: The DAML Authors
maintainer: nick.chapman@digitalasset.com
github: https://github.com/digital-asset/daml
github: digital-asset/daml
dependencies:
- async

View File

@ -1,8 +1,8 @@
{ system ? builtins.currentSystem }:
{ system ? builtins.currentSystem
, pkgs ? import ./nixpkgs.nix { inherit system; }
}:
let
pkgs = import ./nixpkgs.nix { inherit system; };
# Selects "bin" output from multi-output derivations which are has it. For
# other multi-output derivations, select only the first output. For
# single-output generation, do nothing.
@ -27,10 +27,20 @@ in rec {
ghc = bazel_dependencies.ghc;
# Tools used in the dev-env. These are invoked through wrappers
# in dev-env/bin. See the development guide for more information:
# https://digitalasset.atlassian.net/wiki/spaces/DEL/pages/104431683/Maintaining+the+Nix+Development+Environment
tools = pkgs.lib.mapAttrs (_: pkg: selectBin pkg) (rec {
# wrap the .bazelrc to automate the configuration of
# `build --config <kernel>`
bazelrc =
let
kernel =
if pkgs.stdenv.targetPlatform.isLinux then "linux"
else if pkgs.stdenv.targetPlatform.isDarwin then "darwin"
else throw "unsupported system";
in
pkgs.writeText "daml-bazelrc" ''
build --config ${kernel}
'';
toolAttrs = rec {
# Code generators
make = pkgs.gnumake;
@ -139,24 +149,8 @@ in rec {
# Build tools
# wrap the .bazelrc to automate the configuration of
# `build --config <kernel>`
bazelrc =
let
kernel =
if pkgs.stdenv.targetPlatform.isLinux then "linux"
else if pkgs.stdenv.targetPlatform.isDarwin then "darwin"
else throw "unsupported system";
in
pkgs.writeText "daml-bazelrc" ''
build --config ${kernel}
'';
bazel = pkgs.writeScriptBin "bazel" (''
if [ -z "''${DADE_REPO_ROOT:-}" ]; then
>&2 echo "Please run bazel inside of the dev-env"
exit 1
fi
#!${pkgs.bash}/bin/bash
# Set the JAVA_HOME to our JDK
export JAVA_HOME=${jdk.home}
export GIT_SSL_CAINFO="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
@ -218,7 +212,10 @@ in rec {
template
]);
nix-store-gcs-proxy = pkgs.callPackage ./tools/nix-store-gcs-proxy {};
});
};
# Tools used in the dev-env. These are invoked through wrappers in dev-env/bin.
tools = pkgs.lib.mapAttrs (_: pkg: selectBin pkg) toolAttrs;
# Set of packages that we want Hydra to build for us
cached = bazel_dependencies // {

6
shell.nix Normal file
View File

@ -0,0 +1,6 @@
{ pkgs ? import ./nix/nixpkgs.nix { }
, default ? import ./nix/default.nix { inherit pkgs; }
}:
pkgs.mkShell {
buildInputs = pkgs.lib.attrsets.mapAttrsToList (name: value: value) default.toolAttrs;
}