Coder Social home page Coder Social logo

nix-bootstrap's Introduction

nix-bootstrap logo

nix-bootstrap

This project aims to simplify generating the infrastructure for common types of projects.

Features

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!

Key

The following symbols are used throughout this page to indicate support status:

Symbol Meaning
โœ… Fully Supported
๐ŸŸ  Partially Supported
๐Ÿ•“ Support Planned
โŒ Not Supported

Toolchain Support

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.

Pre-Commit Hooks

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.

Continuous Integration

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.

Installation & Usage

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.

Contributing

We welcome contributions to the project. Detailed information on our ways of working can be found in CONTRIBUTING.md.

In brief:

Development Environment Setup

Expand development environment setup instructions

This section is for people who want to contribute to the nix-bootstrap tool.

Environment Setup

  1. Install nix by running the following command:

    sh <(curl -L https://nixos.org/nix/install) --daemon
  2. Enable Nix Flakes.

  3. 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.
  4. Hook direnv into your shell

  5. Clone the nix-bootstrap repository

  6. Run direnv allow in the cloned directory

  7. Run setUpHaskellLanguageServer to ensure cabal and the HLS build correctly

Building nix-bootstrap with Cabal

You'll probably want to run your builds with Cabal during development as it builds incrementally by module.

  1. After a fresh clone, run setUpHaskellLanguageServer. This gets around a bug in Cabal.
  2. 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.
  3. You can run tests with cabal test --test-show-details=streaming -O0

Building nix-bootstrap with Nix

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.

Structure of the nix-bootstrap Repo

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

Common Scenarios

Adding support for a new toolchain
  1. Add a new ProjectSuperType and corresponding ProjectType to the Bootstrap.Data.ProjectType module
  2. Run cabal build -O0, handling incomplete case statements until all of the warnings are fixed
Adding a new file to the list of files to be bootstrapped
  1. Add a new module for the file under Bootstrap.Data.Bootstrappable

  2. In the new module:

    1. Create a datatype for the file
    2. Make that datatype an instance of Bootstrap.Data.Bootstrappable.Bootstrappable
    3. Add a function which will return Maybe a where a is your datatype, depending on whether it is necessary to bootstrap the file under the given circumstances
    4. Name the function in 2.3 using a suffix of "for" according to the conventions - see Bootstrap.Data.Bootstrappable.VSCodeSettings vsCodeSettingsFor for an example.
  3. Call the function in 2.3 in the mkInitialBuildPlanMap function in the Bootstrap module

License

nix-bootstrap is released under the Apache 2.0 Licence and is covered by Crown Copyright.

nix-bootstrap's People

Contributors

sd234678 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nix-bootstrap's Issues

Infer project name from directory name

Other tools such as npm init infer a default project name from the name of the current directory. Since we expect users to run in an empty directory created for their project, this seems sensible for us to do the same.

elm-review hook doesn't work in CI

The hook for elm-review doesn't work in CI as elm-json isn't available in the sandboxed environment mandated by nix build .\#runChecks doesn't contain it.

Find a way around this in a pure context.

Incorrect command in Elm CI

In the build site stage of generated CI for Elm projects, pnpm --frozen-lockfile should instead be pnpm install --frozen-lockfile.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.