diff --git a/overview/default.nix b/overview/default.nix index b6af9fc74..c5a484708 100644 --- a/overview/default.nix +++ b/overview/default.nix @@ -240,34 +240,43 @@ let
${heading 1 null name} ${render.metadata.one project.metadata} - ${render.options.many (pick.options project)} - ${render.examples.many (pick.examples project)} ${optionalString (project.nixos.examples ? demo) ( - render.serviceDemo.one project.nixos.modules.services project.nixos.examples.demo + render.serviceDemo.one "vm" project.nixos.modules project.nixos.examples.demo + )} + ${optionalString (project.nixos.examples ? demo-shell) ( + render.serviceDemo.one "shell" project.nixos.modules project.nixos.examples.demo-shell )} + ${render.options.many (pick.options project)} + ${render.examples.many (pick.examples project)}
''; - demoGlue.one = exampleText: '' + demoGlue.one = demo-function: exampleText: '' # default.nix { ngipkgs ? import (fetchTarball "https://github.com/ngi-nix/ngipkgs/tarball/main") { }, }: - ngipkgs.demo-vm ( + ngipkgs.${demo-function} ( ${toString (intersperse "\n " (splitString "\n" exampleText))} ) ''; serviceDemo.one = - services: example: + type: modules: example: let demoSystem = import (nixpkgs + "/nixos/lib/eval-config.nix") { inherit system; - modules = (attrValues services) ++ [ example.module ]; + modules = + [ + example.module + ./demo/shell.nix + ] + ++ (attrValues modules.services) + ++ (attrValues modules.programs); }; 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); + servicePort = if openPorts != [ ] then (builtins.head openPorts) else ""; nix-config = eval { imports = [ ./content-types/nix-config.nix ]; settings = [ @@ -289,7 +298,10 @@ let }; in '' - ${heading 2 "demo" "Try the service in a VM"} + ${heading 2 "demo" ( + if type == "shell" then "Try the program in a shell" else "Try the service in a VM" + )} +
  1. Install Nix @@ -323,10 +335,17 @@ let
    nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/$rev.tar.gz --packages nix --run "nix-build ./default.nix && ./result"
  2. -
  3. - Access the service
    - Open a web browser at http://localhost:${toString servicePort} . -
  4. + ${ + if servicePort != "" then + '' +
  5. + Access the service
    + Open a web browser at http://localhost:${toString servicePort} . +
  6. + '' + else + "" + }
''; }; @@ -340,7 +359,13 @@ let summary = project.metadata.summary or null; demoFile = if project.nixos.examples ? demo then - (pkgs.writeText "default.nix" (render.demoGlue.one (readFile project.nixos.examples.demo.module))) + (pkgs.writeText "default.nix" ( + render.demoGlue.one "demo-vm" (readFile project.nixos.examples.demo.module) + )) + else if project.nixos.examples ? demo-shell then + (pkgs.writeText "default.nix" ( + render.demoGlue.one "demo-shell" (readFile project.nixos.examples.demo-shell.module) + )) else null; } @@ -355,7 +380,7 @@ let deliverables = { service = project.nixos.modules ? services && project.nixos.modules.services != { }; program = project.nixos.modules ? programs && project.nixos.modules.programs != { }; - demo = project.nixos.examples ? demo; + demo = project.nixos.examples ? demo || project.nixos.examples ? demo-shell; }; }) projects; inherit version; diff --git a/projects/mitmproxy/default.nix b/projects/mitmproxy/default.nix index d08758286..91608e1a5 100644 --- a/projects/mitmproxy/default.nix +++ b/projects/mitmproxy/default.nix @@ -15,10 +15,10 @@ nixos.modules.programs = { mitmproxy = { module = ./module.nix; - examples.basic = { - module = ./example.nix; + examples.demo-shell = { + module = ./demo.nix; description = ""; - tests.basic = null; + tests.demo = null; }; }; }; diff --git a/projects/mitmproxy/example.nix b/projects/mitmproxy/demo.nix similarity index 81% rename from projects/mitmproxy/example.nix rename to projects/mitmproxy/demo.nix index 4e22388c4..d652ef408 100644 --- a/projects/mitmproxy/example.nix +++ b/projects/mitmproxy/demo.nix @@ -1,3 +1,4 @@ +{ ... }: { programs.mitmproxy.enable = true; }