Skip to content

Inline bash scripts in Nix #1563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
steve-chavez opened this issue Apr 21, 2025 · 1 comment
Open

Inline bash scripts in Nix #1563

steve-chavez opened this issue Apr 21, 2025 · 1 comment

Comments

@steve-chavez
Copy link
Member

Problem

There are various cases where bash scripts are source from within Nix and then they have their variables replaced with substitute:

  • postgres/flake.nix

    Lines 498 to 510 in 61ff753

    pkgs.runCommand "start-postgres-client" { } ''
    mkdir -p $out/bin
    substitute ${./nix/tools/run-client.sh.in} $out/bin/start-postgres-client \
    --subst-var-by 'PGSQL_DEFAULT_PORT' '${pgsqlDefaultPort}' \
    --subst-var-by 'PGSQL_SUPERUSER' '${pgsqlSuperuser}' \
    --subst-var-by 'PSQL15_BINDIR' '${basePackages.psql_15.bin}' \
    --subst-var-by 'PSQL17_BINDIR' '${basePackages.psql_17.bin}' \
    --subst-var-by 'PSQLORIOLEDB17_BINDIR' '${basePackages.psql_orioledb-17.bin}' \
    --subst-var-by 'MIGRATIONS_DIR' '${migrationsDir}' \
    --subst-var-by 'POSTGRESQL_SCHEMA_SQL' '${postgresqlSchemaSql}' \
    --subst-var-by 'PGBOUNCER_AUTH_SCHEMA_SQL' '${pgbouncerAuthSchemaSql}' \
    --subst-var-by 'STAT_EXTENSION_SQL' '${statExtensionSql}'
    chmod +x $out/bin/start-postgres-client

  • postgres/flake.nix

    Lines 523 to 528 in 61ff753

    substitute ${./nix/tools/migrate-tool.sh.in} $out/bin/migrate-postgres \
    --subst-var-by 'PSQL15_BINDIR' '${basePackages.psql_15.bin}' \
    --subst-var-by 'PSQL_CONF_FILE' '${configFile}' \
    --subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}' \
    --subst-var-by 'PRIMING_SCRIPT' '${primingScript}' \
    --subst-var-by 'MIGRATION_DATA' '${migrationData}'

  • postgres/flake.nix

    Lines 535 to 537 in 61ff753

    substitute ${./nix/tools/run-replica.sh.in} $out/bin/start-postgres-replica \
    --subst-var-by 'PGSQL_SUPERUSER' '${pgsqlSuperuser}' \
    --subst-var-by 'PSQL15_BINDIR' '${basePackages.psql_15.bin}'

This hurts reusability of the scripts logic and adds verboseness to the scripts.

Solution

Inline the scripts in the Nix file to avoid substitutions.

@steve-chavez steve-chavez added the bug Something isn't working label Apr 21, 2025
@steve-chavez steve-chavez removed the bug Something isn't working label Apr 21, 2025
@samrose
Copy link
Collaborator

samrose commented Apr 28, 2025

#1564 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants