/ flake.nix
flake.nix
 1  # The core functionality is provided here using flakes. Legacy support for
 2  # `nix-shell` is provided by a wrapper in `shell.nix`.
 3  
 4  # TODO Hacking around the Qt problems
 5  # TODO PyPI package not in nixpkgs
 6  {
 7    description = "Python development environment";
 8    inputs = {
 9      nixpkgs     .url = "github:nixos/nixpkgs/nixos-22.05";
10      flake-utils .url = "github:numtide/flake-utils";
11      flake-compat = {
12        url = "github:edolstra/flake-compat";
13        flake = false;
14      };
15    };
16  
17    outputs = { self, nixpkgs, flake-utils, ... }:
18      # Option 1: try to support each default system
19      flake-utils.lib.eachDefaultSystem # NB Some packages in nixpkgs are not supported on some systems
20        # Option 2: try to support selected systems
21        # flake-utils.lib.eachSystem ["x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin"]
22        (system:
23          let
24            pkgs = import nixpkgs {
25              inherit system;
26              # Any overlays you need can go here
27              overlays = [ ];
28            };
29            # ----- A Python interpreter with the packages that interest us -------
30            python-with-all-my-packages = (python:
31              (python.withPackages (ps: with ps; [
32                pytest
33                fastapi
34                uvicorn
35                sqlalchemy
36                psycopg2
37              ])));
38          in
39          rec {
40  
41            #devShell = self.devShells.${ system }.python310; # does not need `rec`
42            devShell = devShells.python310;
43            devShells =
44              builtins.listToAttrs (
45                builtins.map
46                  (
47                    pythonVersion: {
48                      name = pythonVersion;
49                      value = pkgs.mkShell {
50                        buildInputs = [
51                          (python-with-all-my-packages pkgs.${ pythonVersion })
52                        ];
53                        packages = [
54                          pkgs.python3Packages.python-lsp-server
55                          pkgs.postgresql
56                        ];
57                        shellHook =
58                          ''
59                            export PGDATA=$PWD/postgres_data
60                            export PGHOST=$PWD/postgres
61                            export LOG_PATH=$PWD/postgres/LOG
62                            export PGDATABASE=dustforce
63                            export DATABASE_URL="postgresql:///postgres?host=$PGHOST"
64                            ./start.sh
65                          '';
66                      };
67                    }
68                  ) [ "python310" ]
69              );
70          }
71        );
72  }