Skip to content

Commit

Permalink
Setup dev dependencies using nix flakes and devenv.sh
Browse files Browse the repository at this point in the history
See https://devenv.sh/ and https://github.com/direnv/direnv.

Start your development environment by copying .envrc.example to .envrc
and use `direnv allow` to enable.

After the build completes (it is cached) you can run `devenv up` to
start PostgreSQL on port 6543. Use `devenv test` to create the
databases and run the tests.
  • Loading branch information
erikrozendaal committed Jan 22, 2025
1 parent 7e87209 commit 6a33f31
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .envrc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Use Nix to setup development dependencies, github hooks, and services with `devenv`.
# See `flake.nix` for the setup.
watch_file flake.nix
watch_file flake.lock
use flake . --no-pure-eval
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ tmp/*
.vscode
integration-specs/rails-app/Gemfile.lock
integration-specs/simple/Gemfile.lock
.envrc
.devenv
/.pre-commit-config.yaml
262 changes: 262 additions & 0 deletions flake.lock

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

85 changes: 85 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
inputs = {
nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
systems.url = "github:nix-systems/default";
devenv.url = "github:cachix/devenv";
devenv.inputs.nixpkgs.follows = "nixpkgs";
};

nixConfig = {
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
extra-substituters = "https://devenv.cachix.org";
};

outputs = { self, nixpkgs, devenv, systems, ... } @ inputs:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
{
packages = forEachSystem (system: {
devenv-up = self.devShells.${system}.default.config.procfileScript;
devenv-test = self.devShells.${system}.default.config.test;
});

devShells = forEachSystem
(system:
let
postgresPort = 6543;
pkgs = nixpkgs.legacyPackages.${system};
in
{
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
{
env.PGPORT = postgresPort;

enterTest = ''
reset-database
run-tests
'';

git-hooks.hooks.rubocop = {
enable = true;
name = "rubocop";
types = [ "ruby" ];
excludes = [
"^docs/.*$"
"^integration-specs/rails-app/(bin|db)/.*$"
"^integration-specs/rails-app/config/puma.rb$"
];
entry = "bundle exec rubocop";
};

languages.ruby = {
enable = true;
package = pkgs.ruby;
};

services.postgres = {
enable = true;
listen_addresses = "127.0.0.1";
port = postgresPort;
initialScript = ''
CREATE ROLE sequent LOGIN SUPERUSER;
'';
settings = {
log_min_duration_statement = "100ms";
};
};

# https://devenv.sh/reference/options/
packages = with pkgs; [
libyaml
pkg-config
postgresql
];

scripts.run-tests.exec = "bundle exec rspec";
scripts.reset-database.exec = "SEQUENT_ENV=test bundle exec rake sequent:db:drop sequent:db:create";
}
];
};
});
};
}

0 comments on commit 6a33f31

Please sign in to comment.