I am starting a Python project that was imported through git.
However, the default branch in my git repository does not have a nix configuration file.
When I switched to the development branch and rebuilt the environment, I found that the onCreate field did not take effect (no .venv environment was generated), but the onStart field did take effect and the command was successfully executed.
my dev.nix file (I hide a part of onCreate command)
{ pkgs, ... }: {
# Which nixpkgs channel to use.
channel = "stable-23.11"; # or "unstable"
# Use https://search.nixos.org/packages to find packages
packages = [
pkgs.python311
pkgs.python311Packages.pip
pkgs.ffmpeg-full
pkgs.pre-commit
pkgs.openssh
pkgs.util-linux
];
# Sets environment variables in the workspace
env = {
"APP_PATH" = "/home/user/sekai-backend";
};
idx = {
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
extensions = [
"ms-python.flake8"
"ms-python.debugpy"
"ms-python.python"
];
# Enable previews
previews = {
enable = false;
previews = {
};
};
# Workspace lifecycle hooks
workspace = {
# Runs when a workspace is first created
onCreate = {
prepare = ''
python3 -m venv ".venv"
source .venv/bin/activate
pip install -r requirements.txt
pip install fastapi uvicorn[standard]
pip install pre-commit && pre-commit install
'';
};
onStart = {
redis = "chmod 400 portforward.pem && ssh -i \"./portforward.pem\" -L 6378:############## -N";
};
};
};
}