Skip to content

Commit

Permalink
Support Nix to setup development environment
Browse files Browse the repository at this point in the history
  • Loading branch information
louischan-oursky committed Dec 23, 2024
1 parent 21b458b commit 89b393e
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
**/venv
**/var

# direnv
**/.envrc
**/.direnv

resources/**/generated
resources/portal/static/*
!resources/portal/static/img/*
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
/tls-key.pem
.parcel-cache/

# direnv
.envrc
.direnv/

# docker
docker-compose.override.yaml

Expand Down
32 changes: 31 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- [Contributing guide](#contributing-guide)
* [Install dependencies](#install-dependencies)
+ [Install dependencies with asdf and homebrew](#install-dependencies-with-asdf-and-homebrew)
+ [Install dependencies with Nix Flakes](#install-dependencies-with-nix-flakes)
* [Set up environment](#set-up-environment)
* [Set up the database](#set-up-the-database)
* [Set up MinIO](#setup-minio)
Expand All @@ -22,7 +24,9 @@ It also covers some common development tasks.

## Install dependencies

This project uses asdf, and there is a .tool-versions file at the project root.
### Install dependencies with asdf and homebrew

This project supports asdf, and there is a .tool-versions file at the project root.

1. Install asdf
2. Run the following to install all dependencies in .tool-versions
Expand Down Expand Up @@ -82,6 +86,32 @@ This project uses asdf, and there is a .tool-versions file at the project root.

7. Run `make vendor`.

### Install dependencies with Nix Flakes

This project supports Nix Flakes.
If you are not a Nix user, please see the above section instead.

1. Make a shell with dependencies installed.

You can either run

```sh
nix develop
```

Or if you are also a direnv and nix-direnv user, you can place a `.envrc` at the project
with the following content

```
# shellcheck shell=bash
if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
fi
use flake
```

2. Run `make build-frontend`.

## Set up environment

1. Set up environment variables
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ vendor:
go install golang.org/x/vuln/cmd/govulncheck@latest
go install golang.org/x/tools/cmd/goimports@latest
go install go.k6.io/xk6/cmd/xk6@latest
$(MAKE) build-frondend

.PHONY: build-frondend
build-frondend:
npm --prefix ./scripts/npm ci
npm --prefix ./authui ci
npm --prefix ./portal ci
Expand Down
98 changes: 98 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

117 changes: 117 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
description = "A basic flake with a shell";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};
go_1_22_7.url = "github:NixOS/nixpkgs/5ed627539ac84809c78b2dd6d26a5cebeb5ae269";
nodejs_20_9_0.url = "github:NixOS/nixpkgs/a71323f68d4377d12c04a5410e214495ec598d4c";
};

outputs =
{
nixpkgs,
flake-utils,
go_1_22_7,
nodejs_20_9_0,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
go_pkgs = go_1_22_7.legacyPackages.${system};
go = go_pkgs.go_1_22;
nodejs = nodejs_20_9_0.legacyPackages.${system}.nodejs_20;
in
{
devShells.default = pkgs.mkShell {
packages = [
go
nodejs
# The version of python3 does not matter that much.
pkgs.python3

pkgs.pkg-config

(go_pkgs.buildGoModule {
name = "mockgen";
src = go_pkgs.fetchFromGitHub {
owner = "golang";
repo = "mock";
rev = "v1.6.0";
sha256 = "sha256-5Kp7oTmd8kqUN+rzm9cLqp9nb3jZdQyltGGQDiRSWcE=";
};
subPackages = [ "mockgen" ];
vendorHash = "sha256-5gkrn+OxbNN8J1lbgbxM8jACtKA7t07sbfJ7gVJWpJM=";
})

(go_pkgs.buildGoModule {
name = "wire";
src = go_pkgs.fetchFromGitHub {
owner = "google";
repo = "wire";
rev = "v0.5.0";
sha256 = "sha256-9xjymiyPFMKbysgZULmcBEMI26naUrLMgTA+d7Q+DA0=";
};
vendorHash = "sha256-ZFUX4LgPte6oAf94D82Man/P9VMpx+CDNCTMBwiy9Fc=";
subPackages = [ "cmd/wire" ];
})

(go_pkgs.buildGoModule {
name = "govulncheck";
src = go_pkgs.fetchgit {
url = "https://go.googlesource.com/vuln";
rev = "refs/tags/v1.1.3";
hash = "sha256-ydJ8AeoCnLls6dXxjI05+THEqPPdJqtAsKTriTIK9Uc=";
};
vendorHash = "sha256-jESQV4Na4Hooxxd0RL96GHkA7Exddco5izjnhfH6xTg=";
subPackages = [ "cmd/govulncheck" ];
# checkPhase by default run tests. Running tests will result in build error.
# So we skip it.
doCheck = false;
})

(go_pkgs.buildGoModule {
name = "goimports";
src = go_pkgs.fetchgit {
url = "https://go.googlesource.com/tools";
rev = "refs/tags/v0.28.0";
hash = "sha256-BCxsVz4f2h75sj1LzDoKvQ9c8P8SYjcaQE9CdzFdt3w=";
};
vendorHash = "sha256-MSir25OEmQ7hg0OAOjZF9J5a5SjlJXdOc523uEBSOSs=";
subPackages = [ "cmd/goimports" ];
})

(go_pkgs.buildGoModule {
name = "xk6";
src = go_pkgs.fetchFromGitHub {
owner = "grafana";
repo = "xk6";
rev = "v0.13.3";
sha256 = "sha256-lmtGljTLbcOkE+CYupocM9gmHsTVnpPT9sXOKVuFOww=";
};
vendorHash = null;
doCheck = false;
subPackages = [ "cmd/xk6" ];
})
];
buildInputs = [
pkgs.icu
pkgs.vips
# file includes libmagic.
pkgs.file
];
nativeBuildInputs = [
pkgs.pkg-config
pkgs.icu
pkgs.vips
pkgs.file
];
};
}
);
}

0 comments on commit 89b393e

Please sign in to comment.