diff --git a/.envrc b/.envrc index a96880d..e3c2943 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1,7 @@ -use flake -dotenv_if_exists +export DIRENV_WARN_TIMEOUT=20s + +eval "$(devenv direnvrc)" + +# The use_devenv function supports passing flags to the devenv command +# For example: use devenv --impure --option services.postgres.enable:bool true +use devenv diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0febf2e..361fcc3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,16 +32,16 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install Nix - uses: cachix/install-nix-action@v27 - with: - nix_path: nixpkgs=channel:nixos-unstable + uses: cachix/install-nix-action@v31 + - name: Install devenv + run: nix profile install nixpkgs#devenv - name: Migrate database - run: nix develop --command -- just migrate + run: devenv shell just migrate - name: Formatting check - run: nix develop --command -- just format-check + run: devenv shell just format-check - name: Lint - run: nix develop --command -- just lint + run: devenv shell just lint - name: Audit - run: nix develop --command -- just audit + run: devenv shell just audit - name: Tests - run: nix develop --command -- just test + run: devenv shell just test diff --git a/.gitignore b/.gitignore index 753d933..0d0bbb0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,54 @@ .env /coverage /target + +# Devenv +.devenv* +devenv.local.nix + +# direnv +.direnv + +# pre-commit +.pre-commit-config.yaml + +# Emacs backup files +*~ +\#*\# +.\#* + +# Vim files +*.swp +*.swo +*~ + +# VS Code +.vscode/ +*.code-workspace + +# JetBrains IDEs +.idea/ +*.iml + +# macOS +.DS_Store +.AppleDouble +.LSOverride + +# Windows +Thumbs.db +ehthumbs.db +Desktop.ini + +# Linux +*~ + +# Temporary files +*.tmp +*.temp +*.log + +# OS generated files +.Spotlight-V100 +.Trashes +._* diff --git a/README.md b/README.md index 61d63df..ac5fc13 100644 --- a/README.md +++ b/README.md @@ -628,29 +628,31 @@ bacon test bacon doc ``` -#### Nix Development Environment (Optional) +#### Devenv Development Environment (Optional) -If you use [Nix](https://nixos.org/), you can use the provided flake for a reproducible development environment: +If you use [Nix](https://nixos.org/), you can use the provided devenv configuration for a reproducible development environment: ```bash # Enter the development shell with all tools pre-installed -nix develop +devenv shell # Or use direnv for automatic environment activation direnv allow ``` -The Nix flake provides: +The devenv configuration provides: - Exact Rust version (1.81) with required components - All development tools (just, cargo-deny, sqlx-cli, bacon) - LSP support (rust-analyzer) - SQL tooling (sqls for SQL language server) +- PostgreSQL database for development -**Nix flake contents:** +**Devenv configuration:** - **Rust toolchain**: Specified version with rustfmt, clippy, and rust-analyzer - **Development tools**: just, cargo-deny, sqlx-cli, bacon - **SQL tools**: sqls (SQL language server) -- **Platform support**: Currently x86_64-linux (can be extended) +- **Database**: PostgreSQL with automatic setup +- **Platform support**: Cross-platform (Linux, macOS, etc.) #### Database Setup for Tests diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 0000000..cba30e2 --- /dev/null +++ b/devenv.lock @@ -0,0 +1,123 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1749054588, + "owner": "cachix", + "repo": "devenv", + "rev": "b6be42d9e6f6053be1d180e4a4fb95e0aa9a8424", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1747046372, + "owner": "edolstra", + "repo": "flake-compat", + "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1747372754, + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "80479b6ec16fefd9c1db3ea13aeb038c60530f46", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1746807397, + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "c5208b594838ea8e6cca5997fbf784b7cca1ca90", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": [ + "git-hooks" + ], + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1749091064, + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "12419593ce78f2e8e1e89a373c6515885e218acb", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 0000000..517e84e --- /dev/null +++ b/devenv.nix @@ -0,0 +1,36 @@ +{ pkgs, nixpkgs, rust-overlay, ... }: +let + overlays = [ (import rust-overlay) ]; + system = pkgs.stdenv.system; + rustPkgs = import nixpkgs { inherit system overlays; }; + rustVersion = (rustPkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml); +in { + dotenv.enable = true; + + packages = with rustPkgs; [ + bacon + cargo-deny + just + postgresql + sqls + sqlx-cli + (rustVersion.override { + extensions = [ + "rust-src" + "rustfmt" + "clippy" + "rust-analyzer" + ]; + }) + ]; + + services.postgres = { + enable = true; + listen_addresses = "localhost"; + initialScript = '' + CREATE USER georm WITH PASSWORD 'georm' SUPERUSER; + CREATE DATABASE georm OWNER georm; + GRANT ALL PRIVILEGES ON DATABASE georm TO georm; + ''; + }; +} diff --git a/devenv.yaml b/devenv.yaml new file mode 100644 index 0000000..7e204f4 --- /dev/null +++ b/devenv.yaml @@ -0,0 +1,8 @@ +inputs: + rust-overlay: + url: github:oxalica/rust-overlay + inputs: + nixpkgs: + follows: nixpkgs + nixpkgs: + url: github:cachix/devenv-nixpkgs/rolling diff --git a/docker/compose.dev.yml b/docker/compose.dev.yml deleted file mode 100644 index 38bdad1..0000000 --- a/docker/compose.dev.yml +++ /dev/null @@ -1,33 +0,0 @@ -services: - db: - image: postgres:16-alpine - restart: unless-stopped - container_name: georm-backend-db - environment: - POSTGRES_PASSWORD: ${DB_PASSWORD} - POSTGRES_USER: ${DB_USER} - POSTGRES_DB: ${DB_NAME} - ports: - - 127.0.0.1:5432:5432 - volumes: - - georm_backend_db_data:/var/lib/postgresql/data - - pgadmin: - image: dpage/pgadmin4:8 - restart: unless-stopped - container_name: georm-backend-pgadmin - environment: - PGADMIN_DEFAULT_EMAIL: admin@example.com - PGADMIN_DEFAULT_PASSWORD: password - PGADMIN_DISABLE_POSTFIX: true - PGADMIN_CONFIG_SERVER_MODE: 'False' - ports: - - 127.0.0.1:8080:80 - volumes: - - georm_backend_pgadmin_data:/var/lib/pgadmin - depends_on: - - db - -volumes: - georm_backend_db_data: - georm_backend_pgadmin_data: diff --git a/docker/mod.just b/docker/mod.just deleted file mode 100644 index db4d08b..0000000 --- a/docker/mod.just +++ /dev/null @@ -1,14 +0,0 @@ -default: start - -start: - docker compose -f compose.dev.yml up -d - -stop: - docker compose -f compose.dev.yml down - -logs: - docker compose -f compose.dev.yml logs -f - -## Local Variables: -## mode: makefile -## End: \ No newline at end of file diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 265e37c..0000000 --- a/flake.lock +++ /dev/null @@ -1,96 +0,0 @@ -{ - "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1738142207, - "narHash": "sha256-NGqpVVxNAHwIicXpgaVqJEJWeyqzoQJ9oc8lnK9+WC4=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "9d3ae807ebd2981d593cddd0080856873139aa40", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1736320768, - "narHash": "sha256-nIYdTAiKIGnFNugbomgBJR+Xv5F1ZQU+HfaBqJKroC0=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "4bc9c909d9ac828a039f288cf872d16d38185db8", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" - } - }, - "rust-overlay": { - "inputs": { - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1738290352, - "narHash": "sha256-YKOHUmc0Clm4tMV8grnxYL4IIwtjTayoq/3nqk0QM7k=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "b031b584125d33d23a0182f91ddbaf3ab4880236", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix deleted file mode 100644 index b00068c..0000000 --- a/flake.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ - description = "Georm, a simple, opiniated SQLx ORM for PostgreSQL"; - - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; - rust-overlay.url = "github:oxalica/rust-overlay"; - }; - - outputs = { self, nixpkgs, flake-utils, rust-overlay }: - flake-utils.lib.eachSystem ["x86_64-linux"] (system: - let - overlays = [ (import rust-overlay) ]; - pkgs = import nixpkgs { inherit system overlays; }; - rustVersion = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml); - in { - devShell = with pkgs; mkShell { - buildInputs = [ - bacon - cargo-deny - just - rust-analyzer - (rustVersion.override { - extensions = [ - "rust-src" - "rustfmt" - "clippy" - "rust-analyzer" - ]; - }) - sqls - sqlx-cli - ]; - }; - }); -} diff --git a/justfile b/justfile index 51b4ed5..85f5a3d 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,3 @@ -mod docker - default: lint clean: