aboutsummaryrefslogtreecommitdiffstats
path: root/flake.nix
diff options
context:
space:
mode:
authorsadbeast <sadbeast@sadbeast.com>2024-06-23 15:36:59 -0700
committersadbeast <sadbeast@sadbeast.com>2024-07-13 21:58:23 -0700
commit8d018d996c1eddb882dc64ebbd228bb0135944f3 (patch)
treed01956546a77dbae33357c9a5d174f511ac9b282 /flake.nix
downloadteamdraft-8d018d996c1eddb882dc64ebbd228bb0135944f3.tar.gz
teamdraft-8d018d996c1eddb882dc64ebbd228bb0135944f3.tar.bz2
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix110
1 files changed, 110 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..7581a31
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,110 @@
+{
+ description = "Team Draft";
+
+ inputs = {
+ devshell.url = "github:numtide/devshell";
+ flake-parts.url = "github:hercules-ci/flake-parts";
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+ process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
+ services-flake.url = "github:juspay/services-flake";
+ treefmt-nix.url = "github:numtide/treefmt-nix";
+ };
+
+ outputs = inputs @ {
+ flake-parts,
+ ...
+ }:
+ flake-parts.lib.mkFlake {inherit inputs;} {
+ imports = [
+ inputs.devshell.flakeModule
+ inputs.process-compose-flake.flakeModule
+ inputs.treefmt-nix.flakeModule
+ ];
+ systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
+ perSystem = {
+ config,
+ self',
+ inputs',
+ pkgs,
+ system,
+ ...
+ }:
+ with builtins; rec {
+ # Per-system attributes can be defined here. The self' and inputs'
+ # module parameters provide easy access to attributes of the same
+ # system.
+ process-compose."services" = {
+ imports = [
+ inputs.services-flake.processComposeModules.default
+ ];
+ services.postgres."pg1" = {
+ enable = true;
+ package = pkgs.postgresql_16;
+ extensions = extensions: [
+ extensions.pgtap
+ extensions.pgsodium
+ ];
+
+ initialScript.before = replaceStrings ["$"] ["\\$"] (readFile ./src/db/schema.sql);
+ initialScript.after = replaceStrings ["$"] ["\\$"] (readFile ./src/db/seed.sql);
+ socketDir = "/tmp/pg1";
+ };
+ };
+
+ devshells.default = {
+ commands = [
+ {
+ name = "docs";
+ help = "generate auto docs";
+ command = "zig test -femit-docs src/main.zig";
+ }
+ {
+ name = "db";
+ help = "run postgresql";
+ command = "nix run .#services";
+ }
+ {
+ name = "dbreset";
+ help = "recreate db and run postgresql";
+ command = "rm -rf data && nix run .#services";
+ }
+ {
+ name = "ci";
+ help = "run all tests";
+ command = "zig build test && pg_prove";
+ }
+ {
+ name = "deploy";
+ help = "deploy to production lol";
+ command = ''zig build -Doptimize=ReleaseFast && scp -r zig-out/bin/* teamdraft: && ssh teamdraft -C "sudo systemctl stop teamdraft && sudo cp ./{teamdraft,scorecorder} /home/teamdraft/ && sudo systemctl start teamdraft"'';
+ }
+ ];
+ packages = with pkgs; [
+ kcov
+ perl538Packages.TAPParserSourceHandlerpgTAP
+ pgcli
+ postgresql_16
+ postgresql16Packages.pgtap
+ sops
+ zig
+ ];
+ };
+
+ treefmt.config = {
+ projectRootFile = "flake.nix";
+
+ flakeCheck = true;
+ flakeFormatter = true;
+
+ programs.zig.enable = true;
+ programs.alejandra.enable = true;
+ };
+ };
+
+ flake = {
+ # The usual flake attributes can be defined here, including system-
+ # agnostic ones like nixosModule and system-enumerating ones, although
+ # those are more easily expressed in perSystem.
+ };
+ };
+}