diff --git a/README.md b/README.md deleted file mode 100644 index 8788088..0000000 --- a/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# 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 new file mode 100644 index 0000000..931ba60 --- /dev/null +++ b/README.org @@ -0,0 +1,34 @@ +* 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_environment/global_packages.txt b/node/global_packages.txt similarity index 100% rename from node_environment/global_packages.txt rename to node/global_packages.txt diff --git a/node/shell.nix b/node/shell.nix new file mode 100644 index 0000000..6ec98a3 --- /dev/null +++ b/node/shell.nix @@ -0,0 +1,38 @@ +{ 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 deleted file mode 100644 index 88581ef..0000000 --- a/node_environment/default.nix +++ /dev/null @@ -1,19 +0,0 @@ -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/python_environment/requirements.txt b/python/requirements.txt similarity index 100% rename from python_environment/requirements.txt rename to python/requirements.txt diff --git a/python/shell.nix b/python/shell.nix new file mode 100644 index 0000000..b957648 --- /dev/null +++ b/python/shell.nix @@ -0,0 +1,36 @@ +{ 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 deleted file mode 100644 index b38f66f..0000000 --- a/python_environment/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -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/rust/shell.nix b/rust/shell.nix new file mode 100644 index 0000000..c458cad --- /dev/null +++ b/rust/shell.nix @@ -0,0 +1,31 @@ +{ 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)" + ''; +}