From 89cfefaff7f7b84d3e9a40cd27377e1b0b5bb389 Mon Sep 17 00:00:00 2001 From: Deepak Mallubhotla Date: Sat, 4 Jun 2022 13:12:50 -0500 Subject: [PATCH 1/6] nix: initial nix flake --- flake.nix | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 flake.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..633249a --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + description = "Application packaged using poetry2nix"; + + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs"; + inputs.poetry2nix.url = "github:nix-community/poetry2nix"; + + outputs = { self, nixpkgs, flake-utils, poetry2nix }: + { + # Nixpkgs overlay providing the application + overlay = nixpkgs.lib.composeManyExtensions [ + poetry2nix.overlay + (final: prev: { + # The application + pyewjn = prev.poetry2nix.mkPoetryApplication { + overrides = [ + prev.poetry2nix.defaultPoetryOverrides + ]; + projectDir = ./.; + }; + pyewjnEnv = prev.poetry2nix.mkPoetryEnv { + overrides = [ + prev.poetry2nix.defaultPoetryOverrides + ]; + projectDir = ./.; + }; + }) + ]; + } // (flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }; + in + { + apps = { + pyewjn = pkgs.pyewjn; + }; + + defaultApp = pkgs.pyewjn; + devShell = pkgs.mkShell { + buildInputs = [ + pkgs.poetry + pkgs.pyewjnEnv + pkgs.pyewjn + ]; + }; + + })); +} -- 2.47.2 From 908cd65129d5bd21e1b3e7175f84b7cc100895c6 Mon Sep 17 00:00:00 2001 From: Deepak Mallubhotla Date: Sat, 4 Jun 2022 13:13:36 -0500 Subject: [PATCH 2/6] nix: adds lock file --- flake.lock | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 flake.lock diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..780aeb1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,92 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1654366296, + "narHash": "sha256-7XkmwoaM9cI2Qk0KJmSM15oW7KYpDWCFeUWOoDa1OKI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f1a49956529e0fe9a7fe7efb2f60a80f11c9f81f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1654366296, + "narHash": "sha256-7XkmwoaM9cI2Qk0KJmSM15oW7KYpDWCFeUWOoDa1OKI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f1a49956529e0fe9a7fe7efb2f60a80f11c9f81f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "poetry2nix": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1654364689, + "narHash": "sha256-vKXN+lYyaPR8SX3OUwqdEY0ccZ5PiVugmPKQtbH8QS0=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "5ccffe18c3b1ff74cc9a7f69fa614e96c1f768a3", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "poetry2nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "poetry2nix": "poetry2nix" + } + } + }, + "root": "root", + "version": 7 +} -- 2.47.2 From af15cc1d4ca4a6dddfacba39ea729bd7b22dd660 Mon Sep 17 00:00:00 2001 From: Deepak Mallubhotla Date: Sat, 4 Jun 2022 15:21:15 -0500 Subject: [PATCH 3/6] nix: pin versions? --- flake.lock | 21 ++++++++++++--------- flake.nix | 6 +++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/flake.lock b/flake.lock index 780aeb1..e1ab60e 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,17 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1653893745, - "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "lastModified": 1648297722, + "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", "type": "github" }, "original": { "owner": "numtide", "repo": "flake-utils", + "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", "type": "github" } }, @@ -32,16 +33,17 @@ }, "nixpkgs": { "locked": { - "lastModified": 1654366296, - "narHash": "sha256-7XkmwoaM9cI2Qk0KJmSM15oW7KYpDWCFeUWOoDa1OKI=", + "lastModified": 1648854265, + "narHash": "sha256-e/RlfodBOMr2SH9diDPYMraTWvhOWSSsXDQikHFdUvM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f1a49956529e0fe9a7fe7efb2f60a80f11c9f81f", + "rev": "e194871435cad8ffb1d64b64fb7df3b2b8a10088", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", + "rev": "e194871435cad8ffb1d64b64fb7df3b2b8a10088", "type": "github" } }, @@ -66,16 +68,17 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1654364689, - "narHash": "sha256-vKXN+lYyaPR8SX3OUwqdEY0ccZ5PiVugmPKQtbH8QS0=", + "lastModified": 1648808959, + "narHash": "sha256-1KZuZ0yJ4j1cWvOvnyyy36xCTcG9+sNe2FDHOHnErQM=", "owner": "nix-community", "repo": "poetry2nix", - "rev": "5ccffe18c3b1ff74cc9a7f69fa614e96c1f768a3", + "rev": "99c79568352799af09edaeefc858d337e6d9c56f", "type": "github" }, "original": { "owner": "nix-community", "repo": "poetry2nix", + "rev": "99c79568352799af09edaeefc858d337e6d9c56f", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 633249a..58bf9ae 100644 --- a/flake.nix +++ b/flake.nix @@ -1,9 +1,9 @@ { description = "Application packaged using poetry2nix"; - inputs.flake-utils.url = "github:numtide/flake-utils"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs"; - inputs.poetry2nix.url = "github:nix-community/poetry2nix"; + inputs.flake-utils.url = "github:numtide/flake-utils?rev=0f8662f1319ad6abf89b3380dd2722369fc51ade"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs?rev=e194871435cad8ffb1d64b64fb7df3b2b8a10088"; + inputs.poetry2nix.url = "github:nix-community/poetry2nix?rev=99c79568352799af09edaeefc858d337e6d9c56f"; outputs = { self, nixpkgs, flake-utils, poetry2nix }: { -- 2.47.2 From aae86062da4bf2fc7ade3070513cc07a4f73b194 Mon Sep 17 00:00:00 2001 From: Deepak Mallubhotla Date: Tue, 7 Jun 2022 17:22:19 -0500 Subject: [PATCH 4/6] nix: adds nix custom flag for do.sh --- flake.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flake.nix b/flake.nix index 58bf9ae..97439a5 100644 --- a/flake.nix +++ b/flake.nix @@ -45,6 +45,9 @@ pkgs.pyewjnEnv pkgs.pyewjn ]; + shellHook = '' + export DO_NIX_CUSTOM=1 + ''; }; })); -- 2.47.2 From 34601fafbd41066a35feb8574359ba43fcaa227f Mon Sep 17 00:00:00 2001 From: Deepak Mallubhotla Date: Tue, 7 Jun 2022 17:30:26 -0500 Subject: [PATCH 5/6] nix: makes do.sh play better with nix --- do.sh | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/do.sh b/do.sh index 1ab44f1..aa4a83b 100644 --- a/do.sh +++ b/do.sh @@ -4,30 +4,56 @@ set -Eeuo pipefail # -e "Automatic exit from bash shell script on error" -u "Treat unset variables and parameters as errors" +checknix() { + if [[ "${DO_NIX_CUSTOM:=0}" -eq 1 ]]; then + echo "In an interactive nix env." + else + echo "Using poetry as runner, no nix detected." + fi +} + build() { echo "I am ${FUNCNAME[0]}ing" poetry build } fmt() { - poetry run black . + if [[ "${DO_NIX_CUSTOM:=0}" -eq 1 ]]; then + black . + else + poetry run black . + fi find . -type f -name "*.py" -exec sed -i -e 's/ /\t/g' {} \; } test() { echo "I am ${FUNCNAME[0]}ing" - poetry run flake8 pyewjn tests - poetry run mypy pyewjn - poetry run pytest --benchmark-disable + if [[ "${DO_NIX_CUSTOM:=0}" -eq 1 ]]; then + flake8 pyewjn tests + mypy pyewjn + pytest --benchmark-disable + else + poetry run flake8 pyewjn tests + poetry run mypy pyewjn + poetry run pytest --benchmark-disable + fi } benchmark() { echo "I am ${FUNCNAME[0]}ing" - poetry run pytest --benchmark-only + if [[ "${DO_NIX_CUSTOM:=0}" -eq 1 ]]; then + pytest --benchmark-only + else + poetry run pytest --benchmark-only + fi } htmlcov() { - poetry run pytest --cov-report=html + if [[ "${DO_NIX_CUSTOM:=0}" -eq 1 ]]; then + pytest --cov-report=html + else + poetry run pytest --cov-report=html + fi } release() { -- 2.47.2 From b54a7275d957be8d26e2bcde452c1fda8e9a5fc0 Mon Sep 17 00:00:00 2001 From: Deepak Mallubhotla Date: Tue, 7 Jun 2022 18:23:32 -0500 Subject: [PATCH 6/6] nix: adds npx to env --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 97439a5..9851327 100644 --- a/flake.nix +++ b/flake.nix @@ -48,6 +48,7 @@ shellHook = '' export DO_NIX_CUSTOM=1 ''; + packages = [ pkgs.nodejs-16_x ]; }; })); -- 2.47.2