From b2e0bda97e9b730a11c41d4ec83de5fca3c642be Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Sat, 6 Mar 2021 00:39:18 +0100 Subject: [PATCH 01/10] change Python version to 3 --- python_environment/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python_environment/default.nix b/python_environment/default.nix index b38f66f..a475d01 100644 --- a/python_environment/default.nix +++ b/python_environment/default.nix @@ -3,8 +3,8 @@ with import {}; stdenv.mkDerivation { name = "myPythonEnv"; buildInputs = with pkgs; [ - python38Full - python38Packages.virtualenv + python3Full + python3Packages.virtualenv ]; src = null; shellHook = '' From e26c68f285ddaeafacd7eb0b78acd5693ab8de83 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Thu, 11 Mar 2021 09:37:54 +0100 Subject: [PATCH 02/10] move default.nix to shell.nix --- node_environment/{default.nix => shell.nix} | 8 +++----- python_environment/{default.nix => shell.nix} | 10 ++++------ 2 files changed, 7 insertions(+), 11 deletions(-) rename node_environment/{default.nix => shell.nix} (77%) rename python_environment/{default.nix => shell.nix} (74%) diff --git a/node_environment/default.nix b/node_environment/shell.nix similarity index 77% rename from node_environment/default.nix rename to node_environment/shell.nix index 88581ef..8979379 100644 --- a/node_environment/default.nix +++ b/node_environment/shell.nix @@ -1,11 +1,9 @@ -with import {}; - -stdenv.mkDerivation { - name = "myNodeEnv"; +{ pkgs ? import {} }: +pkgs.mkShell { + name = "node-environment"; buildInputs = with pkgs; [ nodejs ]; - src = null; shellHook = '' mkdir -p .npm if [ -s global_packages.txt ]; then diff --git a/python_environment/default.nix b/python_environment/shell.nix similarity index 74% rename from python_environment/default.nix rename to python_environment/shell.nix index a475d01..378fe0f 100644 --- a/python_environment/default.nix +++ b/python_environment/shell.nix @@ -1,12 +1,10 @@ -with import {}; - -stdenv.mkDerivation { - name = "myPythonEnv"; +{ pkgs ? import {} }: +pkgs.mkShell { + name = "python-environment"; buildInputs = with pkgs; [ - python3Full + python3 python3Packages.virtualenv ]; - src = null; shellHook = '' if [ ! -d .venv ]; then python -m venv .venv From eb17946c217b3cf942b550818434f6daf1276e5e Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Thu, 11 Mar 2021 10:30:50 +0100 Subject: [PATCH 03/10] update README --- README.md | 5 ----- README.org | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) delete mode 100644 README.md create mode 100644 README.org 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..39eebe3 --- /dev/null +++ b/README.org @@ -0,0 +1,23 @@ +* nix_virtualenvs + + This is a set of various virtual 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_environment + + 1. Create a directory =.npm= + 2. If the file =global_packages.txt= is present, install the packages via *npm* globally in the =.npm= directory + 3. Run ~npm install~ if a file =package.json= is present + 4. Add the =.npm= directory to the ~$PATH~ variable + +** python_environment + + 1. Create a new python virtualenv in the folder =.venv= + 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 From ee563bb987b8234a4d71b76f9b21918bb6840f86 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Thu, 11 Mar 2021 13:03:19 +0100 Subject: [PATCH 04/10] add rust_environment --- rust_environment/shell.nix | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 rust_environment/shell.nix diff --git a/rust_environment/shell.nix b/rust_environment/shell.nix new file mode 100644 index 0000000..6255daf --- /dev/null +++ b/rust_environment/shell.nix @@ -0,0 +1,30 @@ +{ pkgs ? import {} }: +pkgs.mkShell { + NIX_ENFORCE_PURITY=0; + buildInputs = with pkgs; [ + cargo + rustc + ]; + shellHook = '' + function log_header { + echo -ne "==> \e[32m\e[1m$1\e[0m\n\n" + } + function log_subheader { + echo -ne "--> \e[33m\e[1m$1\e[0m\n\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)" + ''; +} From 49973291c4f2cd9b97ac90c3bbd0cb32a4ea9324 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Thu, 11 Mar 2021 13:03:41 +0100 Subject: [PATCH 05/10] add logging --- README.org | 15 ++++++++++----- node_environment/shell.nix | 26 ++++++++++++++++++++++++-- python_environment/shell.nix | 19 +++++++++++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/README.org b/README.org index 39eebe3..47d8e80 100644 --- a/README.org +++ b/README.org @@ -10,14 +10,19 @@ ** node_environment - 1. Create a directory =.npm= - 2. If the file =global_packages.txt= is present, install the packages via *npm* globally in the =.npm= directory - 3. Run ~npm install~ if a file =package.json= is present - 4. Add the =.npm= directory to the ~$PATH~ variable + 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_environment - 1. Create a new python virtualenv in the folder =.venv= + 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_environment + + 1. Run ~cargo build~ if =Cargo.toml= is present diff --git a/node_environment/shell.nix b/node_environment/shell.nix index 8979379..ed68d7c 100644 --- a/node_environment/shell.nix +++ b/node_environment/shell.nix @@ -5,13 +5,35 @@ pkgs.mkShell { nodejs ]; shellHook = '' - mkdir -p .npm + function log_header { + echo -ne "==> \e[32m\e[1m$1\e[0m\n\n" + } + function log_subheader { + echo -ne "--> \e[33m\e[1m$1\e[0m\n\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 - export PATH=$PWD/.npm/bin:$PATH + log_header "package versions" + log "node $(node --version)" + log "npm $(npm --version)" ''; } diff --git a/python_environment/shell.nix b/python_environment/shell.nix index 378fe0f..19883f6 100644 --- a/python_environment/shell.nix +++ b/python_environment/shell.nix @@ -6,13 +6,32 @@ pkgs.mkShell { python3Packages.virtualenv ]; shellHook = '' + function log_header { + echo -ne "==> \e[32m\e[1m$1\e[0m\n\n" + } + function log_subheader { + echo -ne "--> \e[33m\e[1m$1\e[0m\n\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)" ''; } From 5c0bb8fdde0b5f21f76726e39a789d38893ffedc Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Thu, 11 Mar 2021 15:02:57 +0100 Subject: [PATCH 06/10] add rustfmt --- rust_environment/shell.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/rust_environment/shell.nix b/rust_environment/shell.nix index 6255daf..cd7a9b2 100644 --- a/rust_environment/shell.nix +++ b/rust_environment/shell.nix @@ -4,6 +4,7 @@ pkgs.mkShell { buildInputs = with pkgs; [ cargo rustc + rustfmt ]; shellHook = '' function log_header { From 0cdc75a4f08ba911a778ce923068b0116ea3257c Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Thu, 11 Mar 2021 18:23:14 +0100 Subject: [PATCH 07/10] rename folders --- {node_environment => node}/global_packages.txt | 0 {node_environment => node}/shell.nix | 0 {python_environment => python}/requirements.txt | 0 {python_environment => python}/shell.nix | 0 {rust_environment => rust}/shell.nix | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {node_environment => node}/global_packages.txt (100%) rename {node_environment => node}/shell.nix (100%) rename {python_environment => python}/requirements.txt (100%) rename {python_environment => python}/shell.nix (100%) rename {rust_environment => rust}/shell.nix (100%) 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_environment/shell.nix b/node/shell.nix similarity index 100% rename from node_environment/shell.nix rename to node/shell.nix 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_environment/shell.nix b/python/shell.nix similarity index 100% rename from python_environment/shell.nix rename to python/shell.nix diff --git a/rust_environment/shell.nix b/rust/shell.nix similarity index 100% rename from rust_environment/shell.nix rename to rust/shell.nix From c1e517f5cf69124d5fd753cf656045303febcccb Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Thu, 11 Mar 2021 18:25:20 +0100 Subject: [PATCH 08/10] update README --- README.org | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.org b/README.org index 47d8e80..931ba60 100644 --- a/README.org +++ b/README.org @@ -1,6 +1,6 @@ -* nix_virtualenvs +* nix_environments - This is a set of various virtual environments which can be used with the *Nix* package manager. + 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. @@ -8,7 +8,9 @@ If you need more Nix packages in your environent, enhance the list ~buildInputs~ in the file =shell.nix=. -** node_environment +** 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 @@ -16,13 +18,17 @@ 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_environment +** 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_environment +** rust + + This environment does the following: 1. Run ~cargo build~ if =Cargo.toml= is present From 231f1421af393a1484fa10efbd2bea6deecbd0b1 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Sun, 14 Mar 2021 22:07:17 +0100 Subject: [PATCH 09/10] remove names --- node/shell.nix | 1 - python/shell.nix | 1 - 2 files changed, 2 deletions(-) diff --git a/node/shell.nix b/node/shell.nix index ed68d7c..85d19a1 100644 --- a/node/shell.nix +++ b/node/shell.nix @@ -1,6 +1,5 @@ { pkgs ? import {} }: pkgs.mkShell { - name = "node-environment"; buildInputs = with pkgs; [ nodejs ]; diff --git a/python/shell.nix b/python/shell.nix index 19883f6..d34f295 100644 --- a/python/shell.nix +++ b/python/shell.nix @@ -1,6 +1,5 @@ { pkgs ? import {} }: pkgs.mkShell { - name = "python-environment"; buildInputs = with pkgs; [ python3 python3Packages.virtualenv From ec47f4e1102fa3eaef38d1f9411e8eb7bb731015 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Sat, 10 Apr 2021 10:02:01 +0200 Subject: [PATCH 10/10] remove newlines after headings --- node/shell.nix | 4 ++-- python/shell.nix | 4 ++-- rust/shell.nix | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/node/shell.nix b/node/shell.nix index 85d19a1..6ec98a3 100644 --- a/node/shell.nix +++ b/node/shell.nix @@ -5,10 +5,10 @@ pkgs.mkShell { ]; shellHook = '' function log_header { - echo -ne "==> \e[32m\e[1m$1\e[0m\n\n" + echo -ne "==> \e[32m\e[1m$1\e[0m\n" } function log_subheader { - echo -ne "--> \e[33m\e[1m$1\e[0m\n\n" + echo -ne "--> \e[33m\e[1m$1\e[0m\n" } function log { echo -ne " $1\n" diff --git a/python/shell.nix b/python/shell.nix index d34f295..b957648 100644 --- a/python/shell.nix +++ b/python/shell.nix @@ -6,10 +6,10 @@ pkgs.mkShell { ]; shellHook = '' function log_header { - echo -ne "==> \e[32m\e[1m$1\e[0m\n\n" + echo -ne "==> \e[32m\e[1m$1\e[0m\n" } function log_subheader { - echo -ne "--> \e[33m\e[1m$1\e[0m\n\n" + echo -ne "--> \e[33m\e[1m$1\e[0m\n" } function log { echo -ne " $1\n" diff --git a/rust/shell.nix b/rust/shell.nix index cd7a9b2..c458cad 100644 --- a/rust/shell.nix +++ b/rust/shell.nix @@ -8,10 +8,10 @@ pkgs.mkShell { ]; shellHook = '' function log_header { - echo -ne "==> \e[32m\e[1m$1\e[0m\n\n" + echo -ne "==> \e[32m\e[1m$1\e[0m\n" } function log_subheader { - echo -ne "--> \e[33m\e[1m$1\e[0m\n\n" + echo -ne "--> \e[33m\e[1m$1\e[0m\n" } function log { echo -ne " $1\n"