diff --git a/.envrc b/.envrc index 3550a30..cffc922 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use flake +use flake . --impure diff --git a/.gitignore b/.gitignore index 6615d35..26aa54a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /target/ -/.db/ /.vagrant/ /.direnv/ +/.devenv/ /deps/ /_build/ /priv/static/assets/ diff --git a/flake.lock b/flake.lock index d585acb..a1c6401 100644 --- a/flake.lock +++ b/flake.lock @@ -20,10 +20,65 @@ "type": "github" } }, + "devenv": { + "inputs": { + "flake-compat": "flake-compat", + "nix": "nix", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1706918346, + "narHash": "sha256-UYbmL0db7+yQNpQ3nyW5077kmtB3fT/M0h/LhosODm4=", + "owner": "cachix", + "repo": "devenv", + "rev": "e4019e17e9818cc3f107cef515d23d255e43e29a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, "locked": { "lastModified": 1701680307, "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", @@ -38,7 +93,117 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "lowdown-src": { + "flake": false, + "locked": { + "lastModified": 1633514407, + "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=", + "owner": "kristapsdz", + "repo": "lowdown", + "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8", + "type": "github" + }, + "original": { + "owner": "kristapsdz", + "repo": "lowdown", + "type": "github" + } + }, + "nix": { + "inputs": { + "lowdown-src": "lowdown-src", + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-regression": "nixpkgs-regression" + }, + "locked": { + "lastModified": 1676545802, + "narHash": "sha256-EK4rZ+Hd5hsvXnzSzk2ikhStJnD63odF7SzsQ8CuSPU=", + "owner": "domenkozar", + "repo": "nix", + "rev": "7c91803598ffbcfe4a55c44ac6d49b2cf07a527f", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "relaxed-flakes", + "repo": "nix", + "type": "github" + } + }, "nixpkgs": { + "locked": { + "lastModified": 1678875422, + "narHash": "sha256-T3o6NcQPwXjxJMn2shz86Chch4ljXgZn746c2caGxd8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "126f49a01de5b7e35a43fd43f891ecf6d3a51459", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1703134684, "narHash": "sha256-SQmng1EnBFLzS7WSRyPM9HgmZP2kLJcPAz+Ug/nug6o=", @@ -54,11 +219,40 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1704725188, + "narHash": "sha256-qq8NbkhRZF1vVYQFt1s8Mbgo8knj+83+QlL5LBnYGpI=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ea96f0c05924341c551a797aaba8126334c505d2", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "crane": "crane", - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", + "devenv": "devenv", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2", "rust-overlay": "rust-overlay" } }, @@ -99,6 +293,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "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", diff --git a/flake.nix b/flake.nix index 350b06b..cd17ad5 100644 --- a/flake.nix +++ b/flake.nix @@ -1,8 +1,14 @@ { description = "Prymn"; + nixConfig = { + extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; + extra-substituters = "https://devenv.cachix.org"; + }; + inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + devenv.url = "github:cachix/devenv"; flake-utils.url = "github:numtide/flake-utils"; rust-overlay = { url = "github:oxalica/rust-overlay"; @@ -17,26 +23,44 @@ }; }; - outputs = { self, nixpkgs, flake-utils, rust-overlay, crane }: + outputs = { self, nixpkgs, devenv, flake-utils, rust-overlay, crane }@inputs: flake-utils.lib.eachDefaultSystem (system: let overlays = [ (import ./nix/overlay.nix) (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; - scripts = pkgs.callPackage ./nix/scripts.nix { }; rustBuilder = import ./nix/rust.nix { inherit crane pkgs system; }; in { - devShells.default = with pkgs; mkShell { - packages = [ - elixir - elixir-ls - rustToolchain - scripts.prymn_db - ] ++ lib.optionals stdenv.isLinux [ inotify-tools ]; + packages = { + devenv-up = self.devShells.${system}.default.config.procfileScript; + }; - shellHook = '' - export PROJECT_ROOT_DIR="$PWD" - ''; + devShells.default = devenv.lib.mkShell { + inherit pkgs inputs; + + modules = [ + ({ pkgs, config, ... }: { + packages = [ + pkgs.elixir + pkgs.elixir-ls + pkgs.rustToolchain + pkgs.natscli + ] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.inotify-tools ]; + + services.postgres = { + enable = true; + package = pkgs.postgresql_16; + initialDatabases = [{ name = "prymn_dev"; }]; + initialScript = "CREATE USER postgres SUPERUSER;"; + }; + + processes.nats-server.exec = "${pkgs.nats-server}/bin/nats-server -c ./agent/server.conf"; + + enterShell = '' + echo happy deving + ''; + }) + ]; }; checks.rustTest = rustBuilder.test; diff --git a/nix/scripts.nix b/nix/scripts.nix deleted file mode 100644 index d83d63f..0000000 --- a/nix/scripts.nix +++ /dev/null @@ -1,47 +0,0 @@ -{ writeShellApplication, postgresql, ... }: - -{ - prymn_db = writeShellApplication { - name = "prymn_db"; - - runtimeInputs = [ postgresql ]; - - text = '' - #!/usr/bin/env bash - - set -e - - export PGDATA=$PROJECT_ROOT_DIR/.db - export PGHOST=/tmp - export DB_LOG=$PROJECT_ROOT_DIR/.db/log - - start_db() { - if [ ! -d "$PGDATA" ]; then - initdb "$PGDATA" --auth=trust - fi - - if ! pg_ctl status >/dev/null; then - pg_ctl start -l "$DB_LOG" -o "-c unix_socket_directories=$PGHOST" - echo "starting your dev database..." - fi - - user_exists=$(psql --csv -t -d postgres -c "SELECT count(*) FROM pg_user WHERE usename='postgres'") - if [ "$user_exists" != "1" ]; then - createuser -s -h "$PGHOST" postgres - fi - } - - command="''${1-default}" - case $command in - shell) - psql -U postgres - exit 0 - ;; - start | default | *) - start_db - exit 0 - ;; - esac - ''; - }; -}