Skip to content

Commit

Permalink
feat(nix-shell): Add support for nix-shell
Browse files Browse the repository at this point in the history
Signed-off-by: ESCristiano <[email protected]>
  • Loading branch information
ESCristiano committed Jun 19, 2023
1 parent 3003881 commit d00ccf2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ If you prefer, you can build the container image locally by running:
```bash
make -C ci/docker build
```

---

**NOTE**
Expand All @@ -139,6 +138,30 @@ locally.

---

## Using the Bao-Project Nix Shell

Nix provides a robust and reproducible environment by encapsulating all necessary dependencies within a controlled environment. This approach effectively eliminates issues associated with version conflicts and missing packages/dependencies, ensuring a seamless and reliable development experience.

We offer a nix-shell environment containing all essential Bao-Project dependencies, allowing developers to effortlessly work across all Bao-Project repositories. The required dependencies will be automatically fetched. If you already have the necessary packages/dependencies installed, Nix will prioritize the ones it fetched, ensuring reproducibility. Once you exit the nix-shell environment, those packages are no longer accessible. The Nix packages are isolated from your system packages, eliminating any risk of corruption.

You can utilize the Bao-Project nix-shell in two ways: (1) run a standalone command within the Bao-Project nix-shell environment; (2) or open an interactive Bao-Project nix-shell environment.

**Running a Standalone Command**

This command opens a nix-shell, executes the provided user command, and automatically closes the shell.

```bash
make nix-shell-run cmd="your command"
```

**Opening a Nix-Shell Environment**

This command opens an interactive nix-shell with all the Bao-Project dependencies.

```bash
make nix-shell
```

## Setting up GitHub Actions

When setting up GitHub Actions' workflows for you repo, each step should make
Expand Down
27 changes: 27 additions & 0 deletions ci.mk
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,32 @@ endef

#############################################################################

# Nix-shell
# Provides a nix-shell with the bao-project environment (i.e, all bao-project
# dependencies) which can be used to run the commands/tools used accross all
# bao-project repositories.
# To open an interactive nix-shell with the bao-project environment:
# make nix-shell
# To run a standalone commnand inside the nix-shell use:
# make nix-shell-run cmd="command-to-run"
# @param The command to run inside the nix-shell.
# @example make nix-shell-run cmd="ls"
# @example $(call ci, nix-shell-run, ls)

nix-shell:
@nix-shell $(ci_dir)/shell.nix

nix-shell-run:
@nix-shell $(ci_dir)/shell.nix --run "$(cmd)"

.PHONY: nix-shell nix-shell-run
non_build_targets+=nix-shell nix-shell-run

define nix-shell-run
cmd:=$1
endef

#############################################################################

ci=$(eval $(call $1, $2, $3, $4, $5, $6, $7, $8, $9))

22 changes: 22 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let
pkgs = import <nixpkgs> {};

in
pkgs.mkShell {
buildInputs = [
pkgs.docutils
pkgs.sphinx
pkgs.python311Packages.sphinxcontrib-spelling
pkgs.python311Packages.sphinx-tabs
pkgs.python311Packages.pyenchant
pkgs.python311Packages.doc8
pkgs.enchant
pkgs.python311Packages.sphinx-rtd-theme
];
shellHook = ''
echo ""
echo "######################################################################"
echo "# Welcome to bao-project Nix shell environment! #"
echo "######################################################################"
'';
}

0 comments on commit d00ccf2

Please sign in to comment.