diff --git a/flake.nix b/flake.nix index 2d28fd3..b81602c 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ templates = { default = { - path = ./templates/php; + path = ./templates/default; description = "A simple boilerplate for running Laravel with nix run."; }; nodejs = { diff --git a/templates/default/.envrc b/templates/default/.envrc new file mode 100644 index 0000000..48a5693 --- /dev/null +++ b/templates/default/.envrc @@ -0,0 +1,3 @@ +use flake + +export PATH="$PATH:./vendor/bin" \ No newline at end of file diff --git a/templates/default/.gitignore b/templates/default/.gitignore new file mode 100644 index 0000000..4a8461c --- /dev/null +++ b/templates/default/.gitignore @@ -0,0 +1,3 @@ +.direnv +node_modules +vendor diff --git a/templates/default/Caddyfile b/templates/default/Caddyfile new file mode 100644 index 0000000..3b3788e --- /dev/null +++ b/templates/default/Caddyfile @@ -0,0 +1,34 @@ +(cors) { + @origin header Origin {args[0]} + header @origin Access-Control-Allow-Origin "{args[0]}" + header @origin Access-Control-Allow-Methods "OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE" +} + +wp.test { + root * . + + encode zstd gzip + file_server + php_fastcgi 127.0.0.1:9009 + + tls internal +} + +laravel.test { + # import cors laravel.test + + respond /caddy/live OK + + root * ./public + + try_files {path} page-cache/{path}.html page-cache/{path}.json page-cache/{path}.xml + + encode zstd gzip + file_server + php_fastcgi 127.0.0.1:9009 + + # Uncomment for Laravel Octane + # reverse_proxy :8000 + + tls internal +} diff --git a/templates/default/flake.lock b/templates/default/flake.lock new file mode 100644 index 0000000..d8707ee --- /dev/null +++ b/templates/default/flake.lock @@ -0,0 +1,113 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1751413152, + "narHash": "sha256-Tyw1RjYEsp5scoigs1384gIg6e0GoBVjms4aXFfRssQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "77826244401ea9de6e3bac47c2db46005e1f30b5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1751949589, + "narHash": "sha256-mgFxAPLWw0Kq+C8P3dRrZrOYEQXOtKuYVlo9xvPntt8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b008d60392981ad674e04016d25619281550a9d", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1751159883, + "narHash": "sha256-urW/Ylk9FIfvXfliA1ywh75yszAbiTEVgpPeinFyVZo=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "14a40a1d7fb9afa4739275ac642ed7301a9ba1ab", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1751949589, + "narHash": "sha256-mgFxAPLWw0Kq+C8P3dRrZrOYEQXOtKuYVlo9xvPntt8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b008d60392981ad674e04016d25619281550a9d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "process-compose-flake": { + "locked": { + "lastModified": 1749418557, + "narHash": "sha256-wJHHckWz4Gvj8HXtM5WVJzSKXAEPvskQANVoRiu2w1w=", + "owner": "Platonic-Systems", + "repo": "process-compose-flake", + "rev": "91dcc48a6298e47e2441ec76df711f4e38eab94e", + "type": "github" + }, + "original": { + "owner": "Platonic-Systems", + "repo": "process-compose-flake", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable", + "process-compose-flake": "process-compose-flake", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1752055615, + "narHash": "sha256-19m7P4O/Aw/6+CzncWMAJu89JaKeMh3aMle1CNQSIwM=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "c9d477b5d5bd7f26adddd3f96cfd6a904768d4f9", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/default/flake.nix b/templates/default/flake.nix new file mode 100644 index 0000000..d6bf5ca --- /dev/null +++ b/templates/default/flake.nix @@ -0,0 +1,91 @@ +{ + description = "A dev environment"; + + inputs = { + # nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + flake-parts.url = "github:hercules-ci/flake-parts"; + process-compose-flake.url = "github:Platonic-Systems/process-compose-flake"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = + inputs@{ self + , flake-parts + , nixpkgs + , nixpkgs-unstable + , process-compose-flake + , treefmt-nix + }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + inputs.treefmt-nix.flakeModule + # inputs.process-compose-flake.flakeModule + ]; + systems = [ "x86_64-linux" ]; + + perSystem = + { pkgs, system, inputs', ... }: { + _module.args.pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + + overlays = [ + (final: prev: { unstable = inputs'.nixpkgs-unstable.legacyPackages; }) + ]; + }; + + treefmt = { + # Used to find the project root + projectRootFile = "flake.nix"; + settings.global.excludes = [ + ".direnv/**" + ".jj/**" + ".env" + ".envrc" + ".env.local" + ]; + + + # Format nix files + programs.nixpkgs-fmt.enable = true; + programs.deadnix.enable = true; + + # Format js, json, and yaml files + programs.prettier.enable = true; + settings.formatter.prettier = + { + excludes = [ + "public/**" + "resources/js/modernizr.js" + "storage/app/caniuse.json" + "*.md" + ]; + }; + }; + + /* + process-compose.default.settings.processes = { + web.command = "sudo ${pkgs.caddy}/bin/caddy run"; + mail.command = "${pkgs.mailhog}/bin/MailHog"; + php.command = "${php}/bin/php-fpm -F -y php-fpm.conf"; + redis.command = "${$pks.redis}/bin/redis-server"; + }; + */ + + devShells.default = pkgs.mkShell + { + buildInputs = with pkgs; [ + # TODO: Packages go here. + + # IDE + unstable.helix + typescript-language-server + vscode-langservers-extracted + ]; + }; + }; + }; +} diff --git a/templates/php/flake.lock b/templates/php/flake.lock index b92900f..d8707ee 100644 --- a/templates/php/flake.lock +++ b/templates/php/flake.lock @@ -5,11 +5,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1738453229, - "narHash": "sha256-7H9XgNiGLKN1G1CgRh0vUL4AheZSYzPm+zmZ7vxbJdo=", + "lastModified": 1751413152, + "narHash": "sha256-Tyw1RjYEsp5scoigs1384gIg6e0GoBVjms4aXFfRssQ=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "32ea77a06711b758da0ad9bd6a844c5740a87abd", + "rev": "77826244401ea9de6e3bac47c2db46005e1f30b5", "type": "github" }, "original": { @@ -20,11 +20,12 @@ }, "nixpkgs": { "locked": { - "lastModified": 1736916166, - "narHash": "sha256-puPDoVKxkuNmYIGMpMQiK8bEjaACcCksolsG36gdaNQ=", - "path": "/nix/store/awsvw44jla0idziiks2zwgzslfd2dczn-source", - "rev": "e24b4c09e963677b1beea49d411cd315a024ad3a", - "type": "path" + "lastModified": 1751949589, + "narHash": "sha256-mgFxAPLWw0Kq+C8P3dRrZrOYEQXOtKuYVlo9xvPntt8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b008d60392981ad674e04016d25619281550a9d", + "type": "github" }, "original": { "id": "nixpkgs", @@ -33,23 +34,42 @@ }, "nixpkgs-lib": { "locked": { - "lastModified": 1738452942, - "narHash": "sha256-vJzFZGaCpnmo7I6i416HaBLpC+hvcURh/BQwROcGIp8=", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz" + "lastModified": 1751159883, + "narHash": "sha256-urW/Ylk9FIfvXfliA1ywh75yszAbiTEVgpPeinFyVZo=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "14a40a1d7fb9afa4739275ac642ed7301a9ba1ab", + "type": "github" }, "original": { - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz" + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1751949589, + "narHash": "sha256-mgFxAPLWw0Kq+C8P3dRrZrOYEQXOtKuYVlo9xvPntt8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b008d60392981ad674e04016d25619281550a9d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" } }, "process-compose-flake": { "locked": { - "lastModified": 1733325752, - "narHash": "sha256-79tzPuXNRo1NUllafYW6SjeLtjqfnLGq7tHCM7cAXNg=", + "lastModified": 1749418557, + "narHash": "sha256-wJHHckWz4Gvj8HXtM5WVJzSKXAEPvskQANVoRiu2w1w=", "owner": "Platonic-Systems", "repo": "process-compose-flake", - "rev": "1012530b582f1bd3b102295c799358d95abf42d7", + "rev": "91dcc48a6298e47e2441ec76df711f4e38eab94e", "type": "github" }, "original": { @@ -62,6 +82,7 @@ "inputs": { "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable", "process-compose-flake": "process-compose-flake", "treefmt-nix": "treefmt-nix" } @@ -73,11 +94,11 @@ ] }, "locked": { - "lastModified": 1738953846, - "narHash": "sha256-yrK3Hjcr8F7qS/j2F+r7C7o010eVWWlm4T1PrbKBOxQ=", + "lastModified": 1752055615, + "narHash": "sha256-19m7P4O/Aw/6+CzncWMAJu89JaKeMh3aMle1CNQSIwM=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "4f09b473c936d41582dd744e19f34ec27592c5fd", + "rev": "c9d477b5d5bd7f26adddd3f96cfd6a904768d4f9", "type": "github" }, "original": { diff --git a/templates/php/flake.nix b/templates/php/flake.nix index fd097f9..1b8aff2 100644 --- a/templates/php/flake.nix +++ b/templates/php/flake.nix @@ -1,12 +1,9 @@ { - description = "A very basic flake"; + description = "A PHP dev environment"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; + # nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - # dolt.url = "github:sbrow/dolt"; - # phps.url = "github:fossar/nix-phps"; - # phps.inputs.nixpkgs.follows = "nixpkgs"; flake-parts.url = "github:hercules-ci/flake-parts"; process-compose-flake.url = "github:Platonic-Systems/process-compose-flake"; @@ -45,7 +42,7 @@ xdebug.client_port=9000 ; xdebug 2 - xdebug.remote_enable=1 + ; xdebug.remote_enable=1 ''; }; in @@ -75,22 +72,7 @@ programs.nixpkgs-fmt.enable = true; programs.deadnix.enable = true; - # Format php files - /* - settings.formatter."pint" = - { - command = "./vendor/bin/pint"; - includes = [ "*[!.blade].php" ]; - excludes = [ "_ide_helper*.php" ]; - }; - - # Format blade files - settings.formatter."blade-formatter" = { - command = "./bin/blade-formatter"; - options = [ "--write" ]; - includes = [ "*.blade.php" ]; - }; - */ + # TODO: Format php files # Format js, json, and yaml files programs.prettier.enable = true; @@ -103,23 +85,13 @@ "*.md" ]; }; - - # Format elm components - #programs.elm-format.enable = true; - - # Override the default package - #programs.terraform.package = nixpkgs.terraform_1; }; process-compose.default.settings.processes = { web.command = "sudo ${pkgs.caddy}/bin/caddy run"; mail.command = "${pkgs.mailhog}/bin/MailHog"; php.command = "${php}/bin/php-fpm -F -y php-fpm.conf"; - #php.command = "${php} artisan octane:start --watch"; # redis.command = "${$pks.redis}/bin/redis-server"; - # db.command = "${doltPkg}/bin/dolt sql-server --config dolt.yml"; - # worker.command = php artisan horizon; - # schedule.command = php artisan schedule:work; }; devShells.default = pkgs.mkShell