Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ The flake schemas are also helpful:

```text
{
inherit (inputs.up) schemas;
schemas = inputs.up.exportedSchemas // {
# other schemas
};
}
```

Expand Down Expand Up @@ -154,3 +156,32 @@ To run it:
```shell
nix run ".#taskRunners.<system>.default"
```

## Environment variable sets

There are two types of environment variable sets: **static** and **computed**.
Static sets are attribute sets of strings:

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

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.


```nix
computedEnvVars = forEachSupportedSystem (
{ pkgs, system }:
{
postgres = {
PGSSLCERT = "${pkgs.postgresql}/share/postgresql/root.crt";
};
}
);
Comment on lines +176 to +186

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.

```
103 changes: 79 additions & 24 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
shellHook = ''
${self.taskRunners.${system}.default.shellHook}
'';

env = self.computedEnvVars.${system}.openssl;
};
}
);
Expand All @@ -54,23 +56,37 @@

lib = import ./nix/lib.nix { inherit lib; };

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

computedEnvVars = forEachSupportedSystem (
{ pkgs, system }:
{
openssl = {
OPENSSL_DIR = "${pkgs.openssl.dev}";
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include";
};
}
);

processTrees = forEachSupportedSystem (
{ pkgs, system }:
{
data = pkgs.lib.mkProcessTree {
postgres = pkgs.lib.mkProcessTree {
description = "Run Postgres locally";

packages = with pkgs; [
(postgresql_18.withPackages (p: with p; [ pg_uuidv7 ]))
openssl
redis
];

environment = {
PGDATA = ".state/postgres";
PGDATABASE = "testing";
PGHOST = "127.0.0.1";
PGPORT = "5432";
};
environment = self.staticEnvVars.postgres // self.computedEnvVars.${system}.openssl;

processes = {
postgres-setup = {
Expand Down Expand Up @@ -174,7 +190,32 @@
schemas
;
}
// {
// self.exportedSchemas;

exportedSchemas = {
exportedSchemas = {
version = 1;
doc = ''
The `exportedSchemas` flake output is used to define flake schemas that you
intend for other flakes to use.
'';

inventory =
output:
inputs.flake-schemas.lib.mkChildren (
builtins.mapAttrs (schemaName: schemaDef: {
shortDescription = "A schema checker for the `${schemaName}` flake output";
evalChecks.isValidSchema =
schemaDef.version or 0 == 1
&& schemaDef ? doc
&& builtins.isString (schemaDef.doc)
&& schemaDef ? inventory
&& builtins.isFunction (schemaDef.inventory);
what = "flake schema";
}) output
);
};

taskRunners = {
version = 1;
doc = ''
Expand All @@ -196,35 +237,49 @@
);
};

envVars = {
staticEnvVars = {
version = 1;
doc = ''
The `envVars` output provides sets of environment variables
The `staticEnvVars` output provides sets of environment variables
that can be sourced into shells or consumed by other tools.
'';
inventory =
output:
let
isEnv = v: builtins.isAttrs v && builtins.all (s: builtins.isString s) (builtins.attrValues v);
isPerSystem = builtins.all (v: builtins.isAttrs v && !isEnv v) (builtins.attrValues output);
in
inputs.flake-schemas.lib.mkChildren (
if isPerSystem then
builtins.mapAttrs (system: envs: {
builtins.mapAttrs (_name: env: {
evalChecks.isAttrs = builtins.isAttrs env;
evalChecks.allStrings = isEnv env;
what = "environment variables set";
}) output
);
};

computedEnvVars = {
version = 1;
doc = ''
The `computedEnvVars` output provides sets of environment variables
that can be sourced into shells or consumed by other tools. Unlike `staticEnvVars`, these
sets are system specific and involve some kind of computation (like using packages from Nixpkgs).
'';
appendSystem = true;
inventory =
output:
let
isEnv = v: builtins.isAttrs v && builtins.all (s: builtins.isString s) (builtins.attrValues v);
in
inputs.flake-schemas.lib.mkChildren (
builtins.mapAttrs (system: envs: {
forSystems = [ system ];
children = builtins.mapAttrs (_name: env: {
forSystems = [ system ];
children = builtins.mapAttrs (_name: env: {
forSystems = [ system ];
evalChecks.isAttrs = builtins.isAttrs env;
evalChecks.allStrings = isEnv env;
what = "environment variable set";
}) envs;
}) output
else
builtins.mapAttrs (_name: env: {
evalChecks.isAttrs = builtins.isAttrs env;
evalChecks.allStrings = isEnv env;
what = "environment variables set";
}) output
what = "computed environment variable set";
}) envs;
}) output
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};

Expand Down