Skip to content

Commit

Permalink
Merge pull request #6 from tennox/devenv
Browse files Browse the repository at this point in the history
πŸ§‘β€πŸ’»  add nix flake & devenv
  • Loading branch information
linux-china authored Dec 10, 2023
2 parents a924fda + d489bb6 commit 8412ea2
Show file tree
Hide file tree
Showing 8 changed files with 600 additions and 3 deletions.
12 changes: 12 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail

# Docs: https://direnv.net/

if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8="
fi

nix_direnv_watch_file devenv.nix

use flake . --impure
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,13 @@ Cargo.lock

vendor/
*.lock

##########
# DEVENV #
##########
/.direnv/
/.devenv/
# auto-generated by devenv
/.pre-commit-config.yaml
/result
!/flake.lock
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Setting up a devenv

1. Install [nix](https://github.com/DeterminateSystems/nix-installer) (or install the required dependencies yourself, but for e.g. tests, there are a lot)
2. Install [direnv](https://direnv.net/) (optional, recommended for ease of use)
3. Run `direnv allow` / `nix develop --impure`

### Tests
Note: I did not manage to set up all dependencies yet - e.g. java tests are failing
```bash
# enter shell:
nix develop --impure .#test
# run directly:
nix develop --impure .#test -c cargo test
```
38 changes: 38 additions & 0 deletions devenv-test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Docs: https://devenv.sh/basics/
{ pkgs, ... }: {
name = "tk test";

# Extend main devenv:
imports = [ ./devenv.nix ];

languages = {
# Docs: https://devenv.sh/languages/
java.enable = true;
javascript.enable = true;
python.enable = true;
};

packages = with pkgs; [
# Search for packages: https://search.nixos.org/packages?channel=unstable&query=cowsay
# (note: this searches on unstable channel, be aware your nixpkgs flake input might be on a release channel)

go-task
gnumake
deno
sbt
go-task
cargo-make
jbang

#handled by `languages` above:
# python3
# nodejs
# adoptopenjdk-jre-bin
];

env = {
NODE_HOME = "${pkgs.nodejs}";
# JAVA_HOME = "${pkgs.adoptopenjdk-jre-bin.home}"; - seems to be handled by languages.java
JBANG_HOME = "${pkgs.jbang}/bin";
};
}
31 changes: 31 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Docs: https://devenv.sh/basics/
{ pkgs, ... }: {

languages = {
# Docs: https://devenv.sh/languages/
nix.enable = true;
rust = {
enable = true; # https://github.com/cachix/devenv/blob/main/src/modules/languages/rust.nix
channel = "nightly";
};
};

packages = with pkgs; [
# Search for packages: https://search.nixos.org/packages?channel=unstable&query=cowsay
# (note: this searches on unstable channel, be aware your nixpkgs flake input might be on a release channel)
cargo-watch
];

#difftastic.enable = true; # Better git diff https://devenv.sh/integrations/difftastic/

pre-commit.hooks = {
# Docs: https://devenv.sh/pre-commit-hooks/
# available pre-configured hooks: https://devenv.sh/reference/options/#pre-commithooks
# adding hooks which are not included: https://github.com/cachix/pre-commit-hooks.nix/issues/31
nixpkgs-fmt.enable = true; # nix formatting
nil.enable = true; # nix check

clippy.enable = true;
#cargo-check.enable = true; ← alternative to clippy
};
}
Loading

0 comments on commit 8412ea2

Please sign in to comment.