This project aims to simplify generating the infrastructure for common types of projects.
nix-bootstrap provides development infrastructure and pre-commit hooks as well as some production build configurations.
Expand feature tables
Existing features and toolchains supported have been decided based on the needs of the internal developer community within GCHQ.
That said, if there's a toolchain/feature set you'd like that we don't support, feel free to contribute it!
The following symbols are used throughout this page to indicate support status:
Symbol | Meaning |
---|---|
β | Fully Supported |
π | Partially Supported |
π | Support Planned |
β | Not Supported |
Toolchain\\Feature | Development Environment | VSCode DevContainer | Gitignore | Pre-Commit Hooks1 | Reproducible Production Builds |
---|---|---|---|---|---|
Elm | β
Either as a standalone app or as part of a Node project with Parcel. |
β
With the Elm extension installed. |
β | β | β |
Golang | β | β
With the official Go extension installed. |
β | β | π Support is currently considered experimental. |
Haskell | β
Either as a simple project or just a place to run a repl. |
β
With the haskell.haskell extension installed. |
β | β | β |
Java | β
With maven, google-java-format, and optionally minishift. |
β
With the official Java, and optionally the Lombok, extensions installed. |
β | β | π Only supports Spring applications. Support is currently considered experimental. |
Minimal (With no project-specific tooling) | β | β | β | π | β |
NodeJS | β
With latest stable node, AWS CLI, and optionally PNPm/Yarn. |
β | β | β | β |
Python | β
With Python version 3.9 |
β
With the official Python VSCode extension. |
β | π | β |
Rust | β | β
With the official rust-analyzer extension. |
β | β | β |
1 Marked as fully supported if any non-nix pre-commit hooks are added. See the Pre-Commit Hooks table below for details.
Toolchain\\Hook Type | Nix Formatting2 | Formatters | Linters | Testing |
---|---|---|---|---|
Elm | β | β
elm-format |
β
elm-review |
β |
Golang | β | β
go-fmt |
β | β
go test |
Haskell | β | β
ormolu |
β
hlint |
β |
Java | β | β
google-java-format |
β | β |
Minimal | β | β | β | β |
NodeJS | β | β
prettier |
β | β |
Python | β | β | β | β |
Rust | β | β
rustfmt |
β
cargo check + clippy |
β |
2 alejandra
is set up to format nix files.
nix-bootstrap provides configurations for GitLab CI out-of-the-box.
Scenario\\CI Job | Build Development Environment | Run Pre-Commit Hooks | Build For Production |
---|---|---|---|
Default | β | β | β |
Pre-Commit Hooks Enabled | β | β | β |
Pre-Commit Hooks Disabled, Production Build Configured | β | β | β |
Pre-Commit Hooks Enabled, Production Build Configured | β | β | β |
For Elm projects, it provides an additional CI job to build the Elm site.
Expand installation instructions
The simplest way to get started is to run the following script:
sh <(curl -L https://raw.githubusercontent.com/gchq/nix-bootstrap/main/scripts/run.sh)
Or to run nix-bootstrap with flakes enabled:
sh <(curl -L https://raw.githubusercontent.com/gchq/nix-bootstrap/main/scripts/run.sh) --experimental-use-flakes
Alternatively, you can always clone the repo and build nix-bootstrap using nix build
.
The built binary will then be available in ./result/bin/nix-bootstrap
.
We welcome contributions to the project. Detailed information on our ways of working can be found in CONTRIBUTING.md.
In brief:
- Sign the GCHQ Contributor Licence Agreement.
- Submit a pull request.
Expand development environment setup instructions
This section is for people who want to contribute to the nix-bootstrap tool.
-
Install nix by running the following command:
sh <(curl -L https://nixos.org/nix/install) --daemon
-
Install direnv >=2.23.0, by first installing the direnv package for your system.
- You can check your current version by running
direnv version
- On the latest Ubuntu, this is available using
apt-get
- If you can't install it through your OS's package manager, download a release from the GitHub releases page and put it somewhere on your
$PATH
.
- You can check your current version by running
-
Run
direnv allow
in the cloned directory -
Run
setUpHaskellLanguageServer
to ensure cabal and the HLS build correctly
You'll probably want to run your builds with Cabal during development as it builds incrementally by module.
- After a fresh clone, run
setUpHaskellLanguageServer
. This gets around a bug in Cabal. - During development, run builds with
cabal build -O0
. The-O0
(optimisation zero) flag speeds up the compilation process at the expense of not optimising the code for quicker run times. - You can run tests with
cabal test --test-show-details=streaming -O0
Nix should be used for production builds, as it enables several additional checks.
Run nix build
. This will produce a production binary at result/bin/nix-bootstrap
.
Note: ^ This command has a space in it, not a dash - this is a change since v1 of the nix CLI.
The nix-bootstrap source modules are grouped as follows (those without .hs
extensions are directories):
src/
βββ Bootstrap
βΒ Β βββ Cli.hs - Handling of nix-bootstrap's CLI options and producing its RunConfig from them
βΒ Β βββ Data - Data structures, including files we bootstrap
βΒ Β β βββ Bootstrappable - All the files we bootstrap
βΒ Β β βββ Go - Files we bootstrap which are specific to Go projects
βΒ Β β βββ Python - Files we bootstrap which are specific to Python projects
βΒ Β βββ Error.hs - Error handling helpers
βΒ Β βββ Monad.hs - Exposes MonadBootstrap, a collection of common constraints required by nix-bootstrap functions
βΒ Β βββ Niv.hs - Management of dependencies with Niv
β βββ Nix - Handling of writing and structuring Nix Code
β βΒ Β βββ Expr - A Nix AST and some common expressions formed with it
β βΒ Β βββ ReproducibleBuild - Expressions specific to producing reproducible builds
βΒ Β βββ State.hs - Management of state used for user interactions
βΒ Β βββ Terminal - Additional helpers for things displayed in the CLI
βΒ Β βββ Terminal.hs - Handles user interactions through the terminal
βΒ Β βββ Unix.hs - Provides an interface for interacting with other CLIs
βββ Bootstrap.hs - The main nix-bootstrap entrypoint
βββ Prelude.hs - A custom prelude
- Add a new
ProjectSuperType
and correspondingProjectType
to theBootstrap.Data.ProjectType
module - Run
cabal build -O0
, handling incomplete case statements until all of the warnings are fixed
-
Add a new module for the file under
Bootstrap.Data.Bootstrappable
-
In the new module:
- Create a datatype for the file
- Make that datatype an instance of
Bootstrap.Data.Bootstrappable.Bootstrappable
- Add a function which will return
Maybe a
wherea
is your datatype, depending on whether it is necessary to bootstrap the file under the given circumstances - Name the function in
2.3
using a suffix of "for" according to the conventions - seeBootstrap.Data.Bootstrappable.VSCodeSettings
vsCodeSettingsFor
for an example.
-
Call the function in
2.3
in themkInitialBuildPlanMap
function in theBootstrap
module
nix-bootstrap is released under the Apache 2.0 Licence and is covered by Crown Copyright.