From f8d90b5ec3a466f344efb3a4e815b5c126df6def Mon Sep 17 00:00:00 2001 From: Christoph Herb <52382992+chrishrb@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:47:10 +0200 Subject: [PATCH] add templates --- flake.nix | 15 ++++++++++++++- templates/README.md | 7 +++++++ templates/basic/flake.nix | 30 ++++++++++++++++++++++++++++++ templates/python/flake.nix | 27 +++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 templates/README.md create mode 100644 templates/basic/flake.nix create mode 100644 templates/python/flake.nix diff --git a/flake.nix b/flake.nix index f16fe94..a4a373e 100644 --- a/flake.nix +++ b/flake.nix @@ -113,7 +113,6 @@ }; # Programs that can be run by calling this flake - #apps = forAllSystems (system: apps = forAllSystems ( system: let @@ -134,6 +133,7 @@ }); + # Checks for nvim health checks = forAllSystems (system: let pkgs = import nixpkgs { inherit system overlays; }; @@ -154,5 +154,18 @@ } ); + # Templates for starting other projects quickly + templates = rec { + default = basic; + basic = { + path = ./templates/basic; + description = "Basic program template"; + }; + python = { + path = ./templates/python; + description = "Python template"; + }; + }; + }; } diff --git a/templates/README.md b/templates/README.md new file mode 100644 index 0000000..95e4de5 --- /dev/null +++ b/templates/README.md @@ -0,0 +1,7 @@ +# Templates + +These are new flakes that can be generated quickly using: + +```bash +nix flake init -t github:chrishrb/dotfiles#basic +``` diff --git a/templates/basic/flake.nix b/templates/basic/flake.nix new file mode 100644 index 0000000..fa9cc27 --- /dev/null +++ b/templates/basic/flake.nix @@ -0,0 +1,30 @@ +{ + description = "Basic project"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + outputs = { self, nixpkgs, ... }@inputs: inputs.flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + packages.default = pkgs.mkDerivation { + name = "basic"; + src = self; + # buildInputs = with pkgs; []; + buildPhase = '' + echo "Building..." + mkdir -p $out/bin + echo "#!/bin/bash" > $out/bin/hello.sh + echo "echo Hello, world!" >> $out/bin/hello.sh + ''; + }; + + devShells.default = pkgs.mkShell { + # buildInputs = with pkgs; [ ]; + }; + } + ); +} diff --git a/templates/python/flake.nix b/templates/python/flake.nix new file mode 100644 index 0000000..89cb680 --- /dev/null +++ b/templates/python/flake.nix @@ -0,0 +1,27 @@ +{ + description = "Python template"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + outputs = { nixpkgs, self, ... }@inputs: inputs.flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + packages.default = pkgs.python312Packages.buildPythonApplication { + name = "python-cli"; + src = self; + buildInputs = with pkgs.python312Packages; [ pip setuptools wheel ]; + checkInputs = with pkgs.python312Packages; [ pytest arnparse requests-mock ]; + propagatedBuildInputs = with pkgs.python3Packages; [ + boto3 + requests + urllib3 + click + ]; + }; + } + ); +}