about summary refs log tree commit diff stats
path: root/templates/unmaintained/python/flake.nix
blob: 36c7478149ece6b8a46b53bc8adf03db637e58ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{
  description = ""; # TODO: fill this out

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";

    mach-nix.url = "github:davhau/mach-nix";
  };

  outputs = {
    self,
    nixpkgs,
    mach-nix,
    flake-utils,
    ...
  }: let
    pythonVersion = "python39"; # TODO: update if necessary
  in
    flake-utils.lib.eachDefaultSystem (
      system: let
        pkgs = nixpkgs.legacyPackages.${system};
        mach = mach-nix.lib.${system};

        pythonApp = mach.buildPythonApplication ./.;
        pythonAppEnv = mach.mkPython {
          python = pythonVersion;
          requirements = builtins.readFile ./requirements.txt;
        };
        pythonAppImage = pkgs.dockerTools.buildLayeredImage {
          name = pythonApp.pname;
          contents = [pythonApp];
          config.Cmd = ["${pythonApp}/bin/main"];
        };
      in {
        packages = {
          image = pythonAppImage;
          pythonPkg = pythonApp;

          default = self.packages.pythonPkg;
        };

        apps.default = {
          type = "app";
          program = "${self.packages.pythonPkg}/bin/main";
        };

        devShells.default = pkgs.mkShell {
          packages = with pkgs; [
            pythonAppEnv
            black
            ruff
            python310Packages.python-lsp-server
            gnat
          ];

          env = {
            LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
              pkgs.stdenv.cc.cc
            ];

            PYTHONPATH = "${pythonAppEnv}/bin/python";
          };
        };
      }
    );
}