From a8a26921b4784ae8945ef390ba2f771ddfa599a9 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sun, 28 Jul 2024 06:01:20 -0400 Subject: [PATCH] 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