diff --git a/bash/nixpkgs/flake.lock b/bash/nixpkgs/flake.lock deleted file mode 100644 index 45fde49..0000000 --- a/bash/nixpkgs/flake.lock +++ /dev/null @@ -1,43 +0,0 @@ -{ - "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 deleted file mode 100644 index 9505679..0000000 --- a/bash/nixpkgs/flake.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ - 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/nixpkgs/package.nix b/bash/nixpkgs/package.nix deleted file mode 100644 index 20e14bc..0000000 --- a/bash/nixpkgs/package.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ stdenv -, bash -}: - -stdenv.mkDerivation { - pname = "soe"; - version = "1.0"; - - src = ./.; - - buildInputs = [ bash ]; - - installPhase = '' - mkdir -p $out/bin - cp soe $out/bin - ''; -} diff --git a/bash/nixpkgs/soe b/bash/nixpkgs/soe deleted file mode 100755 index e861d8f..0000000 --- a/bash/nixpkgs/soe +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -echo -n "Primes up to: " -read num -echo - -nums=() -for i in `seq 2 $num`; do - nums+=($i) -done - -unset nums[-1] - -while [ -n "$nums" ]; do - prime=${nums[0]} - 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/flake.lock b/fish/nixpkgs/flake.lock deleted file mode 100644 index c44d5a5..0000000 --- a/fish/nixpkgs/flake.lock +++ /dev/null @@ -1,43 +0,0 @@ -{ - "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 deleted file mode 100644 index 9505679..0000000 --- a/fish/nixpkgs/flake.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ - 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/nixpkgs/package.nix b/fish/nixpkgs/package.nix deleted file mode 100644 index aaeb6d2..0000000 --- a/fish/nixpkgs/package.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ stdenv -, fish -}: - -stdenv.mkDerivation { - pname = "soe"; - version = "1.0"; - - src = ./.; - - buildInputs = [ fish ]; - - installPhase = '' - mkdir -p $out/bin - cp soe $out/bin - ''; -} diff --git a/fish/nixpkgs/soe b/fish/nixpkgs/soe deleted file mode 100755 index 5cc2b5a..0000000 --- a/fish/nixpkgs/soe +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env fish - -read -P "Primes up to: " num -echo - -set nums (seq 2 $num)[..-2] - -while test -n "$nums" - set prime $nums[1] - echo -n "$prime " - - set -e nums_ - for elem in $nums - test (math $elem % $prime) -eq 0 || set -a nums_ $elem - end - set nums $nums_ -end - -echo diff --git a/flake.lock b/flake.lock index 5999137..785f948 100644 --- a/flake.lock +++ b/flake.lock @@ -1,6 +1,41 @@ { "nodes": { - "root": {} + "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", "version": 7 diff --git a/flake.nix b/flake.nix index 6164411..cf65e5a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,43 +1,20 @@ { - description = "Templates of the Sieve of Eratosthenes implemented in various languages"; + description = "The Sieve of Eratosthenes implemented in many different languages"; - outputs = { self, ... }: - let - # Get all project directories - subdirs = dir: - let sub = builtins.readDir dir; - in builtins.filter - (d: sub.${d} == "directory") - (builtins.attrNames sub); + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; - vowelStart = str: builtins.elem (builtins.substring 0 1 str) [ "a" "e" "i" "o" "u" ]; + outputs = { self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; - concatMapAttrs = func: attr: - builtins.foldl' (x: y: x // y) {} - (builtins.map func attr); - - 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 ./.); - }; + 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; + }); } diff --git a/python/nixpkgs/.envrc b/python/.envrc similarity index 100% rename from python/nixpkgs/.envrc rename to python/.envrc diff --git a/python/nixpkgs/bin/soe b/python/bin/soe-python old mode 100755 new mode 100644 similarity index 100% rename from python/nixpkgs/bin/soe rename to python/bin/soe-python diff --git a/python/nixpkgs/package.nix b/python/default.nix similarity index 68% rename from python/nixpkgs/package.nix rename to python/default.nix index 961c388..76a15d5 100644 --- a/python/nixpkgs/package.nix +++ b/python/default.nix @@ -1,7 +1,7 @@ -{ python3 }: +{ python3, ... }: python3.pkgs.buildPythonApplication { - pname = "soe"; + pname = "soe-python"; version = "1.0"; src = ./.; diff --git a/python/nixpkgs/flake.lock b/python/nixpkgs/flake.lock deleted file mode 100644 index c44d5a5..0000000 --- a/python/nixpkgs/flake.lock +++ /dev/null @@ -1,43 +0,0 @@ -{ - "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 deleted file mode 100644 index 9505679..0000000 --- a/python/nixpkgs/flake.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ - 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/nixpkgs/setup.py b/python/setup.py similarity index 71% rename from python/nixpkgs/setup.py rename to python/setup.py index 158092b..0e31be3 100644 --- a/python/nixpkgs/setup.py +++ b/python/setup.py @@ -3,5 +3,5 @@ from setuptools import setup setup( name="soe", version="1.0.0", - scripts=["bin/soe"] + scripts=["bin/soe-python"] ) diff --git a/python/nixpkgs/shell.nix b/python/shell.nix similarity index 53% rename from python/nixpkgs/shell.nix rename to python/shell.nix index 332eaff..5feafb5 100644 --- a/python/nixpkgs/shell.nix +++ b/python/shell.nix @@ -1,3 +1,2 @@ -{ python3 }: - +{ python3, ... }: python3.buildEnv.env diff --git a/python/nixpkgs/soe/__init__.py b/python/soe/__init__.py similarity index 100% rename from python/nixpkgs/soe/__init__.py rename to python/soe/__init__.py diff --git a/python/nixpkgs/soe/main.py b/python/soe/main.py similarity index 59% rename from python/nixpkgs/soe/main.py rename to python/soe/main.py index f6a1425..23f1cf2 100644 --- a/python/nixpkgs/soe/main.py +++ b/python/soe/main.py @@ -1,4 +1,5 @@ + def sieve_of_eratosthenes(n): nums = list(range(2, n)) while nums: @@ -7,11 +8,18 @@ def sieve_of_eratosthenes(n): yield prime def main(): - num = int(input("Primes up to: ")) + num = 0 + another = True + while another: + try: + num = int(input()) + another = False + except ValueError: + pass + print() for i in sieve_of_eratosthenes(num): - print(i, end=" ") - print() + print(i) if __name__ == "__main__":