From ace4288c9dd523a3bfb1abb4cf0c7a39a8ee90f5 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 7 Feb 2023 14:24:32 -0500 Subject: [PATCH 01/10] Modify flake.nix to make dev shells optional --- flake.nix | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index cf65e5a..e0f05d9 100644 --- a/flake.nix +++ b/flake.nix @@ -10,11 +10,19 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs) lib; + # Check if project has a shell.nix + hasShell = dir: (builtins.readDir ./${dir}) ? "shell.nix"; + + # Get all project directories currentDir = builtins.readDir ./.; - dirs = pkgs.lib.filterAttrs (_: v: v == "directory") currentDir; - in { - packages = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir} {}) dirs; - devShells = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir}/shell.nix {}) dirs; - }); + dirs = lib.filterAttrs (_: v: v == "directory") currentDir; + in + lib.concatMapAttrs (dir: _: { + packages.${dir} = pkgs.callPackage ./${dir} {}; + } // lib.optionalAttrs (hasShell dir) { + devShells.${dir} = pkgs.callPackage ./${dir}/shell.nix {}; + }) dirs + ); } From 4cd72752936b0046b9b4fd7ffc600fe33e53e9b3 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 7 Feb 2023 14:55:16 -0500 Subject: [PATCH 02/10] Fix bug in flake file --- flake.nix | 6 +++--- python/default.nix | 2 +- python/shell.nix | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index e0f05d9..e31f50f 100644 --- a/flake.nix +++ b/flake.nix @@ -17,12 +17,12 @@ # Get all project directories currentDir = builtins.readDir ./.; - dirs = lib.filterAttrs (_: v: v == "directory") currentDir; + dirs = builtins.attrNames (lib.filterAttrs (_: v: v == "directory") currentDir); in - lib.concatMapAttrs (dir: _: { + builtins.foldl' lib.recursiveUpdate {} (builtins.map (dir: { packages.${dir} = pkgs.callPackage ./${dir} {}; } // lib.optionalAttrs (hasShell dir) { devShells.${dir} = pkgs.callPackage ./${dir}/shell.nix {}; - }) dirs + }) dirs) ); } diff --git a/python/default.nix b/python/default.nix index 76a15d5..6c22630 100644 --- a/python/default.nix +++ b/python/default.nix @@ -1,4 +1,4 @@ -{ python3, ... }: +{ python3 }: python3.pkgs.buildPythonApplication { pname = "soe-python"; diff --git a/python/shell.nix b/python/shell.nix index 5feafb5..332eaff 100644 --- a/python/shell.nix +++ b/python/shell.nix @@ -1,2 +1,3 @@ -{ python3, ... }: +{ python3 }: + python3.buildEnv.env From da579f08af532a5e64eafe41f53f0ffb5dd7da35 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 8 Feb 2023 12:07:14 -0500 Subject: [PATCH 03/10] Implement in shell scripts --- bash/default.nix | 22 ++++++++++++++++++++++ bash/soe-bash | 19 +++++++++++++++++++ fish/default.nix | 22 ++++++++++++++++++++++ fish/soe-fish | 17 +++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 bash/default.nix create mode 100644 bash/soe-bash create mode 100644 fish/default.nix create mode 100644 fish/soe-fish diff --git a/bash/default.nix b/bash/default.nix new file mode 100644 index 0000000..fc38787 --- /dev/null +++ b/bash/default.nix @@ -0,0 +1,22 @@ +{ stdenv +, lib +, bash +, makeWrapper +}: + +stdenv.mkDerivation { + pname = "soe-bash"; + version = "1.0"; + + src = ./.; + + buildInputs = [ bash ]; + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + mkdir -p $out/bin + install -m555 soe-bash $out/bin + wrapProgram $out/bin/soe-bash \ + --prefix PATH : ${lib.makeBinPath [ bash ]} + ''; +} diff --git a/bash/soe-bash b/bash/soe-bash new file mode 100644 index 0000000..5f8c1c7 --- /dev/null +++ b/bash/soe-bash @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +read num +echo + +nums=() +for i in `seq 2 $num`; do + nums+=($i) +done + +while [ -n "$nums" ]; do + prime=${nums[0]} + echo $prime + nums_=() + for elem in "${nums[@]}"; do + [ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem) + done + nums=(${nums_[@]}) +done diff --git a/fish/default.nix b/fish/default.nix new file mode 100644 index 0000000..3b14eb7 --- /dev/null +++ b/fish/default.nix @@ -0,0 +1,22 @@ +{ stdenv +, lib +, fish +, makeWrapper +}: + +stdenv.mkDerivation { + pname = "soe-fish"; + version = "1.0"; + + src = ./.; + + buildInputs = [ fish ]; + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + mkdir -p $out/bin + install -m555 soe-fish $out/bin + wrapProgram $out/bin/soe-fish \ + --prefix PATH : ${lib.makeBinPath [ fish ]} + ''; +} diff --git a/fish/soe-fish b/fish/soe-fish new file mode 100644 index 0000000..899dc6f --- /dev/null +++ b/fish/soe-fish @@ -0,0 +1,17 @@ +#!/usr/bin/env fish + +read -P "" num +echo + +set nums (seq 2 $num) + +while test -n "$nums" + set prime $nums[1] + echo $prime + + set -e nums_ + for elem in $nums + test (math $elem % $prime) -eq 0 || set -a nums_ $elem + end + set nums $nums_ +end From 12733ba5c6c85bc2e08b3d1d08f3d7af153063a3 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 8 Feb 2023 12:56:01 -0500 Subject: [PATCH 04/10] Fix primes bound on shell scripts --- bash/soe-bash | 2 ++ fish/soe-fish | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bash/soe-bash b/bash/soe-bash index 5f8c1c7..b9ca298 100644 --- a/bash/soe-bash +++ b/bash/soe-bash @@ -8,6 +8,8 @@ for i in `seq 2 $num`; do nums+=($i) done +unset nums[-1] + while [ -n "$nums" ]; do prime=${nums[0]} echo $prime diff --git a/fish/soe-fish b/fish/soe-fish index 899dc6f..e73893e 100644 --- a/fish/soe-fish +++ b/fish/soe-fish @@ -3,7 +3,7 @@ read -P "" num echo -set nums (seq 2 $num) +set nums (seq 2 $num)[..-2] while test -n "$nums" set prime $nums[1] From 51a6ae01e16635de7e7fa3ba1b8b52b4ce339e39 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Fri, 9 Feb 2024 22:44:02 -0500 Subject: [PATCH 05/10] Use `pathExists` instead of `readDir` --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index e31f50f..da251c9 100644 --- a/flake.nix +++ b/flake.nix @@ -13,7 +13,7 @@ inherit (pkgs) lib; # Check if project has a shell.nix - hasShell = dir: (builtins.readDir ./${dir}) ? "shell.nix"; + hasShell = dir: builtins.pathExists ./${dir}/shell.nix; # Get all project directories currentDir = builtins.readDir ./.; From 81ca8af87072ca056e547c3d13378dd0ad5bc565 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Fri, 9 Feb 2024 22:44:24 -0500 Subject: [PATCH 06/10] Refactor derivation definitions --- bash/default.nix | 6 +----- bash/soe-bash | 0 fish/default.nix | 6 +----- fish/soe-fish | 0 python/bin/soe-python | 0 5 files changed, 2 insertions(+), 10 deletions(-) mode change 100644 => 100755 bash/soe-bash mode change 100644 => 100755 fish/soe-fish mode change 100644 => 100755 python/bin/soe-python diff --git a/bash/default.nix b/bash/default.nix index fc38787..b11cdff 100644 --- a/bash/default.nix +++ b/bash/default.nix @@ -1,7 +1,6 @@ { stdenv , lib , bash -, makeWrapper }: stdenv.mkDerivation { @@ -11,12 +10,9 @@ stdenv.mkDerivation { src = ./.; buildInputs = [ bash ]; - nativeBuildInputs = [ makeWrapper ]; installPhase = '' mkdir -p $out/bin - install -m555 soe-bash $out/bin - wrapProgram $out/bin/soe-bash \ - --prefix PATH : ${lib.makeBinPath [ bash ]} + cp soe-bash $out/bin ''; } diff --git a/bash/soe-bash b/bash/soe-bash old mode 100644 new mode 100755 diff --git a/fish/default.nix b/fish/default.nix index 3b14eb7..0d97b0c 100644 --- a/fish/default.nix +++ b/fish/default.nix @@ -1,7 +1,6 @@ { stdenv , lib , fish -, makeWrapper }: stdenv.mkDerivation { @@ -11,12 +10,9 @@ stdenv.mkDerivation { src = ./.; buildInputs = [ fish ]; - nativeBuildInputs = [ makeWrapper ]; installPhase = '' mkdir -p $out/bin - install -m555 soe-fish $out/bin - wrapProgram $out/bin/soe-fish \ - --prefix PATH : ${lib.makeBinPath [ fish ]} + cp soe-fish $out/bin ''; } diff --git a/fish/soe-fish b/fish/soe-fish old mode 100644 new mode 100755 diff --git a/python/bin/soe-python b/python/bin/soe-python old mode 100644 new mode 100755 From a8a26921b4784ae8945ef390ba2f771ddfa599a9 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sun, 28 Jul 2024 06:01:20 -0400 Subject: [PATCH 07/10] Restructure everything --- bash/nixpkgs/flake.lock | 43 +++++++++++++++ bash/nixpkgs/flake.nix | 17 ++++++ bash/{default.nix => nixpkgs/package.nix} | 5 +- bash/{soe-bash => nixpkgs/soe} | 1 + fish/nixpkgs/flake.lock | 43 +++++++++++++++ fish/nixpkgs/flake.nix | 17 ++++++ fish/{default.nix => nixpkgs/package.nix} | 5 +- fish/{soe-fish => nixpkgs/soe} | 1 + flake.lock | 37 +------------ flake.nix | 59 +++++++++++++-------- python/{ => nixpkgs}/.envrc | 0 python/{bin/soe-python => nixpkgs/bin/soe} | 0 python/nixpkgs/flake.lock | 43 +++++++++++++++ python/nixpkgs/flake.nix | 17 ++++++ python/{default.nix => nixpkgs/package.nix} | 2 +- python/{ => nixpkgs}/setup.py | 2 +- python/{ => nixpkgs}/shell.nix | 0 python/{ => nixpkgs}/soe/__init__.py | 0 python/{ => nixpkgs}/soe/main.py | 2 +- 19 files changed, 227 insertions(+), 67 deletions(-) create mode 100644 bash/nixpkgs/flake.lock create mode 100644 bash/nixpkgs/flake.nix rename bash/{default.nix => nixpkgs/package.nix} (74%) rename bash/{soe-bash => nixpkgs/soe} (92%) create mode 100644 fish/nixpkgs/flake.lock create mode 100644 fish/nixpkgs/flake.nix rename fish/{default.nix => nixpkgs/package.nix} (74%) rename fish/{soe-fish => nixpkgs/soe} (91%) rename python/{ => nixpkgs}/.envrc (100%) rename python/{bin/soe-python => nixpkgs/bin/soe} (100%) create mode 100644 python/nixpkgs/flake.lock create mode 100644 python/nixpkgs/flake.nix rename python/{default.nix => nixpkgs/package.nix} (81%) rename python/{ => nixpkgs}/setup.py (71%) rename python/{ => nixpkgs}/shell.nix (100%) rename python/{ => nixpkgs}/soe/__init__.py (100%) rename python/{ => nixpkgs}/soe/main.py (90%) diff --git a/bash/nixpkgs/flake.lock b/bash/nixpkgs/flake.lock new file mode 100644 index 0000000..45fde49 --- /dev/null +++ b/bash/nixpkgs/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1722073938, + "narHash": "sha256-OpX0StkL8vpXyWOGUD6G+MA26wAXK6SpT94kLJXo6B4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e36e9f57337d0ff0cf77aceb58af4c805472bfae", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/bash/nixpkgs/flake.nix b/bash/nixpkgs/flake.nix new file mode 100644 index 0000000..9505679 --- /dev/null +++ b/bash/nixpkgs/flake.nix @@ -0,0 +1,17 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = { self, nixpkgs, systems, ... }: + let eachSystem = nixpkgs.lib.genAttrs (import systems); + in { + packages = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + soe = pkgs.callPackage ./package.nix {}; + default = self.packages.${system}.soe; + }); + }; +} diff --git a/bash/default.nix b/bash/nixpkgs/package.nix similarity index 74% rename from bash/default.nix rename to bash/nixpkgs/package.nix index b11cdff..20e14bc 100644 --- a/bash/default.nix +++ b/bash/nixpkgs/package.nix @@ -1,10 +1,9 @@ { stdenv -, lib , bash }: stdenv.mkDerivation { - pname = "soe-bash"; + pname = "soe"; version = "1.0"; src = ./.; @@ -13,6 +12,6 @@ stdenv.mkDerivation { installPhase = '' mkdir -p $out/bin - cp soe-bash $out/bin + cp soe $out/bin ''; } diff --git a/bash/soe-bash b/bash/nixpkgs/soe similarity index 92% rename from bash/soe-bash rename to bash/nixpkgs/soe index b9ca298..3aefb63 100755 --- a/bash/soe-bash +++ b/bash/nixpkgs/soe @@ -1,5 +1,6 @@ #!/usr/bin/env bash +echo -n "Primes up to: " read num echo diff --git a/fish/nixpkgs/flake.lock b/fish/nixpkgs/flake.lock new file mode 100644 index 0000000..c44d5a5 --- /dev/null +++ b/fish/nixpkgs/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1722141560, + "narHash": "sha256-Ul3rIdesWaiW56PS/Ak3UlJdkwBrD4UcagCmXZR9Z7Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "038fb464fcfa79b4f08131b07f2d8c9a6bcc4160", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/fish/nixpkgs/flake.nix b/fish/nixpkgs/flake.nix new file mode 100644 index 0000000..9505679 --- /dev/null +++ b/fish/nixpkgs/flake.nix @@ -0,0 +1,17 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = { self, nixpkgs, systems, ... }: + let eachSystem = nixpkgs.lib.genAttrs (import systems); + in { + packages = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + soe = pkgs.callPackage ./package.nix {}; + default = self.packages.${system}.soe; + }); + }; +} diff --git a/fish/default.nix b/fish/nixpkgs/package.nix similarity index 74% rename from fish/default.nix rename to fish/nixpkgs/package.nix index 0d97b0c..aaeb6d2 100644 --- a/fish/default.nix +++ b/fish/nixpkgs/package.nix @@ -1,10 +1,9 @@ { stdenv -, lib , fish }: stdenv.mkDerivation { - pname = "soe-fish"; + pname = "soe"; version = "1.0"; src = ./.; @@ -13,6 +12,6 @@ stdenv.mkDerivation { installPhase = '' mkdir -p $out/bin - cp soe-fish $out/bin + cp soe $out/bin ''; } diff --git a/fish/soe-fish b/fish/nixpkgs/soe similarity index 91% rename from fish/soe-fish rename to fish/nixpkgs/soe index e73893e..23d46ae 100755 --- a/fish/soe-fish +++ b/fish/nixpkgs/soe @@ -1,5 +1,6 @@ #!/usr/bin/env fish +echo -n "Primes up to: " read -P "" num echo diff --git a/flake.lock b/flake.lock index 785f948..5999137 100644 --- a/flake.lock +++ b/flake.lock @@ -1,41 +1,6 @@ { "nodes": { - "flake-utils": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1675132057, - "narHash": "sha256-lq7VYB8J2wn35CeByP9760tR6mwQtztPze+J8O4fHdU=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5b374db81f4a26de2cef6dae71b4478b362866a4", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - } - } + "root": {} }, "root": "root", "version": 7 diff --git a/flake.nix b/flake.nix index da251c9..6164411 100644 --- a/flake.nix +++ b/flake.nix @@ -1,28 +1,43 @@ { - description = "The Sieve of Eratosthenes implemented in many different languages"; + description = "Templates of the Sieve of Eratosthenes implemented in various languages"; - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs"; - flake-utils.url = "github:numtide/flake-utils"; - }; + outputs = { self, ... }: + let + # Get all project directories + subdirs = dir: + let sub = builtins.readDir dir; + in builtins.filter + (d: sub.${d} == "directory") + (builtins.attrNames sub); - outputs = { self, nixpkgs, flake-utils, ... }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - inherit (pkgs) lib; + vowelStart = str: builtins.elem (builtins.substring 0 1 str) [ "a" "e" "i" "o" "u" ]; - # Check if project has a shell.nix - hasShell = dir: builtins.pathExists ./${dir}/shell.nix; + concatMapAttrs = func: attr: + builtins.foldl' (x: y: x // y) {} + (builtins.map func attr); - # Get all project directories - currentDir = builtins.readDir ./.; - dirs = builtins.attrNames (lib.filterAttrs (_: v: v == "directory") currentDir); - in - builtins.foldl' lib.recursiveUpdate {} (builtins.map (dir: { - packages.${dir} = pkgs.callPackage ./${dir} {}; - } // lib.optionalAttrs (hasShell dir) { - devShells.${dir} = pkgs.callPackage ./${dir}/shell.nix {}; - }) dirs) - ); + templateDirs = + builtins.concatMap (lang: + builtins.map + (pkg: { inherit lang pkg; }) + (subdirs ./${lang})) + (subdirs ./.); + in { + templates = concatMapAttrs ({ lang, pkg }: { + "${lang}-${pkg}" = { + description = "Packaging a${if vowelStart lang + then "n" + else ""} ${lang} executable using ${pkg}"; + path = builtins.filterSource + (path: type: builtins.baseNameOf path != "flake.lock") + ./${lang}/${pkg}; + }; + }) templateDirs // concatMapAttrs (lang: { + "${lang}" = self.templates."${lang}-nixpkgs" // { + description = "Packaging a${if vowelStart lang + then "n" + else ""} ${lang} executable"; + }; + }) (subdirs ./.); + }; } diff --git a/python/.envrc b/python/nixpkgs/.envrc similarity index 100% rename from python/.envrc rename to python/nixpkgs/.envrc diff --git a/python/bin/soe-python b/python/nixpkgs/bin/soe similarity index 100% rename from python/bin/soe-python rename to python/nixpkgs/bin/soe diff --git a/python/nixpkgs/flake.lock b/python/nixpkgs/flake.lock new file mode 100644 index 0000000..c44d5a5 --- /dev/null +++ b/python/nixpkgs/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1722141560, + "narHash": "sha256-Ul3rIdesWaiW56PS/Ak3UlJdkwBrD4UcagCmXZR9Z7Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "038fb464fcfa79b4f08131b07f2d8c9a6bcc4160", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/python/nixpkgs/flake.nix b/python/nixpkgs/flake.nix new file mode 100644 index 0000000..9505679 --- /dev/null +++ b/python/nixpkgs/flake.nix @@ -0,0 +1,17 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = { self, nixpkgs, systems, ... }: + let eachSystem = nixpkgs.lib.genAttrs (import systems); + in { + packages = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + soe = pkgs.callPackage ./package.nix {}; + default = self.packages.${system}.soe; + }); + }; +} diff --git a/python/default.nix b/python/nixpkgs/package.nix similarity index 81% rename from python/default.nix rename to python/nixpkgs/package.nix index 6c22630..961c388 100644 --- a/python/default.nix +++ b/python/nixpkgs/package.nix @@ -1,7 +1,7 @@ { python3 }: python3.pkgs.buildPythonApplication { - pname = "soe-python"; + pname = "soe"; version = "1.0"; src = ./.; diff --git a/python/setup.py b/python/nixpkgs/setup.py similarity index 71% rename from python/setup.py rename to python/nixpkgs/setup.py index 0e31be3..158092b 100644 --- a/python/setup.py +++ b/python/nixpkgs/setup.py @@ -3,5 +3,5 @@ from setuptools import setup setup( name="soe", version="1.0.0", - scripts=["bin/soe-python"] + scripts=["bin/soe"] ) diff --git a/python/shell.nix b/python/nixpkgs/shell.nix similarity index 100% rename from python/shell.nix rename to python/nixpkgs/shell.nix diff --git a/python/soe/__init__.py b/python/nixpkgs/soe/__init__.py similarity index 100% rename from python/soe/__init__.py rename to python/nixpkgs/soe/__init__.py diff --git a/python/soe/main.py b/python/nixpkgs/soe/main.py similarity index 90% rename from python/soe/main.py rename to python/nixpkgs/soe/main.py index 23f1cf2..1c6c4a8 100644 --- a/python/soe/main.py +++ b/python/nixpkgs/soe/main.py @@ -12,7 +12,7 @@ def main(): another = True while another: try: - num = int(input()) + num = int(input("Primes up to: ")) another = False except ValueError: pass From ce6920a1d43b555f0b1719ee19f5feb2d2ff1a38 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sun, 28 Jul 2024 06:25:15 -0400 Subject: [PATCH 08/10] remove(python-nixpkgs): remove input check for consistency --- python/nixpkgs/soe/main.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/python/nixpkgs/soe/main.py b/python/nixpkgs/soe/main.py index 1c6c4a8..ba258ad 100644 --- a/python/nixpkgs/soe/main.py +++ b/python/nixpkgs/soe/main.py @@ -8,15 +8,7 @@ def sieve_of_eratosthenes(n): yield prime def main(): - num = 0 - another = True - while another: - try: - num = int(input("Primes up to: ")) - another = False - except ValueError: - pass - + num = int(input("Primes up to: ")) print() for i in sieve_of_eratosthenes(num): print(i) From 0e55a43863af909aa238ccb7728466d784e6607e Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sun, 28 Jul 2024 06:35:26 -0400 Subject: [PATCH 09/10] fix(fish): fix improper prompt --- fish/nixpkgs/soe | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fish/nixpkgs/soe b/fish/nixpkgs/soe index 23d46ae..ae66188 100755 --- a/fish/nixpkgs/soe +++ b/fish/nixpkgs/soe @@ -1,7 +1,6 @@ #!/usr/bin/env fish -echo -n "Primes up to: " -read -P "" num +read -P "Primes up to: " num echo set nums (seq 2 $num)[..-2] From a3b53b180cc855955e19b8f5cc8b578473ce9a55 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sun, 28 Jul 2024 06:43:01 -0400 Subject: [PATCH 10/10] style: modify the output of scripts Instead of separating output primes by newline, the scripts now separate by spaces. --- bash/nixpkgs/soe | 4 +++- fish/nixpkgs/soe | 4 +++- python/nixpkgs/soe/main.py | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bash/nixpkgs/soe b/bash/nixpkgs/soe index 3aefb63..e861d8f 100755 --- a/bash/nixpkgs/soe +++ b/bash/nixpkgs/soe @@ -13,10 +13,12 @@ unset nums[-1] while [ -n "$nums" ]; do prime=${nums[0]} - echo $prime + echo -n "$prime " nums_=() for elem in "${nums[@]}"; do [ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem) done nums=(${nums_[@]}) done + +echo diff --git a/fish/nixpkgs/soe b/fish/nixpkgs/soe index ae66188..5cc2b5a 100755 --- a/fish/nixpkgs/soe +++ b/fish/nixpkgs/soe @@ -7,7 +7,7 @@ set nums (seq 2 $num)[..-2] while test -n "$nums" set prime $nums[1] - echo $prime + echo -n "$prime " set -e nums_ for elem in $nums @@ -15,3 +15,5 @@ while test -n "$nums" end set nums $nums_ end + +echo diff --git a/python/nixpkgs/soe/main.py b/python/nixpkgs/soe/main.py index ba258ad..f6a1425 100644 --- a/python/nixpkgs/soe/main.py +++ b/python/nixpkgs/soe/main.py @@ -1,5 +1,4 @@ - def sieve_of_eratosthenes(n): nums = list(range(2, n)) while nums: @@ -11,7 +10,8 @@ def main(): num = int(input("Primes up to: ")) print() for i in sieve_of_eratosthenes(num): - print(i) + print(i, end=" ") + print() if __name__ == "__main__":