Skip to content

Commit

Permalink
Use dependencies installed using Nix if possible
Browse files Browse the repository at this point in the history
All development dependencies should be managed using Nix to ensure
reproducibility. For ease of use, the Nix dependencies are implicitly
used by all scripts.

This may cause a noticeable performance hit if Nix is installed. The
dependencies are assumed to be correctly installed if the environment
variable `IN_MINILUA_NIX_SHELL` is set to a non-empty value (`nix-shell`
exports this automatically). Hence, it's recommended to use the default
Nix workflow of developing inside a `nix-shell` to eliminate this
performance overhead.

Note that `shell.nix` was reformatted using `alejandra` (an
uncompromising Nix formatter) to adhere to standard Nix conventions
(e.g. spaces instead of tabs).
  • Loading branch information
ibbem authored and tn4799 committed Aug 1, 2023
1 parent 05865ba commit 21f2727
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 17 deletions.
2 changes: 2 additions & 0 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
source "$(dirname "${BASH_SOURCE[0]}")/_env.sh"

# common variables used by multiple scripts
FILES=$(find \( -path './build*' -prune -false \) -or \( -path './extern*' -prune -false \) -or -name '*.cpp' -or -name '*.hpp')
6 changes: 6 additions & 0 deletions scripts/_env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/usr/bin/env bash

export MAKEFLAGS=-j4

# Install dependencies using Nix, if installed.
if command -v nix >/dev/null && [ -n "IN_MINILUA_NIX_SHELL" ]
then
. <(nix print-dev-env -f "$(dirname "${BASH_SOURCE[0]}")/../shell.nix")
fi
2 changes: 2 additions & 0 deletions scripts/_run_luatest.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

source "$(dirname "${BASH_SOURCE[0]}")/_env.sh"

file="$1"

cmd="build/bin/MiniLua-bin --quiet"
Expand Down
3 changes: 1 addition & 2 deletions scripts/check_format.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash --pure ../shell.nix
#!/usr/bin/env bash

set -evx

Expand Down
3 changes: 1 addition & 2 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash --pure ../shell.nix
#!/usr/bin/env bash

DIR=$(dirname "${BASH_SOURCE[0]}")
source "$DIR/_common.sh"
Expand Down
2 changes: 2 additions & 0 deletions scripts/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ EOF
exit 1
fi

source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/_env.sh"

# Reformat C/C++ files that are part of the commit
for file in $(git diff --cached --name-only | grep -E '\.(c|h|cpp|hpp)$'); do
echo "Formatting $file"
Expand Down
2 changes: 2 additions & 0 deletions scripts/run_luatests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

source "$(dirname "${BASH_SOURCE[0]}")/_env.sh"

pushd build
make MiniLua-bin
popd
Expand Down
2 changes: 2 additions & 0 deletions scripts/setup_build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -ev

source "$(dirname "${BASH_SOURCE[0]}")/_env.sh"

mkdir -pv build
pushd build

Expand Down
2 changes: 2 additions & 0 deletions scripts/update_luatest.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

source "$(dirname "${BASH_SOURCE[0]}")/_env.sh"

file="$1"

cmd=build/bin/MiniLua-bin
Expand Down
2 changes: 2 additions & 0 deletions scripts/upload_coverage.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -ev

source "$(dirname "${BASH_SOURCE[0]}")/_env.sh"

pushd build
bash <(curl -s https://codecov.io/bash) -f coverage.info.cleaned
popd
43 changes: 30 additions & 13 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
{
sources ? import ./nix/sources.nix,
system ? builtins.currentSystem,
pkgs ?
import sources.nixpkgs {
overlays = [];
config = {};
inherit system;
},
sources ? import ./nix/sources.nix,
system ? builtins.currentSystem,
pkgs ?
import sources.nixpkgs {
overlays = [];
config = {};
inherit system;
},
}:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
niv
clang-tools
python3
];
nativeBuildInputs = with pkgs; [
# Build tools
niv
git
cmake

# Dependencies
boost
qt5.qtbase
qt5.qmake

# Tools
clang-tools
python3
lcov
gcovr
doxygen
which
curl
];

IN_MINILUA_NIX_SHELL = true;
}

0 comments on commit 21f2727

Please sign in to comment.