Skip to content

Add static and computed environment variables - #2

Closed
lucperkins wants to merge 4 commits into
mainfrom
env-vars
Closed

lucperkins wants to merge 4 commits into
mainfrom
env-vars

Conversation

@lucperkins

@lucperkins lucperkins commented Apr 10, 2026 •

Copy link
Copy Markdown
Member

Static:

{
  staticEnvVars.postgres = {
    PGDATA = ".state/postgres";
    PGDATABASE = "testing";
    PGHOST = "127.0.0.1";
    PGPORT = toString 5432;
  };
}

Computed:

{
  computedEnvVars = forEachSupportedSystem (
    { pkgs, system }:
    {
      postgres = {
        PGSSLCERT = "${pkgs.postgresql}/share/postgresql/root.crt";
      };
    }
);

Summary by CodeRabbit

  • Documentation

    • Added comprehensive docs for environment variable sets, explaining static and computed variants with practical Nix examples.
  • New Features

    • Distinct support for static and per-system computed environment variable sets.
    • Developer shells now expose computed environment values and process environments are composed from the new static + computed sets for clearer configuration management.

@coderabbitai

coderabbitai Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Updated README docs to use updated flake schema example and added "Environment variable sets" (static vs computed). Flake outputs changed: added staticEnvVars.postgres, per-system computedEnvVars.${system}.openssl, expose computed env in devShells, renamed a process tree to postgres, and split schemas.envVars into schemas.staticEnvVars and schemas.computedEnvVars.

Changes

Cohort / File(s) Summary
Documentation
README.md
Replaced inherit (inputs.up) schemas example with schemas = inputs.up.exportedSchemas // { ... }; added "Environment variable sets" section describing static and computed types and Nix examples (staticEnvVars.postgres, computedEnvVars = forEachSupportedSystem (...)).
Flake configuration
flake.nix
Added staticEnvVars.postgres; introduced computedEnvVars.${system}.openssl and wired it into devShells.${system}.default.env; renamed processTrees.${system}.data → processTrees.${system}.postgres and added openssl to packages; changed environment composition to self.staticEnvVars.postgres // self.computedEnvVars.${system}.openssl; split schemas.envVars into schemas.staticEnvVars and schemas.computedEnvVars (with appendSystem = true) and added exportedSchemas output and inventory construction.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Use secure packages fh#199: Overlaps in modifying the flake outputs/devShells surface and exported per-system attributes.
  • DeterminateSystems/inspect-system#1: Alters per-system devShell/output generation patterns similar to the computedEnvVars and per-system wiring here.
  • Add flake template for flake schemas flake-templates#15: Related changes to exposing and merging schema outputs via exportedSchemas and input-extension patterns.

Poem

🐰 I nibble schemas, static and new,
Postgres carrots, openssl dew,
Per-system paths I hop and trace,
Dev shells dressed for every case,
A little hop of config joy and chew 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely captures the main change: introducing support for both static and computed environment variables, which is the primary focus of the PR as evidenced by the new staticEnvVars and computedEnvVars attributes and their documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch env-vars

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@flake.nix`:
- Around line 245-255: The computedEnvVars branch calls builtins.attrValues(env)
inside evalChecks.allStrings which can throw on malformed entries before
evalChecks.isAttrs runs; change evalChecks.allStrings so it first checks that
env is an attrset (the same guard logic used for staticEnvVars, e.g. using
evalChecks.isAttrs or the isEnv helper) and only then computes
builtins.attrValues(env) to run the all-strings check, so malformed entries
produce the clean schema error instead of an early exception.

In `@README.md`:
- Around line 174-184: The README example shows
computedEnvVars.${system}.postgres.PGSSLCERT but the actual flake.nix exposes
computedEnvVars.${system}.openssl with OPENSSL_* variables; update the example
to match the flake output by replacing the postgres/PGSSLCERT example with the
openssl entry (computedEnvVars = ... openssl = { OPENSSL_CERT = "..."; ... }) or
otherwise document the openssl key and OPENSSL_* variable names so readers see
the real computedEnvVars.${system}.openssl outputs from flake.nix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 05214cb5-d96e-49fc-b8ab-4370ceaba14c

📥 Commits

Reviewing files that changed from the base of the PR and between 2e23add and fad8999.

📒 Files selected for processing (2)
  • README.md
  • flake.nix

Comment thread flake.nix
Comment thread README.md
Comment on lines +174 to +184
Computed sets are system specific and may be based on things like packages in Nixpkgs:

```nix
computedEnvVars = forEachSupportedSystem (
{ pkgs, system }:
{
postgres = {
PGSSLCERT = "${pkgs.postgresql}/share/postgresql/root.crt";
};
}
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Keep the computed example aligned with the actual flake output.

flake.nix exposes computedEnvVars.${system}.openssl with OPENSSL_* values, but this example documents computedEnvVars.${system}.postgres.PGSSLCERT. As written, readers will look for an output that does not exist.

📝 Proposed doc fix
 computedEnvVars = forEachSupportedSystem (
   { pkgs, system }:
   {
-    postgres = {
-      PGSSLCERT = "${pkgs.postgresql}/share/postgresql/root.crt";
+    openssl = {
+      OPENSSL_DIR = "${pkgs.openssl.dev}";
+      OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
+      OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include";
     };
   }
 );
🧰 Tools
🪛 LanguageTool

[grammar] ~174-~174: Use a hyphen to join words.
Context: ...32; }; } ``` Computed sets are system specific and may be based on things like...

(QB_NEW_EN_HYPHEN)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` around lines 174 - 184, The README example shows
computedEnvVars.${system}.postgres.PGSSLCERT but the actual flake.nix exposes
computedEnvVars.${system}.openssl with OPENSSL_* variables; update the example
to match the flake output by replacing the postgres/PGSSLCERT example with the
openssl entry (computedEnvVars = ... openssl = { OPENSSL_CERT = "..."; ... }) or
otherwise document the openssl key and OPENSSL_* variable names so readers see
the real computedEnvVars.${system}.openssl outputs from flake.nix.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
flake.nix (1)

224-224: Deduplicate isEnv helper across schema blocks.

isEnv is defined twice with identical logic. Consider hoisting it once in the surrounding schemas scope to reduce drift risk.

♻️ Suggested refactor
-      schemas = {
+      schemas = {
         inherit (inputs.flake-schemas.schemas)
           devShells
           formatter
           overlays
           schemas
           ;
-      }
-      // {
+      }
+      // let
+        isEnv = v: builtins.isAttrs v && builtins.all (s: builtins.isString s) (builtins.attrValues v);
+      in {
@@
         staticEnvVars = {
@@
           inventory =
             output:
-            let
-              isEnv = v: builtins.isAttrs v && builtins.all (s: builtins.isString s) (builtins.attrValues v);
-            in
             inputs.flake-schemas.lib.mkChildren (
@@
         computedEnvVars = {
@@
           inventory =
             output:
-            let
-              isEnv = v: builtins.isAttrs v && builtins.all (s: builtins.isString s) (builtins.attrValues v);
-            in
             inputs.flake-schemas.lib.mkChildren (

Also applies to: 246-246

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@flake.nix` at line 224, The helper function isEnv is duplicated in two schema
blocks; hoist a single definition up into the surrounding schemas scope and
remove the duplicate definitions inside the individual schema blocks so both
blocks reference the same isEnv symbol. Locate the existing isEnv definitions
(the isEnv = v: builtins.isAttrs v && builtins.all (s: builtins.isString s)
(builtins.attrValues v) occurrences), move one copy into the parent schemas
scope (above the per-schema blocks), and replace the per-schema copies with
references to that hoisted isEnv to avoid drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@flake.nix`:
- Line 224: The helper function isEnv is duplicated in two schema blocks; hoist
a single definition up into the surrounding schemas scope and remove the
duplicate definitions inside the individual schema blocks so both blocks
reference the same isEnv symbol. Locate the existing isEnv definitions (the
isEnv = v: builtins.isAttrs v && builtins.all (s: builtins.isString s)
(builtins.attrValues v) occurrences), move one copy into the parent schemas
scope (above the per-schema blocks), and replace the per-schema copies with
references to that hoisted isEnv to avoid drift.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5eceffdc-72ae-4026-b03e-6b6dd5667504

📥 Commits

Reviewing files that changed from the base of the PR and between fad8999 and e459b6d.

📒 Files selected for processing (1)
  • flake.nix

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Line 176: Change the phrase "system specific" to the hyphenated compound
adjective "system-specific" in the README text (the sentence starting "Computed
sets are system specific and may be based on things like packages in Nixpkgs:")
so the prose uses correct hyphenation for a compound modifier.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 54961ee9-f252-4a9e-922a-62a490656f57

📥 Commits

Reviewing files that changed from the base of the PR and between e459b6d and 853a6a9.

📒 Files selected for processing (2)
  • README.md
  • flake.nix
🚧 Files skipped from review as they are similar to previous changes (1)
  • flake.nix

Comment thread README.md
}
```

Computed sets are system specific and may be based on things like packages in Nixpkgs:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Hyphenate compound adjective in prose.

Use “system-specific” on Line 176 for correct style.

🧰 Tools
🪛 LanguageTool

[grammar] ~176-~176: Use a hyphen to join words.
Context: ...32; }; } ``` Computed sets are system specific and may be based on things like...

(QB_NEW_EN_HYPHEN)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 176, Change the phrase "system specific" to the hyphenated
compound adjective "system-specific" in the README text (the sentence starting
"Computed sets are system specific and may be based on things like packages in
Nixpkgs:") so the prose uses correct hyphenation for a compound modifier.

@lucperkins

Copy link
Copy Markdown
Member Author

Superseded by #5

@lucperkins lucperkins closed this Apr 17, 2026
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

Successfully merging this pull request may close these issues.

1 participant