Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
88 changes: 69 additions & 19 deletions nix/overlays/dfinity-sdk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,72 @@ in {

dfx-release = mkRelease "dfx" self.releaseVersion packages.rust-workspace-standalone "dfx";

install-sh =
let
version = self.releaseVersion;
in super.runCommandNoCC "install-sh" {
installSh = ../../public/install.sh;
public = ../../public;
buildInputs = [ ];
} ''
# git describe --abbrev=7 --tags
mkdir -p $out

cat $public/install/*.sh > $out/install.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the ordering standard though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Globs were always sorted according to the locale.


# Get rid of comments that don't start with '##' or '#!'.
sed -i "
/#!.*/p
/##.*/p
/^ *$/d
/^ *#/d
s/ *#.*//
" $out/install.sh
'';

install-sh-lint =
let
version = self.releaseVersion;
shfmtOpts = "-p -i 4 -ci -bn -s";
shellcheckOpts = "-s sh -S warning";
in
super.runCommandNoCC "install-sh-lint" {
inherit version;
inherit (self) isMaster;
public = ../../public;
buildInputs = [ install-sh self.shfmt self.shellcheck ];
} ''
set -Eeuo pipefail
# Check if we have an sh compatible script
shckResult="$(shellcheck -Cnever -f gcc ${shellcheckOpts} "$public/install.sh" | \
grep -v "warning: In POSIX sh, 'local' is undefined. \[SC2039\]" | \
sed -e "s%^${install-sh}/?%%g" || true)"

if [ -n "$shckResult" ] ; then
echo "There are some shellcheck warnings:"
echo
echo "$shckResult"
echo
exit 1
fi

# Check if the file is properly formatted
if ! shfmt ${shfmtOpts} -d "${install-sh}/install.sh"; then
echo "Formatting error. Please run:"
echo
echo "shfmt ${shfmtOpts} -w public/install.sh"
exit 1
fi

if grep source "${install-sh}/install.sh"; then
echo "Found a source above in the output. There should be none remaining (inlined)."
exit 1
fi

# Make sure Nix sees the output.
touch $out
'';

# The following prepares a manifest for copying install.sh
# The release part also checks if the install.sh script is well formatted and has no shellcheck issues.
# We ignore 'local' warning by shellcheck, because any existing sh implementation supports it.
Expand Down Expand Up @@ -67,35 +133,19 @@ in {
inherit version;
inherit (self) isMaster;
inherit revision;
installSh = ../../public/install.sh;
manifest = ../../public/manifest.json;
buildInputs = [ self.jo self.shfmt self.shellcheck ];
buildInputs = [ self.jo install-sh-lint install-sh ];
} ''
set -Eeuo pipefail
# Check if we have an sh compatible script
shckResult="$(shellcheck -Cnever -f gcc ${shellcheckOpts} "$installSh" | grep -v "In POSIX sh, 'local' is undefined." || true)"
if [ -n "$shckResult" ] ; then
echo "There are some shellcheck warnings:"
echo $shckResult
echo "Please run:"
echo "shellcheck ${shellcheckOpts} public/install.sh"
exit 1
fi

# Check if the file is properly formatted
if ! shfmt ${shfmtOpts} -d $installSh; then
echo "Please run:"
echo "shfmt ${shfmtOpts} -w public/install.sh"
exit 1
fi

# Building the artifacts
mkdir -p $out

version_manifest_file=$out/manifest.json

cp $manifest $version_manifest_file
# we stamp the file with the revision
substitute "$installSh" $out/install.sh \
substitute "${install-sh}/install.sh" $out/install.sh \
--subst-var revision

# Creating the manifest
Expand Down
Loading