the-algorithm/flake.nix
Aaron Siddhartha Mondal eaae3e286e
❄️ Add Nix flake and pre-commit hooks
Setting up the different tools for development can be hard for new
contributors. This commit adds a Nix flake that provides a reproducible
development environment which is easy to set up and ensures consistent
code style across all subprojects.

The initial flake contains `git`, `pre-commit`, `which` and `bazelisk`
wrapped as a `bazel` executable. Dependencies like Rust, Scala etc may
be added in the `packages` attribute in the future.

The current pre-commit configuration is a no-op. Future commits may
enable the currently disabled parts of `pre-commit-hooks.nix` for a
gradual transition.

Supports `(x86_64|aarch64) (Linux|MacOS)` systems.
2023-04-01 03:26:02 +02:00

64 lines
1.6 KiB
Nix

{
description = "Twitter development environment";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
devenv.url = "github:cachix/devenv/latest";
pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix";
};
outputs = { self, nixpkgs, flake-utils, devenv, pre-commit-hooks-nix, ... } @ inputs:
flake-utils.lib.eachSystem [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
]
(system:
let
pkgs = import nixpkgs { inherit system; };
in
rec {
hooks = import ./pre-commit-hooks.nix {
inherit pkgs;
};
checks = {
pre-commit-check = pre-commit-hooks-nix.lib.${system}.run {
src = ./.;
hooks = hooks;
};
};
devShells = {
default = mkTwitterShell;
};
mkTwitterShell = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [{
pre-commit.hooks = hooks;
scripts.bazel.exec = "${pkgs.bazelisk}/bin/bazelisk $@";
packages = [
pkgs.git
pkgs.pre-commit
pkgs.which
];
enterShell = ''
# Remove potential previous Bazel aliases.
[[ $(type -t bazel) == "alias" ]] && unalias bazel
# Prettier color output for the ls command.
alias ls='ls --color=auto'
'';
}];
};
});
}