Files
archtika/flake.nix

115 lines
3.8 KiB
Nix
Raw Normal View History

2024-07-31 07:23:32 +02:00
{
inputs = {
2024-09-19 17:04:36 +02:00
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2024-07-31 07:23:32 +02:00
};
outputs =
{ self, nixpkgs, ... }:
let
allSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = nixpkgs.lib.genAttrs allSystems;
in
{
devShells = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
api = pkgs.mkShell {
2024-10-03 18:51:30 +02:00
packages = with pkgs; [
postgresql_16
postgrest
];
shellHook = ''
2024-08-24 19:37:00 +02:00
alias dbmate="${pkgs.dbmate}/bin/dbmate --no-dump-schema --url postgres://postgres@localhost:15432/archtika?sslmode=disable"
alias formatsql="${pkgs.pgformatter}/bin/pg_format -s 2 -f 2 -U 2 -i db/migrations/*.sql"
alias dbconnect="${pkgs.postgresql_16}/bin/psql postgres://postgres@localhost:15432/archtika"
'';
2024-07-31 07:23:32 +02:00
};
web = pkgs.mkShell {
packages = with pkgs; [ nodejs_22 ];
shellHook = ''
export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
'';
};
2024-07-31 07:23:32 +02:00
}
);
packages = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
2024-08-13 11:36:32 +02:00
dev-vm = self.nixosConfigurations.dev-vm.config.system.build.vm;
default = pkgs.callPackage ./nix/package.nix { };
2024-09-29 15:00:19 +02:00
docker = pkgs.callPackage ./nix/docker.nix { };
}
);
apps = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
2024-08-09 17:04:33 +02:00
api = {
type = "app";
program = "${pkgs.writeShellScriptBin "api-setup" ''
JWT_SECRET=$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c64)
WEBSITE_MAX_STORAGE_SIZE=100
WEBSITE_MAX_NUMBER_USER=3
2024-09-14 20:28:27 +02:00
${pkgs.postgresql_16}/bin/psql postgres://postgres@localhost:15432/archtika -c "ALTER DATABASE archtika SET \"app.jwt_secret\" TO '$JWT_SECRET'"
${pkgs.postgresql_16}/bin/psql postgres://postgres@localhost:15432/archtika -c "ALTER DATABASE archtika SET \"app.website_max_storage_size\" TO $WEBSITE_MAX_STORAGE_SIZE"
${pkgs.postgresql_16}/bin/psql postgres://postgres@localhost:15432/archtika -c "ALTER DATABASE archtika SET \"app.website_max_number_user\" TO $WEBSITE_MAX_NUMBER_USER"
2024-08-09 17:04:33 +02:00
${pkgs.dbmate}/bin/dbmate --url postgres://postgres@localhost:15432/archtika?sslmode=disable --migrations-dir ${self.outPath}/rest-api/db/migrations up
2024-08-09 17:04:33 +02:00
2024-09-14 20:28:27 +02:00
PGRST_ADMIN_SERVER_PORT=3001 PGRST_DB_SCHEMAS="api" PGRST_DB_ANON_ROLE="anon" PGRST_OPENAPI_MODE="ignore-privileges" PGRST_DB_URI="postgres://authenticator@localhost:15432/archtika" PGRST_JWT_SECRET="$JWT_SECRET" ${pkgs.postgrest}/bin/postgrest
2024-08-09 17:04:33 +02:00
''}/bin/api-setup";
};
2024-07-31 07:23:32 +02:00
}
);
2024-08-11 19:53:22 +02:00
nixosConfigurations = {
dev-vm = nixpkgs.lib.nixosSystem {
2024-08-11 19:53:22 +02:00
system = "x86_64-linux";
modules = [ ./nix/dev-vm.nix ];
};
qs = nixpkgs.lib.nixosSystem {
2024-08-11 19:53:22 +02:00
system = "aarch64-linux";
2024-08-13 18:27:43 +02:00
modules = [
./nix/deploy/qs
{ _module.args.localArchtikaPackage = self.packages."aarch64-linux".default; }
];
};
prod = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
./nix/deploy/prod
2024-08-13 18:27:43 +02:00
{ _module.args.localArchtikaPackage = self.packages."aarch64-linux".default; }
];
2024-08-11 18:46:32 +02:00
};
2024-08-11 19:53:22 +02:00
};
2024-07-31 07:23:32 +02:00
formatter = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.nixfmt-rfc-style
);
};
}