Skip to content
Merged
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
20 changes: 20 additions & 0 deletions overview/content-types/config-item.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
name,
config,
lib,
...
}:
let
inherit (lib) mkOption types;
in
{
options = {
name = mkOption {
type = types.str;
default = name;
};
value = mkOption {
type = with types; either str (listOf str);
};
};
Comment on lines +11 to +19
Copy link
Copy Markdown
Contributor

@fricklerhandwerk fricklerhandwerk Jun 6, 2025

Choose a reason for hiding this comment

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

The NIX_CONFIG thing is a bit tricky. In the instructions what we really want to show is how to set the environment variable to the right value. This is challenging here because NIX_CONFIG is multiline. A convenient rendering will look differently for different shells. So what this change should really be about is

  • adding a shell-code snippet the modular way
  • encoding how to cleverly render setting a multi-line shell variable for bash

the nix configuration we don't need to re-invent -- it's already a NixOS module option, and we should even be able to re-use its rendering logic to produce a string that Nix will accept (not sure though, haven't looked).

then plug it all together such that it displays correctly in the project detail view.

}
29 changes: 29 additions & 0 deletions overview/content-types/nix-config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
name,
config,
lib,
...
}:
let
inherit (lib) mkOption types;
in
{
options = {
__toString = mkOption {
type = with types; functionTo str;
readOnly = true;
default =
self:
let
separator = "'$'\\n''";
concatSettings = lib.concatStringsSep separator (
lib.map (attrs: "${attrs.name} = ${toString attrs.value}") self.settings
);
in
"NIX_CONFIG='${concatSettings}'";
};
settings = mkOption {
type = with types; listOf (submodule ./config-item.nix);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the submodule definition could be inlined here. I think file granularity still needs to be figured out but for now as a rule of thumb stuff that doesn't have a __toString attr shouldn't live in its own file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually nevermind, just saw what @fricklerhandwerk did in #1092 and it was his idea in the first place, so let's roll with this granularity.

Copy link
Copy Markdown
Contributor

@fricklerhandwerk fricklerhandwerk Jun 6, 2025

Choose a reason for hiding this comment

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

__toString attr shouldn't live in its own file.

It doesn't, but arguably we could have collapsed ./config-item into this module.

};
};
}
21 changes: 20 additions & 1 deletion overview/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,25 @@ let
openPorts = demoSystem.config.networking.firewall.allowedTCPPorts;
# The port that is forwarded to the host so that the user can access the demo service.
servicePort = (builtins.head openPorts);
nix-config = eval {
imports = [ ./content-types/nix-config.nix ];
settings = [
{
name = "substituters";
value = [
"https://cache.nixos.org/"
"https://ngi.cachix.org/"
];
}
{
name = "trusted-public-keys";
value = [
"cache.nixos.org-1:6nchdd59x431o0gwypbmraurkbj16zpmqfgspcdshjy="
"ngi.cachix.org-1:n+cal72roc3qqulxihpv+tw5t42whxmmhpragkrsrow="
];
}
];
};
in
''
${heading 2 "demo" "Try the service in a VM"}
Expand All @@ -291,7 +310,7 @@ let
</li>
<li>
<strong>Enable binary substituters</strong>
<pre><code>NIX_CONFIG='substituters = https://cache.nixos.org/ https://ngi.cachix.org/'$'\n'''trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ngi.cachix.org-1:n+CAL72ROC3qQuLxIHpV+Tw5t42WhXmMhprAGkRSrOw='</code></pre>
<pre><code>${nix-config}</code></pre>
<pre><code>export NIX_CONFIG</code></pre>
</li>
<li>
Expand Down