materia/flake.nix

75 lines
2.3 KiB
Nix
Raw Normal View History

2024-05-07 16:49:30 +05:00
{
description = "Materia is a file server";
nixConfig = {
extra-substituters = [ "https://bonfire.cachix.org" ];
extra-trusted-public-keys = [ "bonfire.cachix.org-1:mzAGBy/Crdf8NhKail5ciK7ZrGRbPJJobW6TwFb7WYM=" ];
};
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, poetry2nix, ... }:
let
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" ];
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in
{
packages = forAllSystems (system: let
2024-05-07 16:49:30 +05:00
pkgs = nixpkgsFor.${system};
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication;
in {
materia = mkPoetryApplication {
projectDir = ./.;
};
default = self.packages.${system}.materia;
});
apps = forAllSystems (system: {
materia = {
2024-05-07 16:49:30 +05:00
type = "app";
program = "${self.packages.${system}.materia}/bin/materia";
2024-05-07 16:49:30 +05:00
};
default = self.apps.${system}.materia;
2024-05-07 16:49:30 +05:00
});
devShells = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
db_name = "materia";
db_user = "materia";
db_path = "temp/materia-db";
2024-05-07 16:49:30 +05:00
in {
default = pkgs.mkShell {
buildInputs = with pkgs; [
nil
nodejs
ripgrep
postgresql
poetry
2024-05-07 16:49:30 +05:00
];
LD_LIBRARY_PATH = nixpkgs.lib.makeLibraryPath [ pkgs.stdenv.cc.cc ];
shellHook = ''
trap "pg_ctl -D ${db_path} stop" EXIT
[ ! -d $(pwd)/${db_path} ] && initdb -D $(pwd)/${db_path} -U ${db_user}
pg_ctl -D $(pwd)/${db_path} -l $(pwd)/${db_path}/db.log -o "--unix_socket_directories=$(pwd)/${db_path}" start
[ ! "$(psql -h $(pwd)/${db_path} -U ${db_user} -l | rg '^ ${db_name}')" ] && createdb -h $(pwd)/${db_path} -U ${db_user} ${db_name}
'';
2024-05-07 16:49:30 +05:00
};
});
};
}