feat(nix): add flake templates

Signed-off-by: Seongmin Lee <git@boltless.me>

boltless.me cf3bb887 cef3dbdf

verified
Changed files
+68
nix
templates
+2
nix/flake.nix
··· 118 118 pkgs.slack 119 119 ] else []); 120 120 }; 121 + # This can be just `imports = [ ./templates/templates.nix ]` when using flake-parts 122 + templates = ((import ./templates/templates.nix) { inherit inputs; }).flake.templates; 121 123 }; 122 124 } 123 125 # vim: et:ts=2
+48
nix/templates/python/flake.nix
··· 1 + { 2 + description = "python flake"; 3 + inputs = { 4 + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 5 + flake-parts.url = "github:hercules-ci/flake-parts"; 6 + }; 7 + outputs = inputs @ { flake-parts, ... }: 8 + flake-parts.lib.mkFlake { inherit inputs; } { 9 + systems = [ 10 + "x86_64-linux" 11 + "aarch64-linux" 12 + "aarch64-darwin" 13 + ]; 14 + perSystem = { pkgs, system, ... }: let 15 + commonPackages = [ 16 + pkgs.python313Full 17 + pkgs.pyright 18 + pkgs.uv 19 + pkgs.curl 20 + pkgs.wget 21 + pkgs.cmake 22 + ] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ 23 + pkgs.gcc 24 + pkgs.stdenv.cc.cc.lib 25 + ]; 26 + in { 27 + devShells.default = pkgs.mkShell { 28 + buildInputs = commonPackages; 29 + shellHook = '' 30 + # Set up the Python virtual environment with uv 31 + test -d .venv || ${pkgs.uv}/bin/uv venv .venv 32 + export VIRTUAL_ENV="$(pwd)/.venv" 33 + export PATH="$VIRTUAL_ENV/bin:$PATH" 34 + export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath commonPackages}:$LD_LIBRARY_PATH 35 + 36 + source "$VIRTUAL_ENV/bin/activate" 37 + 38 + if uv sync --frozen; then 39 + package_count=$(uv pip list --format=freeze | wc -l) 40 + echo "Done. $package_count pip packages installed." 41 + else 42 + echo "Warning: An error occurred during uv sync." 43 + fi 44 + ''; 45 + }; 46 + }; 47 + }; 48 + }
+18
nix/templates/templates.nix
··· 1 + { inputs, ... }: 2 + let templatesDir = ./.; 3 + in { 4 + flake.templates = let 5 + mkTemplate = name: val: 6 + let 7 + path = templatesDir + "/${name}"; 8 + flake = import (path + "/flake.nix"); 9 + in { 10 + inherit path; 11 + description = flake.description; 12 + }; 13 + templateEntities = let 14 + op = _: val: val == "directory"; 15 + as = builtins.readDir templatesDir; 16 + in inputs.nixpkgs.lib.filterAttrs op as; 17 + in builtins.mapAttrs mkTemplate templateEntities; 18 + }