From 1b5242781bde0dba283aef8d8d97b3fd47308c31 Mon Sep 17 00:00:00 2001 From: Isaac Johnson Date: Mon, 18 May 2026 14:59:17 +0000 Subject: [PATCH] init --- .gitconfig | 2 + .gitignore | 67 +++++++++++++++ README.md | 3 + airules.md | 186 +++++++++++++++++++++++++++++++++++++++++ dev.nix | 55 ++++++++++++ perlmcp.code-workspace | 8 ++ server.pl | 42 ++++++++++ 7 files changed, 363 insertions(+) create mode 100644 .gitconfig create mode 100644 .gitignore create mode 100644 README.md create mode 100644 airules.md create mode 100644 dev.nix create mode 100644 perlmcp.code-workspace create mode 100644 server.pl diff --git a/.gitconfig b/.gitconfig new file mode 100644 index 0000000..f8fe004 --- /dev/null +++ b/.gitconfig @@ -0,0 +1,2 @@ +[safe] + directory = /home/coder diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ae42db --- /dev/null +++ b/.gitignore @@ -0,0 +1,67 @@ +# Created by https://www.toptal.com/developers/gitignore/api/linux,perl,perl6 +# Edit at https://www.toptal.com/developers/gitignore?templates=linux,perl,perl6 + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Perl ### +!Build/ +.last_cover_stats +/META.yml +/META.json +/MYMETA.* +*.o +*.pm.tdy +*.bs + +# Devel::Cover +cover_db/ + +# Devel::NYTProf +nytprof.out + +# Dist::Zilla +/.build/ + +# Module::Build +_build/ +Build +Build.bat + +# Module::Install +inc/ + +# ExtUtils::MakeMaker +/blib/ +/_eumm/ +/*.gz +/Makefile +/Makefile.old +/MANIFEST.bak +/pm_to_blib +/*.zip + +# Carton +local/ + +### Perl6 ### +# Gitignore for Perl 6 (http://www.perl6.org) +# As part of https://github.com/github/gitignore + +# precompiled files +.precomp +lib/.precomp + +# End of https://www.toptal.com/developers/gitignore/api/linux,perl,perl6 diff --git a/README.md b/README.md new file mode 100644 index 0000000..d15056d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Get started by customizing your environment (defined in the .idx/dev.nix file) with the tools and IDE extensions you'll need for your project! + +Learn more at https://developers.google.com/idx/guides/customize-idx-env \ No newline at end of file diff --git a/airules.md b/airules.md new file mode 100644 index 0000000..aaf780c --- /dev/null +++ b/airules.md @@ -0,0 +1,186 @@ +# Gemini AI Rules for Firebase Studio Nix Projects + +## 1. Persona & Expertise + +You are an expert in configuring development environments within Firebase Studio. You are proficient in using the `dev.nix` file to define reproducible, declarative, and isolated development environments. You have experience with the Nix language in the context of Firebase Studio, including packaging, managing dependencies, and configuring services. + +## 2. Project Context + +This project is a Nix-based environment for Firebase Studio, defined by a `.idx/dev.nix` file. The primary goal is to ensure a reproducible and consistent development environment. The project leverages the power of Nix to manage dependencies, tools, and services in a declarative manner. **Note:** This is not a Nix Flake-based environment. + +## 3. `dev.nix` Configuration + +The `.idx/dev.nix` file is the single source of truth for the development environment. Here are some of the most common configuration options: + +### `channel` +The `nixpkgs` channel determines which package versions are available. + +```nix +{ pkgs, ... }: { + channel = "stable-24.05"; # or "unstable" +} +``` + +### `packages` +A list of packages to install from the specified channel. You can search for packages on the [NixOS package search](https://search.nixos.org/packages). + +```nix +{ pkgs, ... }: { + packages = [ + pkgs.nodejs_20 + pkgs.go + ]; +} +``` + +### `env` +A set of environment variables to define within the workspace. + +```nix +{ pkgs, ... }: { + env = { + API_KEY = "your-secret-key"; + }; +} +``` + +### `idx.extensions` +A list of VS Code extensions to install from the [Open VSX Registry](https://open-vsx.org/). + +```nix +{ pkgs, ... }: { + idx = { + extensions = [ + "vscodevim.vim" + "golang.go" + ]; + }; +} +``` + +### `idx.workspace` +Workspace lifecycle hooks. + +- **`onCreate`:** Runs when a workspace is first created. +- **`onStart`:** Runs every time the workspace is (re)started. + +```nix +{ pkgs, ... }: { + idx = { + workspace = { + onCreate = { + npm-install = "npm install"; + }; + onStart = { + start-server = "npm run dev"; + }; + }; + }; +} +``` + +### `idx.previews` +Configure a web preview for your application. The `$PORT` variable is dynamically assigned. + +```nix +{ pkgs, ... }: { + idx = { + previews = { + enable = true; + previews = { + web = { + command = ["npm" "run" "dev" "--" "--port" "$PORT"]; + manager = "web"; + }; + }; + }; + }; +} +``` + +## 4. Example Setups for Common Frameworks + +Here are some examples of how to configure your `dev.nix` for common languages and frameworks. + +### Node.js Web Server +This example sets up a Node.js environment, installs dependencies, and runs a development server with a web preview. + +```nix +{ pkgs, ... }: { + packages = [ pkgs.nodejs_20 ]; + idx = { + extensions = [ "dbaeumer.vscode-eslint" ]; + workspace = { + onCreate = { + npm-install = "npm install"; + }; + onStart = { + dev-server = "npm run dev"; + }; + }; + previews = { + enable = true; + previews = { + web = { + command = ["npm" "run" "dev" "--" "--port" "$PORT"]; + manager = "web"; + }; + }; + }; + }; +} +``` + +### Python with Flask +This example sets up a Python environment for a Flask web server. Remember to create a `requirements.txt` file with `Flask` in it. + +```nix +{ pkgs, ... }: { + packages = [ pkgs.python3 pkgs.pip ]; + idx = { + extensions = [ "ms-python.python" ]; + workspace = { + onCreate = { + pip-install = "pip install -r requirements.txt"; + }; + }; + previews = { + enable = true; + previews = { + web = { + command = ["flask" "run" "--port" "$PORT"]; + manager = "web"; + }; + }; + }; + }; +} +``` + +### Go CLI +This example sets up a Go environment for building a command-line interface. + +```nix +{ pkgs, ... }: { + packages = [ pkgs.go ]; + idx = { + extensions = [ "golang.go" ]; + workspace = { + onCreate = { + go-mod = "go mod tidy"; + }; + onStart = { + run-app = "go run ."; + }; + }; + }; +} +``` + +## 5. Interaction Guidelines + +- Assume the user is familiar with general software development concepts but may be new to Nix and Firebase Studio. +- When generating Nix code, provide comments to explain the purpose of different sections. +- Explain the benefits of using `dev.nix` for reproducibility and dependency management. +- If a request is ambiguous, ask for clarification on the desired tools, libraries, and versions to be included in the environment. +- When suggesting changes to `dev.nix`, explain the impact of the changes on the development environment and remind the user to reload the environment. diff --git a/dev.nix b/dev.nix new file mode 100644 index 0000000..f1ccff0 --- /dev/null +++ b/dev.nix @@ -0,0 +1,55 @@ + To learn more about how to use Nix to configure your environment +# see: https://developers.google.com/idx/guides/customize-idx-env +{ pkgs }: { + # Which nixpkgs channel to use. + channel = "stable-24.05"; # or "unstable" + # Use https://search.nixos.org/packages to find packages + packages = [ + # pkgs.go + # pkgs.python311 + # pkgs.python311Packages.pip + # pkgs.nodejs_20 + # pkgs.nodePackages.nodemon + pkgs.perl + ]; + # Sets environment variables in the workspace + env = {}; + idx = { + # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id" + extensions = [ + # "vscodevim.vim" + "google.gemini-cli-vscode-ide-companion" + ]; + # Enable previews + previews = { + enable = true; + previews = { + # web = { + # # Example: run "npm run dev" with PORT set to IDX's defined port for previews, + # # and show it in IDX's web preview panel + # command = ["npm" "run" "dev"]; + # manager = "web"; + # env = { + # # Environment variables to set for your server + # PORT = "$PORT"; + # }; + # }; + }; + }; + # Workspace lifecycle hooks + workspace = { + # Runs when a workspace is first created + onCreate = { + # Example: install JS dependencies from NPM + # npm-install = "npm install"; + # Open editors for the following files by default, if they exist: + default.openFiles = [ ".idx/dev.nix" "README.md" ]; + }; + # Runs when the workspace is (re)started + onStart = { + # Example: start a background task to watch and re-build backend code + # watch-backend = "npm run watch-backend"; + }; + }; + }; +} diff --git a/perlmcp.code-workspace b/perlmcp.code-workspace new file mode 100644 index 0000000..bab1b7f --- /dev/null +++ b/perlmcp.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": ".." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/server.pl b/server.pl new file mode 100644 index 0000000..8329801 --- /dev/null +++ b/server.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl +{ +package MyWebServer; +use HTTP::Server::Simple::CGI; +use base qw(HTTP::Server::Simple::CGI); +my %dispatch = ( + '/hello' => \&resp_hello, + # ... +); +sub handle_request { + my $self = shift; + my $cgi = shift; + + my $path = $cgi->path_info(); + my $handler = $dispatch{$path}; + if (ref($handler) eq "CODE") { + print "HTTP/1.0 200 OK\r\n"; + $handler->($cgi); + + } else { + print "HTTP/1.0 404 Not found\r\n"; + print $cgi->header, + $cgi->start_html('Not found'), + $cgi->h1('Not found'), + $cgi->end_html; + } +} +sub resp_hello { + my $cgi = shift; # CGI.pm object + return if !ref $cgi; + + my $who = $cgi->param('name'); + + print $cgi->header, + $cgi->start_html("Hello"), + $cgi->h1("Hello $who!"), + $cgi->end_html; +} +} +# start the server on port 8080 +my $pid = MyWebServer->new(8080)->background(); +print "Use 'kill $pid' to stop server.\n"; \ No newline at end of file