Files
archtika/flake.nix

130 lines
3.9 KiB
Nix
Raw Permalink 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;
dbUrl = user: "postgres://${user}@127.0.0.1:15432/archtika";
2024-07-31 07:23:32 +02:00
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
2024-10-03 18:51:30 +02:00
postgrest
];
shellHook = ''
alias dbmate="${pkgs.dbmate}/bin/dbmate --no-dump-schema --url ${dbUrl "postgres"}?sslmode=disable"
alias formatsql="${pkgs.pgformatter}/bin/pg_format -s 2 -f 2 -U 2 -i db/migrations/*.sql"
alias dbconnect="${pkgs.postgresql}/bin/psql ${dbUrl "postgres"}"
'';
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 =
let
settings = {
maxStorage = 100;
maxWebsites = 3;
};
jwtSecret = "BMlgCY9fEzmf7jhQpNnxlS6TM8E6xk2vS08C3ukm5LM2aTooaF5PfxT3o2K9uKzq";
in
"${pkgs.writeShellScriptBin "api-setup" ''
${pkgs.postgresql}/bin/psql ${dbUrl "postgres"} \
-c "ALTER DATABASE archtika SET \"app.jwt_secret\" TO '${jwtSecret}'" \
-c "ALTER DATABASE archtika SET \"app.website_max_storage_size\" TO ${toString settings.maxStorage}" \
-c "ALTER DATABASE archtika SET \"app.website_max_number_user\" TO ${toString settings.maxWebsites}"
2024-08-09 17:04:33 +02:00
${pkgs.dbmate}/bin/dbmate --no-dump-schema \
--url ${dbUrl "postgres"}?sslmode=disable \
--migrations-dir ${self.outPath}/rest-api/db/migrations up
2024-08-09 17:04:33 +02:00
PGRST_ADMIN_SERVER_PORT=3001 \
PGRST_DB_SCHEMAS="api" \
PGRST_DB_ANON_ROLE="anon" \
PGRST_OPENAPI_MODE="ignore-privileges" \
PGRST_DB_URI="${dbUrl "authenticator"}" \
PGRST_JWT_SECRET="${jwtSecret}" \
${pkgs.postgrest}/bin/postgrest
''}/bin/api-setup";
2024-08-09 17:04:33 +02:00
};
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
);
};
}