-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #695 from ZeusWPI/feature/flake-nix
Add Nix flake for devshell
- Loading branch information
Showing
3 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{ | ||
description = "Gandalf"; | ||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
devshell = { | ||
url = "github:chvp/devshell"; | ||
inputs = { | ||
flake-utils.follows = "flake-utils"; | ||
nixpkgs.follows = "nixpkgs"; | ||
}; | ||
}; | ||
}; | ||
|
||
outputs = { self, nixpkgs, devshell, flake-utils }: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = import nixpkgs { inherit system; overlays = [ devshell.overlays.default ]; }; | ||
in | ||
{ | ||
devShells = rec { | ||
default = gandalf; | ||
gandalf = pkgs.devshell.mkShell { | ||
name = "Gandalf"; | ||
imports = [ | ||
"${devshell}/extra/language/ruby.nix" | ||
"${devshell}/extra/git/hooks.nix" | ||
]; | ||
git.hooks = { | ||
enable = true; | ||
pre-commit = { | ||
text = "bundle exec rubocop"; | ||
}; | ||
}; | ||
packages = with pkgs; [ | ||
docker | ||
nodejs | ||
libyaml | ||
imagemagick | ||
]; | ||
language.ruby = { | ||
package = pkgs.ruby_3_0; | ||
nativeDeps = [ pkgs.libmysqlclient pkgs.zlib ]; | ||
}; | ||
env = [ | ||
{ | ||
name = "DATABASE_ROOT_PASSWORD"; | ||
eval = "gandalf"; | ||
} | ||
{ | ||
name = "TEST_DATABASE_URL"; | ||
eval = "mysql2://root:[email protected]:3306/gandalf_test"; | ||
} | ||
{ | ||
name = "DATABASE_URL"; | ||
eval = "mysql2://root:[email protected]:3306/gandalf"; | ||
} | ||
]; | ||
serviceGroups.server.services = { | ||
rails = { | ||
name = "server"; | ||
command = "rails db:prepare && rails s -p 3000"; | ||
}; | ||
mysql.command = "mysql"; | ||
redis.command = "redis-server --port 6379"; | ||
sidekiq.command = "bundle exec sidekiq"; | ||
}; | ||
commands = [ | ||
{ | ||
name = "gems:refresh"; | ||
category = "general commands"; | ||
help = "Install dependencies"; | ||
command = '' | ||
bundle install | ||
bundle pristine | ||
''; | ||
} | ||
{ | ||
name = "mysql"; | ||
category = "database"; | ||
help = "Start database docker"; | ||
command = '' | ||
trap "systemd-run --user docker stop gandalf-db" 0 | ||
docker run --name gandalf-db -p 3306:3306 --rm -v gandalf-db-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=$DATABASE_ROOT_PASSWORD mariadb:latest & | ||
wait | ||
''; | ||
} | ||
{ | ||
name = "mysql-console"; | ||
category = "database"; | ||
help = "Open database console"; | ||
command = '' | ||
docker exec -i gandalf-db mysql -uroot -p"$DATABASE_ROOT_PASSWORD" | ||
''; | ||
} | ||
{ | ||
name = "redis"; | ||
package = pkgs.redis; | ||
} | ||
]; | ||
}; | ||
}; | ||
} | ||
); | ||
} |