From 47e279ece7c0f07fdc669407bd124ebd55adccb9 Mon Sep 17 00:00:00 2001 From: themadbit Date: Thu, 5 Jun 2025 19:45:23 +0300 Subject: [PATCH] modularize NIX_CONFIG --- overview/content-types/config-item.nix | 20 ++++++++++++++++++ overview/content-types/nix-config.nix | 29 ++++++++++++++++++++++++++ overview/default.nix | 21 ++++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 overview/content-types/config-item.nix create mode 100644 overview/content-types/nix-config.nix diff --git a/overview/content-types/config-item.nix b/overview/content-types/config-item.nix new file mode 100644 index 000000000..bd05b68a7 --- /dev/null +++ b/overview/content-types/config-item.nix @@ -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); + }; + }; +} diff --git a/overview/content-types/nix-config.nix b/overview/content-types/nix-config.nix new file mode 100644 index 000000000..726d1126c --- /dev/null +++ b/overview/content-types/nix-config.nix @@ -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); + }; + }; +} diff --git a/overview/default.nix b/overview/default.nix index 869a410e2..e227e234a 100644 --- a/overview/default.nix +++ b/overview/default.nix @@ -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"} @@ -291,7 +310,7 @@ let
  • Enable binary substituters -
    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='
    +
    ${nix-config}
    export NIX_CONFIG