diff --git a/README.md b/README.md new file mode 100644 index 0000000..8788088 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# nix_virtualenvs + +This is a repository for different virtual environments, which can be used with the **Nix** package manager. + +Just copy the content of the desired folder to your project, add your required packages to the `*.txt` file and run `nix-shell`. diff --git a/README.org b/README.org deleted file mode 100644 index 931ba60..0000000 --- a/README.org +++ /dev/null @@ -1,34 +0,0 @@ -* nix_environments - - This is a set of various environments which can be used with the *Nix* package manager. - - Copy the =shell.nix= file from the desired folder into your project and run ~nix-shell~. - This will drop you into a virtual environment with all requirements fulfilled. - Please check below how the virtual environments work and how to add environment specific packages. - - If you need more Nix packages in your environent, enhance the list ~buildInputs~ in the file =shell.nix=. - -** node - - This environment does the following: - - 1. Create a directory =.npm/bin= if not existent - 2. Add the =.npm/bin= directory to the ~$PATH~ variable - 3. Upgrade npm to the latest version - 4. If the file =global_packages.txt= is present, install the packages via npm into the =.npm= directory - 5. Run ~npm install~ if a file =package.json= is present - -** python - - This environment does the following: - - 1. Create a new python virtualenv in the folder =.venv= if not existent - 2. Source the virtual environment - 3. Upgrade pip to the latest version - 4. If present, install the packages from the file =requirements.txt= via pip - -** rust - - This environment does the following: - - 1. Run ~cargo build~ if =Cargo.toml= is present diff --git a/node/shell.nix b/node/shell.nix deleted file mode 100644 index 6ec98a3..0000000 --- a/node/shell.nix +++ /dev/null @@ -1,38 +0,0 @@ -{ pkgs ? import {} }: -pkgs.mkShell { - buildInputs = with pkgs; [ - nodejs - ]; - shellHook = '' - function log_header { - echo -ne "==> \e[32m\e[1m$1\e[0m\n" - } - function log_subheader { - echo -ne "--> \e[33m\e[1m$1\e[0m\n" - } - function log { - echo -ne " $1\n" - } - - echo "" - log_header "node_environment" - mkdir -p .npm/bin - export PATH=$PWD/.npm/bin:$PATH - log_subheader "upgrading npm" - npm install -g npm --prefix $PWD/.npm - echo "" - if [ -s global_packages.txt ]; then - log_subheader "found global_packages.txt, installing packages" - cat global_packages.txt | xargs npm install -g --prefix $PWD/.npm - echo "" - fi - if [ -s package.json ]; then - log_subheader "found package.json, running 'npm install'" - npm install - echo "" - fi - log_header "package versions" - log "node $(node --version)" - log "npm $(npm --version)" - ''; -} diff --git a/node_environment/default.nix b/node_environment/default.nix new file mode 100644 index 0000000..88581ef --- /dev/null +++ b/node_environment/default.nix @@ -0,0 +1,19 @@ +with import {}; + +stdenv.mkDerivation { + name = "myNodeEnv"; + buildInputs = with pkgs; [ + nodejs + ]; + src = null; + shellHook = '' + mkdir -p .npm + if [ -s global_packages.txt ]; then + cat global_packages.txt | xargs npm install -g --prefix $PWD/.npm + fi + if [ -s package.json ]; then + npm install + fi + export PATH=$PWD/.npm/bin:$PATH + ''; +} diff --git a/node/global_packages.txt b/node_environment/global_packages.txt similarity index 100% rename from node/global_packages.txt rename to node_environment/global_packages.txt diff --git a/python/shell.nix b/python/shell.nix deleted file mode 100644 index b957648..0000000 --- a/python/shell.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ pkgs ? import {} }: -pkgs.mkShell { - buildInputs = with pkgs; [ - python3 - python3Packages.virtualenv - ]; - shellHook = '' - function log_header { - echo -ne "==> \e[32m\e[1m$1\e[0m\n" - } - function log_subheader { - echo -ne "--> \e[33m\e[1m$1\e[0m\n" - } - function log { - echo -ne " $1\n" - } - - echo "" - log_header "python_environment" - if [ ! -d .venv ]; then - python -m venv .venv - fi - source .venv/bin/activate - log_subheader "upgrading pip" - pip install --upgrade pip - echo "" - if [ -s requirements.txt ]; then - log_subheader "found requirements.txt, installing packages" - pip install -r requirements.txt - echo "" - fi - log_header "package versions" - log "$(python --version)" - log "$(pip --version)" - ''; -} diff --git a/python_environment/default.nix b/python_environment/default.nix new file mode 100644 index 0000000..b38f66f --- /dev/null +++ b/python_environment/default.nix @@ -0,0 +1,20 @@ +with import {}; + +stdenv.mkDerivation { + name = "myPythonEnv"; + buildInputs = with pkgs; [ + python38Full + python38Packages.virtualenv + ]; + src = null; + shellHook = '' + if [ ! -d .venv ]; then + python -m venv .venv + fi + source .venv/bin/activate + pip install --upgrade pip + if [ -s requirements.txt ]; then + pip install -r requirements.txt + fi + ''; +} diff --git a/python/requirements.txt b/python_environment/requirements.txt similarity index 100% rename from python/requirements.txt rename to python_environment/requirements.txt diff --git a/rust/shell.nix b/rust/shell.nix deleted file mode 100644 index c458cad..0000000 --- a/rust/shell.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ pkgs ? import {} }: -pkgs.mkShell { - NIX_ENFORCE_PURITY=0; - buildInputs = with pkgs; [ - cargo - rustc - rustfmt - ]; - shellHook = '' - function log_header { - echo -ne "==> \e[32m\e[1m$1\e[0m\n" - } - function log_subheader { - echo -ne "--> \e[33m\e[1m$1\e[0m\n" - } - function log { - echo -ne " $1\n" - } - - echo "" - log_header "rust_environment" - if [ -s Cargo.toml ]; then - log_subheader "found Cargo.toml, running 'cargo-build'" - cargo build - echo "" - fi - log_header "package versions" - log "$(rustc --version)" - log "$(cargo --version)" - ''; -}