{
  description = "Deepsad devenv with python 3.11";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
    poetry2nix = {
      url = "github:nix-community/poetry2nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    {
      self,
      nixpkgs,
      flake-utils,
      poetry2nix,
    }:
    flake-utils.lib.eachDefaultSystem (
      system:
      let
        # see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
        pkgs = import nixpkgs {
          inherit system;
          config.allowUnfree = true;
          config.cudaSupport = true;
        };
        thundersvm = import ./nix/thundersvm.nix {
          inherit pkgs;
          inherit (pkgs) fetchFromGitHub cmake gcc12Stdenv;
          cudaPackages = pkgs.cudaPackages;
        };

        thundersvm-python = import ./nix/thundersvm-python.nix {
          inherit pkgs;
          pythonPackages = pkgs.python311Packages;
          thundersvm =  thundersvm; 
        };
        inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication;
      in
      {
        packages = {
          deepsad = mkPoetryApplication {
            projectDir = self;
            preferWheels = true;
            python = pkgs.python311;
          };
          default = self.packages.${system}.deepsad;
        };

        devShells.default = pkgs.mkShell {
          inputsFrom = [ self.packages.${system}.deepsad ];
          buildInputs = with pkgs.python311Packages; [
            torch-bin
            torchvision-bin
            thundersvm-python
          ];
          #LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [ 
          #pkgs.stdenv.cc.cc
          #];
        };

        devShells.poetry = pkgs.mkShell {
          packages = [
            pkgs.poetry
            pkgs.python311
          ];
        };
      }
    );
}
