From edcf6f758e2a901a0f2f832b3c9cc827b76ced50 Mon Sep 17 00:00:00 2001 From: Artur Manuel Date: Sun, 11 Aug 2024 08:22:48 +0100 Subject: [PATCH] repo: init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit welcome 👋 to my world 🌍 --- LICENSE | 13 +++++++++++++ README.md | 10 ++++++++-- flake.nix | 12 ++++++++++++ templates/python/.gitignore | 1 + templates/python/README | 1 + templates/python/flake.lock | 27 ++++++++++++++++++++++++++ templates/python/flake.nix | 26 +++++++++++++++++++++++++ templates/python/nix/package.nix | 16 +++++++++++++++ templates/python/nix/shell.nix | 8 ++++++++ templates/python/python-app/python-app | 11 +++++++++++ templates/python/python-app/setup.py | 11 +++++++++++ 11 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 LICENSE create mode 100644 flake.nix create mode 100644 templates/python/.gitignore create mode 100644 templates/python/README create mode 100644 templates/python/flake.lock create mode 100644 templates/python/flake.nix create mode 100644 templates/python/nix/package.nix create mode 100644 templates/python/nix/shell.nix create mode 100644 templates/python/python-app/python-app create mode 100644 templates/python/python-app/setup.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5c93f45 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md index cf66b2c..e338017 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ -# flake-template-hell +### Flake Templates +###### My templates I have created whenever I need to make a Nix flake for a project. -My flake templates, forAllSystems... and languages. \ No newline at end of file +--- + +### Why? + +This is just a handy timesaver that I can use whenever I need to make some project and repo. +It also may be handy for those that need to borrow a flake template for their own project and repo. diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7d68532 --- /dev/null +++ b/flake.nix @@ -0,0 +1,12 @@ +{ + description = "Flake Template Hell"; + + outputs = _: { + templates = { + "python" = { + path = ./templates/python; + description = "python flake template"; + }; + }; + }; +} diff --git a/templates/python/.gitignore b/templates/python/.gitignore new file mode 100644 index 0000000..41fbeb0 --- /dev/null +++ b/templates/python/.gitignore @@ -0,0 +1 @@ +**/result diff --git a/templates/python/README b/templates/python/README new file mode 100644 index 0000000..56689bc --- /dev/null +++ b/templates/python/README @@ -0,0 +1 @@ +remember to change python-app to whatever you please! diff --git a/templates/python/flake.lock b/templates/python/flake.lock new file mode 100644 index 0000000..9ed2b35 --- /dev/null +++ b/templates/python/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1722987190, + "narHash": "sha256-68hmex5efCiM2aZlAAEcQgmFI4ZwWt8a80vOeB/5w3A=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "21cc704b5e918c5fbf4f9fff22b4ac2681706d90", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/python/flake.nix b/templates/python/flake.nix new file mode 100644 index 0000000..12a76e7 --- /dev/null +++ b/templates/python/flake.nix @@ -0,0 +1,26 @@ +{ + description = "Python flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; + }; + + outputs = { self, nixpkgs }: + let + systems = [ "x86_64-linux" "aarch64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs systems; + pkgsForEach = nixpkgs.legacyPackages; + in + { + packages = forAllSystems (system: { + default = pkgsForEach.${system}.callPackage ./nix/package.nix { }; + python-app = self.packages.${system}.default; + }); + + devShells = forAllSystems (system: { + default = pkgsForEach.${system}.callPackage ./nix/shell.nix { + inherit (self.packages.${system}) python-app; + }; + }); + }; +} diff --git a/templates/python/nix/package.nix b/templates/python/nix/package.nix new file mode 100644 index 0000000..e025dbd --- /dev/null +++ b/templates/python/nix/package.nix @@ -0,0 +1,16 @@ +{ python3Packages }: +let + pname = "python-app"; + version = "0.1.0"; + inherit (python3Packages) + buildPythonApplication + flask + ; +in +buildPythonApplication { + inherit pname version; + propagatedBuildInputs = [ + flask + ]; + src = ../${pname}; +} diff --git a/templates/python/nix/shell.nix b/templates/python/nix/shell.nix new file mode 100644 index 0000000..1b714d2 --- /dev/null +++ b/templates/python/nix/shell.nix @@ -0,0 +1,8 @@ +{ mkShell, python-app, python312Packages }: +mkShell { + inputsFrom = [ python-app ]; + nativeBuildInputs = [ + python312Packages.ruff-lsp + python312Packages.ruff + ]; +} diff --git a/templates/python/python-app/python-app b/templates/python/python-app/python-app new file mode 100644 index 0000000..0e8ea3b --- /dev/null +++ b/templates/python/python-app/python-app @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +from flask import Flask +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello, World!' + +if __name__ == '__main__': + app.run(host="0.0.0.0", port=8080) diff --git a/templates/python/python-app/setup.py b/templates/python/python-app/setup.py new file mode 100644 index 0000000..f27b28a --- /dev/null +++ b/templates/python/python-app/setup.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +from setuptools import setup, find_packages + +setup(name='python-app', + version='0.1.0', + # Modules to import from other scripts: + packages=find_packages(), + # Executables + scripts=["python-app"], + )