From fb7d97762a7f09a7721ca11a37901ff88a62673b Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Sat, 16 Mar 2024 10:42:32 +0100 Subject: [PATCH 1/4] examples: rubyonrails: use port 3000 instead of 5100 Rails listens on port 3000 by default. --- examples/rubyonrails/.test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/rubyonrails/.test.sh b/examples/rubyonrails/.test.sh index a055c6b04..1c701bfa9 100755 --- a/examples/rubyonrails/.test.sh +++ b/examples/rubyonrails/.test.sh @@ -2,9 +2,9 @@ set -ex pushd blog - wait_for_port 5100 + wait_for_port 3000 rails db:create - curl -s http://localhost:5100/ | grep "version" + curl -s http://localhost:3000/ | grep "version" popd # make sure puma was compiled with ssl From 055bc43d02e301fb8b10e41bb2e7711de859e862 Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Sat, 16 Mar 2024 10:43:58 +0100 Subject: [PATCH 2/4] examples: rubyonrails: force overwriting any files The test outputted errors regarding upon running `rails new` that `.gitignore` already exists. For the test it doesn't really matter to overwrite these files, so I added `--force`. --- examples/rubyonrails/devenv.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rubyonrails/devenv.nix b/examples/rubyonrails/devenv.nix index 1273110ca..4586b3f9d 100644 --- a/examples/rubyonrails/devenv.nix +++ b/examples/rubyonrails/devenv.nix @@ -16,7 +16,7 @@ enterShell = '' if [ ! -d "blog" ]; then gem install rails - rails new blog -d=postgresql + rails new blog --database=postgresql --force fi export PATH="$DEVENV_ROOT/blog/bin:$PATH" pushd blog From 6ab8ee4545c8dc9bc48324c4724840f03344682e Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Sat, 16 Mar 2024 10:47:20 +0100 Subject: [PATCH 3/4] postgres: support non-alphanumeric usernames Currently postgres fails to create a database because my username contains a `.`. Wrapping the database name in `"` will resolve the problem. I've rewritten the line to use HEREDOC so that we do not have to mess with escaping (from Nix) within escaping (from Bash) within escaping (from psql). Now it only escapes using Nix and psql. --- src/modules/services/postgres.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/services/postgres.nix b/src/modules/services/postgres.nix index 4dfef8c68..847380764 100644 --- a/src/modules/services/postgres.nix +++ b/src/modules/services/postgres.nix @@ -56,7 +56,10 @@ let cfg.initialDatabases) else lib.optionalString cfg.createDatabase '' - echo "CREATE DATABASE ''${USER:-$(id -nu)};" | psql --dbname postgres''; + psql --dbname postgres << EOF + CREATE DATABASE "''${USER:-$(id -nu)}"; + EOF + ''; runInitialScript = if cfg.initialScript != null then From 74364ee1d08295a327a4aa3ad9082d00c0fbdb31 Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Sat, 16 Mar 2024 11:38:41 +0100 Subject: [PATCH 4/4] devenv: avoid rebuild when unrelated sources change Currently whenever the examples are changed, devenv will need to be rebuild. This isn't needed, because the package isn't relying on the examples explicity. Using `builtins.path` was just too much of a hassle (paths are absolute, directory path needs to be match along with sub-files/directories). Regex seemed easier. Regex in Nix uses extended Posix, which is again a bit funky, but maybe less so than doing matching by hand. --- package.nix | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/package.nix b/package.nix index 6a6cf019d..54651a6c5 100644 --- a/package.nix +++ b/package.nix @@ -4,11 +4,12 @@ pkgs.rustPlatform.buildRustPackage { pname = "devenv"; version = "1.0.0"; - src = builtins.path { - path = ./.; - filter = path: type: - path != "Cargo.lock" || path != "Cargo.toml" || path != "src/devenv"; - }; + src = pkgs.lib.sourceByRegex ./. [ + "Cargo.toml" + "Cargo.lock" + "devenv(/\.*)?" + "devenv-run-tests(/\.*)?" + ]; cargoLock = { lockFile = ./Cargo.lock;