From ab56a0b5cc7bd97b35e827d0094ddd54e2642b78 Mon Sep 17 00:00:00 2001 From: valentin gagarin Date: Wed, 13 Nov 2024 15:24:40 +0100 Subject: [PATCH] modularize --- website/content/default.nix | 29 ++++++++ website/content/grants.nix | 29 +++++--- website/content/index.nix | 38 ---------- website/content/nlnet.nix | 12 +++ website/content/nordunet.nix | 12 +++ website/content/oid.nix | 17 +++++ website/content/tweag.nix | 10 +++ website/default.nix | 15 +++- website/site.nix | 71 ------------------ website/structure/default.nix | 136 ++++++++++++++++++++++++++++++++++ 10 files changed, 244 insertions(+), 125 deletions(-) create mode 100644 website/content/default.nix delete mode 100644 website/content/index.nix create mode 100644 website/content/nlnet.nix create mode 100644 website/content/nordunet.nix create mode 100644 website/content/oid.nix create mode 100644 website/content/tweag.nix delete mode 100644 website/site.nix create mode 100644 website/structure/default.nix diff --git a/website/content/default.nix b/website/content/default.nix new file mode 100644 index 0000000..ac271d6 --- /dev/null +++ b/website/content/default.nix @@ -0,0 +1,29 @@ +{ config, ... }: +let + inherit (config) pages; +in +{ + imports = [ + ./grants.nix + ]; + + pages.index = { + title = "Fediversity"; + locations = [ + "index.html" + ]; + description = "Fediversity web site"; + summary = '' + This web site hosts up-to-date information about the the NGI Zero Fediversity project. + ''; + body = '' + # Welcome to the Fediversity project + + # Fediversity grants + + ${pages.grants.summary} + + [Learn more about our grants](${pages.grants}) + ''; + }; +} diff --git a/website/content/grants.nix b/website/content/grants.nix index fb5eb3e..a231b0c 100644 --- a/website/content/grants.nix +++ b/website/content/grants.nix @@ -1,17 +1,22 @@ +{ ... }: { - title = "Grants"; - description = "How to apply for grants as part of the Fediversity Project"; - summary = '' - Fediversity will award 450 000 euro in small to medium-size R&D grants towards solutions that bring the next generation of social networks closer. We are seeking project proposals between 5.000 and 50.000 euro’s — which should get you on your way. - ''; - outPath = "grants.html"; - body = '' - Fediversity invites other people to join this ambitious development effort. It is a vast domain with many more challenges than what any preconceived effort could tackle by itself. This is why we invite your contribution to help us reshape the state of play, and together create an open, trustworthy and reliable internet for all. + pages.grants = { + title = "Grants"; + locations = [ + "grants.html" + ]; + description = "How to apply for grants as part of the Fediversity Project"; + summary = '' + Fediversity will award 450 000 euro in small to medium-size R&D grants towards solutions that bring the next generation of social networks closer. We are seeking project proposals between 5.000 and 50.000 euro’s — which should get you on your way. + ''; + body = '' + Fediversity invites other people to join this ambitious development effort. It is a vast domain with many more challenges than what any preconceived effort could tackle by itself. This is why we invite your contribution to help us reshape the state of play, and together create an open, trustworthy and reliable internet for all. - This is your opportunity to make a real difference. You tell us how your project can help Fediversity go harder, better, faster, stronger. In order to enable you to make such contributions, NLnet will award 450 000 euro in small to medium-size R&D grants towards solutions that bring the next generation of social networks closer. NLnet is seeking project proposals between 5.000 and 50.000 euro’s — which should get you on your way. + This is your opportunity to make a real difference. You tell us how your project can help Fediversity go harder, better, faster, stronger. In order to enable you to make such contributions, NLnet will award 450 000 euro in small to medium-size R&D grants towards solutions that bring the next generation of social networks closer. NLnet is seeking project proposals between 5.000 and 50.000 euro’s — which should get you on your way. - Noteworthy fact: many projects which are to be deployed inside Fediversity were themselves bootstrapped on precisely such a grant from NGI, and now it is your turn. + Noteworthy fact: many projects which are to be deployed inside Fediversity were themselves bootstrapped on precisely such a grant from NGI, and now it is your turn. - For more information on how to apply, check the NLnet website. - ''; + For more information on how to apply, check the NLnet website. + ''; + }; } diff --git a/website/content/index.nix b/website/content/index.nix deleted file mode 100644 index 3fa7fed..0000000 --- a/website/content/index.nix +++ /dev/null @@ -1,38 +0,0 @@ -let - grants = import ./grants.nix; - fediversity = import ./fediversity.nix; - nordunet = import ./nordunet.nix; - oid = import ./oid.nix; - nlnet = import ./nlnet.nix; - tweag = import ./tweag.nix; -in -{ - title = "Fediversity"; - description = "NGI Zero Fediversity"; - outPath = "index.html"; - body = '' - # Welcome to the Fediversity project - - ${fediversity.summary} - - [Learn more about Fediversity](./${fediversity}) - - # Fediversity grants - - ${grants.summary} - - [Learn more about our grants](./${grants}) - - # Consortium - - The Consortium behind the Fediversity project is a cooperation between NLnet, Open Internet Discourse Foundation, NORDUnet and Tweag. - - ${toString (map (partner: '' - ## ${partner.title} - - ${partner.description} - - [Read more about ${partner.title}](./${partner}) - '') [ nlnet oid tweag nordunet ])} - ''; -} diff --git a/website/content/nlnet.nix b/website/content/nlnet.nix new file mode 100644 index 0000000..22e4df8 --- /dev/null +++ b/website/content/nlnet.nix @@ -0,0 +1,12 @@ +{ + title = "NLnet"; + description = '' + NLnet supports organisations and people who contribute to an open internet for all. They fund projects that help fix the internet through open hardware, open software, open standards, open science and open data. + ''; + outPath = "nlnet.html"; + body = '' + The NLnet Foundation supports organisations and people who contribute to an open internet for all. NLnet funds projects that help fix the internet through open hardware, open software, open standards, open science and open data. After its historical contribution to the early internet in Europe in the 1980’s, NLnet has been financially supporting the open internet since 1997. + + NLnet provides grants to free and open source projects between 5.000 and 50.000 euro with the possibility to scale up. Funding is open to anyone: organisations of any type and individuals. Within NGI Fediversity, NLnet facilitates the open calls for third-party funding and contributes to outreach and dissemination. + ''; +} diff --git a/website/content/nordunet.nix b/website/content/nordunet.nix new file mode 100644 index 0000000..2dca5e5 --- /dev/null +++ b/website/content/nordunet.nix @@ -0,0 +1,12 @@ +{ + title = "NORDUnet"; + description = '' + NORDUnet is a collaboration of the National Research and Education Networks of the Nordic countries. + ''; + outPath = "nordunet.html"; + body = '' + NORDUnet connects universities and research institutions across Denmark, Finland, Iceland, Norway, and Sweden. It enables collaboration, data sharing, and access to online resources for academic and research purposes. + + Fun fact: the website of NORDUnet, nordu.net is the oldest still active domain on the internet. + ''; +} diff --git a/website/content/oid.nix b/website/content/oid.nix new file mode 100644 index 0000000..16f1f9f --- /dev/null +++ b/website/content/oid.nix @@ -0,0 +1,17 @@ +{ + title = "Open Internet Discourse Foundation"; + description = '' + The Open Internet Discourse Foundation (OID) is founded on the belief that everyone deserves the freedom to express themselves and use the internet without constraints, and is committed to help build a better internet where individuals can truly be who they are. + ''; + outPath = "oid.html"; + body = '' + The three pillars that are at the core of the OID Foundation: + + OID believes in the fundamental right of individuals to privacy, self-determination, and freedom of expression. + Building sustainably. The OID Foundation believes that the internet is crucial infrastructure for society, and as such, should be build from the perspective that software projects can exist and be maintained for a long time; decades, not years. + Transparancy. The OID Foundation takes the commitment to openness seriously, and strives to use open software in all aspects. + In order to realise our vision, we need a healthy, functional and open internet. This is where OID comes in, working on the infrastructure that powers the internet in a way that promotes it’s values. + + OID Foundation is rooted in constructive optimism, believing in tackling challenges head-on with a positive outlook, viewing each obstacle as an opportunity for improvement. As a practical example of the long-term vision is the work on NixOS that the OID is doing, where the reproducibility and long-term maintainability of NixOS’s package management help with an open and sustainable internet. + ''; +} diff --git a/website/content/tweag.nix b/website/content/tweag.nix new file mode 100644 index 0000000..b8a22a8 --- /dev/null +++ b/website/content/tweag.nix @@ -0,0 +1,10 @@ +{ + title = "Tweag"; + description = '' + Tweag is the open source program office (OSPO) of Modus Create, and has extensive experience working with Nix, and many people at the forefront of the Nix community are Tweagers + ''; + outPath = "tweag.html"; + body = '' + Tweag is the open source program office (OSPO) of Modus Create, a global digital consulting firm that helps enterprises build competitive advantage through digital innovation. Tweagers are leading contributors to several open source projects — from functional programming languages to cross-platform frameworks. Tweag has extensive experience working with Nix, and many people at the forefront of the Nix community are Tweagers. + ''; +} diff --git a/website/default.nix b/website/default.nix index be8a990..96b2a4b 100644 --- a/website/default.nix +++ b/website/default.nix @@ -8,11 +8,18 @@ , lib ? import "${sources.nixpkgs}/lib" , }: -let - site = pkgs.callPackage ./site.nix { }; -in { - build = site.build "fediversity.eu" ./content; + build = + let + result = pkgs.lib.evalModules { + modules = [ + ./structure + ./content + { _module.args = { inherit pkgs; }; } + ]; + }; + in + result.config.build; shell = pkgs.mkShellNoCC { packages = with pkgs; [ diff --git a/website/site.nix b/website/site.nix deleted file mode 100644 index e43da97..0000000 --- a/website/site.nix +++ /dev/null @@ -1,71 +0,0 @@ -{ pkgs, lib, ... }: -let - join = lib.concatStringsSep; -in -rec { - /** - Build the web site - */ - build = name: dir: - let - script = '' - mkdir $out - '' + join "\n" copy; - copy = lib.mapAttrsToList - ( - path: document: '' - mkdir -p $out/$(dirname ${path}) - cp ${document} $out/${path} - '' - ) - (files (sources dir)); - in - pkgs.runCommand name { } script; - - /** - Get source files from a flat directory - */ - sources = dir: lib.mapAttrs' - ( - attrname: value: { - name = lib.removeSuffix ".nix" attrname; - value = import (dir + "/${attrname}"); - } - ) - (builtins.readDir dir); - - /** - Create a mapping from output file path to document contents - */ - files = documents: lib.mapAttrs' - ( - name: document: { - name = document.outPath; - value = html document "${name}.html"; - } - ) - documents; - - /** - Convert a Nix document to HTML - */ - html = document: name: - builtins.toFile "${name}.html" '' - - - ${document.title} - - - ${builtins.readFile (commonmark document.body name)} - - - ''; - - /** - Convert a commonmark string to HTML - */ - commonmark = markdown: name: - pkgs.runCommand "${name}.html" { buildInputs = [ pkgs.cmark ]; } '' - cmark ${builtins.toFile "${name}.md" markdown} > $out - ''; -} diff --git a/website/structure/default.nix b/website/structure/default.nix new file mode 100644 index 0000000..dc7780c --- /dev/null +++ b/website/structure/default.nix @@ -0,0 +1,136 @@ +{ config, options, lib, pkgs, ... }: +let + inherit (lib) + mkOption + types + ; + cfg = config; +in +{ + options.pages = mkOption { + description = '' + Collection of pages on the site + ''; + type = with types; attrsOf (submodule ({ name, config, ... }: + { + options = { + title = mkOption { + type = types.str; + }; + locations = mkOption { + description = '' + List of historic output locations for the resulting file + + The first element is the canonical location. + All other elements are used to create redirects to the canonical location. + ''; + type = with types; nonEmptyListOf str; + }; + outPath = mkOption { + description = '' + Canonical location of the page + ''; + type = types.str; + default = lib.head config.locations; + }; + description = mkOption { + description = '' + One-sentence description of page contents + ''; + type = types.str; + }; + summary = mkOption { + description = '' + One-paragraph summary of page contents + ''; + type = types.str; + }; + body = mkOption { + description = '' + Page contents in CommonMark + ''; + type = types.str; + }; + template = mkOption + { + description = '' + Function that converts the page contents to files + ''; + type = with types; functionTo (functionTo (functionTo options.files.type)); + default = cfg.templates.default; + }; + }; + })); + }; + + options.templates = mkOption { + description = '' + Collection of named functions to convert page contents to files + ''; + type = with types; attrsOf (functionTo (functionTo (functionTo options.files.type))); + }; + config.templates.default = + let + commonmark = name: markdown: pkgs.runCommand "${name}.html" + { + buildInputs = [ pkgs.cmark ]; + } '' + cmark ${builtins.toFile "${name}.md" markdown} > $out + ''; + in + lib.mkDefault + (config: name: page: { + # TODO: create static redirects from the tail + ${lib.head page.locations} = builtins.toFile "${name}.html" '' + + + + + + + ${page.title} + + + + + ${builtins.readFile (commonmark name page.body)} + + + ''; + }); + + options.files = mkOption { + description = '' + Files that make up the site, mapping from output path to contents + + By default, all elements in `option`{pages} are converted to files using their template or the default template. + Add more files to the output by assigning to this attribute set. + ''; + type = with types; attrsOf path; + }; + config.files = lib.concatMapAttrs + (name: page: page.template config name page) + config.pages; + + options.build = mkOption { + description = '' + The final output of the web site + ''; + type = types.package; + default = + let + script = '' + mkdir $out + '' + lib.concatStringsSep "\n" copy; + copy = lib.mapAttrsToList + ( + path: file: '' + mkdir -p $out/$(dirname ${path}) + cp -r ${file} $out/${path} + '' + ) + config.files; + in + pkgs.runCommand "source" { } script; + }; +}