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
55 changes: 40 additions & 15 deletions overview/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -240,34 +240,43 @@ let
<article class="page-width">
${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)}
</article>
'';

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 = [
Expand All @@ -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"
)}

<ol>
<li>
<strong>Install Nix</strong>
Expand Down Expand Up @@ -323,10 +335,17 @@ let
<pre><code>nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/$rev.tar.gz --packages nix --run "nix-build ./default.nix && ./result"</code></pre>
</ul>
</li>
<li>
<strong>Access the service</strong><br />
Open a web browser at <a href="http://localhost:${toString servicePort}">http://localhost:${toString servicePort}</a> .
</li>
${
if servicePort != "" then
''
<li>
<strong>Access the service</strong><br />
Open a web browser at <a href="http://localhost:${toString servicePort}">http://localhost:${toString servicePort}</a> .
</li>
''
else
""
}
</ol>
'';
};
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions projects/mitmproxy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ ... }:
{
programs.mitmproxy.enable = true;
}