File size: 1,805 Bytes
47b2311
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{ pkgs, ... }: {
  # Which nixpkgs channel to use.
  channel = "stable-24.05"; # or "unstable"

  # Use https://search.nixos.org/packages to find packages
  packages = [
    pkgs.python311
    pkgs.python311Packages.pip
    pkgs.python311Packages.virtualenv
    pkgs.python311Packages.black  # Optional: Add a popular Python code formatter
    pkgs.python311Packages.isort  # Optional: Add a Python code sorter
    pkgs.python311Packages.flake8 # Optional: Add a Python linter
  ];

  # Sets environment variables in the workspace
  env = {
    PYTHONPATH = "$HOME/.local/lib/python3.11/site-packages";
  };

  idx = {
    # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
    extensions = [
      # "vscodevim.vim"  # Uncomment if you want the Vim extension for VSCode
    ];

    # Enable previews
    previews = {
      enable = true;
      previews = {
        # Example for running a Python script in a web preview:
        # web = {
        #   command = ["python" "app.py"];
        #   manager = "web";
        #   env = {
        #     # Set environment variables like PORT if needed
        #     PORT = "$PORT";
        #   };
        # };
      };
    };

    # Workspace lifecycle hooks
    workspace = {
      # Runs when a workspace is first created
      onCreate = {
        # Example: Set up a virtual environment and install dependencies
        install_dependencies = ''
          python3 -m venv .venv
          . .venv/bin/activate
          pip install -r requirements.txt  # Assuming a requirements.txt file exists
        '';
      };
      # Runs when the workspace is (re)started
      onStart = {
        # Example: Run a background task like starting a Python server
        # start-server = "python3 -m http.server";
      };
    };
  };
}