From 429a57d89a6725aa7d4155ba3ae75a397f6e47e3 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 11 Mar 2024 15:38:29 +0100 Subject: [PATCH] Use process-compose directly --- .gitignore | 1 + dev.sh | 59 +++++++++++++++++++++++++++--------------------------- flake.nix | 9 +++++---- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 649acf8..3d92d81 100644 --- a/.gitignore +++ b/.gitignore @@ -182,3 +182,4 @@ db_data /result /static/ /.devenv/ +/process-compose.yml diff --git a/dev.sh b/dev.sh index 117fe2a..313116b 100755 --- a/dev.sh +++ b/dev.sh @@ -6,9 +6,30 @@ _init() { python ./src/manage.py loaddata src/network_inventory.yaml } +_open_url() { + if [[ ! -z "${DEFAULT_BROWSER}" ]]; then + $DEFAULT_BROWSER $url + elif type explorer.exe &>/dev/null; then + explorer.exe $url + fi +} + +_create_url() { + if [ -f /etc/wsl.conf ]; then + echo "http://localhost:$WEBPORT" + else + echo "http://$(hostname -f):$WEBPORT" + fi +} +#} + +# Main tasks start +declare -A tasks +declare -A descriptions + # Setup the database -_setup() { - sleep 5 +setup() { + find . -name __pycache__ -o -name "*.pyc" -delete if [ -f .direnv/first_run ]; then python ./src/manage.py collectstatic --noinput python ./src/manage.py makemigrations @@ -36,35 +57,15 @@ _setup() { _init touch .direnv/first_run fi -} - -_open_url() { - if [[ ! -z "${DEFAULT_BROWSER}" ]]; then - $DEFAULT_BROWSER $url - elif type explorer.exe &>/dev/null; then - explorer.exe $url - fi -} - -_create_url() { - if [ -f /etc/wsl.conf ]; then - echo "http://localhost:$WEBPORT" - else - echo "http://$(hostname -f):$WEBPORT" - fi -} -#} - -# Main tasks start -declare -A tasks -declare -A descriptions - -run() { - _setup - find . -name __pycache__ -o -name "*.pyc" -delete url=$(_create_url) printf "\n---\n webserver: $url\n---\n" - _open_url $url + _open_url $url sleep 5 +} +descriptions["setup"]="Setup the database and load example data." +tasks["setup"]=setup + +run() { + process-compose up } descriptions["run"]="Start the webserver." tasks["run"]=run diff --git a/flake.nix b/flake.nix index 14b5d16..3693b36 100644 --- a/flake.nix +++ b/flake.nix @@ -15,9 +15,6 @@ forEachSystem = nixpkgs.lib.genAttrs (import systems); in { - packages = forEachSystem (system: { - devenv-up = self.devShells.${system}.default.config.procfileScript; - }); devShells = forEachSystem (system: let @@ -30,6 +27,10 @@ { packages = [ (pkgs.writeScriptBin "dev" "${builtins.readFile ./dev.sh}") + config = self.devShells.${system}.default.config; + enterShell = '' + ln -sf ${config.process-managers.process-compose.configFile} ${config.env.DEVENV_ROOT}/process-compose.yml + ''; ]; env = { DJANGO_SETTINGS_MODULE = "network_inventory.settings.local"; @@ -55,7 +56,7 @@ # https://github.com/cachix/devenv/blob/main/examples/process-compose/devenv.nix processes = { webserver.exec = "poetry run python ./src/manage.py runserver 0.0.0.0:$WEBPORT"; - setup.exec = "dev start"; + setup.exec = "dev setup"; }; services.postgres = { enable = true;