modularize

This commit is contained in:
Valentin Gagarin 2024-11-13 15:24:40 +01:00 committed by Valentin Gagarin
parent 937d24eb09
commit ab56a0b5cc
10 changed files with 244 additions and 125 deletions

View file

@ -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})
'';
};
}

View file

@ -1,10 +1,14 @@
{ ... }:
{ {
pages.grants = {
title = "Grants"; title = "Grants";
locations = [
"grants.html"
];
description = "How to apply for grants as part of the Fediversity Project"; description = "How to apply for grants as part of the Fediversity Project";
summary = '' 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 euros which should get you on your way. 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 euros which should get you on your way.
''; '';
outPath = "grants.html";
body = '' 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. 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.
@ -14,4 +18,5 @@
For more information on how to apply, check the NLnet website. For more information on how to apply, check the NLnet website.
''; '';
};
} }

View file

@ -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 ])}
'';
}

12
website/content/nlnet.nix Normal file
View file

@ -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 1980s, 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.
'';
}

View file

@ -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.
'';
}

17
website/content/oid.nix Normal file
View file

@ -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 its 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 NixOSs package management help with an open and sustainable internet.
'';
}

10
website/content/tweag.nix Normal file
View file

@ -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.
'';
}

View file

@ -8,11 +8,18 @@
, lib ? import "${sources.nixpkgs}/lib" , 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 { shell = pkgs.mkShellNoCC {
packages = with pkgs; [ packages = with pkgs; [

View file

@ -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" ''
<html>
<head>
<title>${document.title}</title>
</head>
<body>
${builtins.readFile (commonmark document.body name)}
<body>
</html>
'';
/**
Convert a commonmark string to HTML
*/
commonmark = markdown: name:
pkgs.runCommand "${name}.html" { buildInputs = [ pkgs.cmark ]; } ''
cmark ${builtins.toFile "${name}.md" markdown} > $out
'';
}

View file

@ -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" ''
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>${page.title}</title>
<meta name="description" content="${page.description}" />
<link rel="canonical" href="${lib.head page.locations}" />
</head>
<body>
${builtins.readFile (commonmark name page.body)}
<body>
</html>
'';
});
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;
};
}