1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2024-12-14 11:47:31 +00:00

Move site to repo hercules-ci/flake.parts-website

https://github.com/hercules-ci/flake.parts-website
This commit is contained in:
Robert Hensing 2022-11-12 16:30:20 +01:00
parent 3fb80e6d35
commit a98d38d5a5
12 changed files with 3 additions and 354 deletions

View file

@ -35,6 +35,7 @@ baseline level of compatibility: the core attributes that constitute a flake.
- Reuse project logic written by others
<!-- end_of_intro -->
<!-- ^^^^^^^^^^^^ used by https://github.com/hercules-ci/flake.parts-website -->
# Getting Started

View file

@ -1,5 +1,5 @@
# Separate `tools` flake
# Separate `dev` flake
Wouldn't recommend this pattern normally, but I'm trying to keep
deps low for `flake-parts` until we have split dev inputs

View file

@ -3,8 +3,7 @@
{
imports = [
inputs.pre-commit-hooks-nix.flakeModule
inputs.hercules-ci-effects.flakeModule
../site/flake-module.nix
inputs.hercules-ci-effects.flakeModule # herculesCI attr
];
systems = [ "x86_64-linux" "aarch64-darwin" ];
perSystem = { config, self', inputs', pkgs, ... }: {
@ -13,10 +12,6 @@
nativeBuildInputs = [
pkgs.nixpkgs-fmt
pkgs.pre-commit
pkgs.hci
pkgs.netlify-cli
pkgs.pandoc
pkgs.mdbook
];
shellHook = ''
${config.pre-commit.installationScript}
@ -31,19 +26,6 @@
};
};
herculesCI = herculesCI@{ config, ... }: {
onPush.default.outputs = {
effects =
withSystem "x86_64-linux" ({ config, pkgs, hci-effects, ... }: {
netlifyDeploy = hci-effects.netlifyDeploy {
content = config.packages.siteContent;
secretName = "default-netlify";
siteId = "29a153b1-3698-433c-bc73-62415efb8117";
productionDeployment = herculesCI.config.repo.branch == "main";
};
});
};
};
flake = {
# for repl exploration / debug
config.config = config;

1
site/.gitignore vendored
View file

@ -1 +0,0 @@
book

View file

@ -1,6 +0,0 @@
[book]
authors = ["Robert Hensing", "Various module authors"]
language = "en"
multilingual = false
src = "src"
title = "flake-parts"

View file

@ -1,137 +0,0 @@
{ inputs, ... }: {
perSystem = { config, self', inputs', pkgs, lib, ... }:
let
inherit (lib) filter any hasPrefix concatMap removePrefix;
libNix = import ../lib.nix { inherit lib; };
eval = libNix.evalFlakeModule { self = { inputs = { inherit (inputs) nixpkgs; }; }; } {
imports = [
inputs.pre-commit-hooks-nix.flakeModule
inputs.hercules-ci-effects.flakeModule
inputs.haskell-flake.flakeModule
inputs.dream2nix.flakeModuleBeta
];
};
opts = eval.options;
filterTransformOptions = { sourceName, sourcePath, baseUrl }:
let sourcePathStr = toString sourcePath;
in
opt:
let
declarations = concatMap
(decl:
if hasPrefix sourcePathStr (toString decl)
then
let subpath = removePrefix sourcePathStr (toString decl);
in [{ url = baseUrl + subpath; name = sourceName + subpath; }]
else [ ]
)
opt.declarations;
in
if declarations == [ ]
then opt // { visible = false; }
else opt // { inherit declarations; };
optionsDoc = { sourceName, baseUrl, sourcePath, title }: pkgs.runCommand "option-doc-${sourceName}"
{
nativeBuildInputs = [ pkgs.libxslt.bin pkgs.pandoc ];
inputDoc = (pkgs.nixosOptionsDoc {
options = opts;
documentType = "none";
transformOptions = filterTransformOptions {
inherit sourceName baseUrl sourcePath;
};
warningsAreErrors = true; # not sure if feasible long term
markdownByDefault = true;
}).optionsDocBook;
inherit title;
} ''
xsltproc --stringparam title "$title" \
-o options.db.xml ${./options.xsl} \
"$inputDoc"
mkdir $out
pandoc --verbose --from docbook --to html options.db.xml >$out/options.md;
'';
repos = {
flake-parts = {
title = "Core Options";
sourceName = "flake-parts";
baseUrl = "https://github.com/hercules-ci/flake-parts/blob/main";
sourcePath = ../.;
};
pre-commit-hooks-nix = {
title = "pre-commit-hooks.nix";
sourceName = "pre-commit-hooks.nix";
baseUrl = "https://github.com/hercules-ci/pre-commit-hooks.nix/blob/flakeModule";
sourcePath = inputs.pre-commit-hooks-nix;
};
hercules-ci-effects = {
title = "hercules-ci-effects";
sourceName = "hercules-ci-effects";
baseUrl = "https://github.com/hercules-ci/hercules-ci-effects/blob/master";
sourcePath = inputs.hercules-ci-effects;
};
haskell-flake = {
title = "haskell-flake";
sourceName = "haskell-flake";
baseUrl = "https://github.com/srid/haskell-flake/blob/master";
sourcePath = inputs.haskell-flake;
};
dream2nix = {
title = "dream2nix beta";
sourceName = "dream2nix";
baseUrl = "https://github.com/nix-community/dream2nix/blob/master";
sourcePath = inputs.dream2nix;
};
};
generatedDocs = lib.mapAttrs (k: optionsDoc) repos;
generatedDocs' = lib.mapAttrs' (name: value: { name = "generated-docs-${name}"; inherit value; }) generatedDocs;
in
{
packages = {
siteContent = pkgs.stdenvNoCC.mkDerivation {
name = "site";
nativeBuildInputs = [ pkgs.mdbook ];
src = ./.;
buildPhase = ''
runHook preBuild
{
while read ln; do
case "$ln" in
*end_of_intro*)
break
;;
*)
echo "$ln"
;;
esac
done
cat src/intro-continued.md
} <${../README.md} >src/README.md
mkdir -p src/options
${lib.concatStringsSep "\n"
(lib.mapAttrsToList
(name: generated: ''
cp '${generated}/options.md' 'src/options/${name}.md'
'')
generatedDocs)
}
mdbook build --dest-dir $out
echo '<html><head><script>window.location.pathname = window.location.pathname.replace(/options.html$/, "") + "/options/flake-parts.html"</script></head><body><a href="options/flake-parts.html">to the options</a></body></html>' \
>$out/options.html
runHook postBuild
'';
dontInstall = true;
};
} // generatedDocs';
};
}

View file

@ -1,54 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns="http://docbook.org/ns/docbook"
xmlns:db="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="db:variablelist">
<chapter>
<title>
<xsl:value-of select="$title"/>
</title>
<para>Overview:</para>
<xsl:for-each select="db:varlistentry">
<para><link xlink:href="#{db:term/@xml:id}"><xsl:copy-of select="db:term/db:option"/></link></para>
</xsl:for-each>
<xsl:apply-templates />
</chapter>
</xsl:template>
<xsl:template match="db:varlistentry">
<section>
<title>
<link xlink:href="#{db:term/@xml:id}" xml:id="{db:term/@xml:id}"><xsl:copy-of select="db:term/db:option"/></link>
</title>
<xsl:apply-templates select="db:listitem/*"/>
</section>
</xsl:template>
<!-- Pandoc doesn't like block-level simplelist -->
<!-- https://github.com/jgm/pandoc/issues/8086 -->
<xsl:template match="db:simplelist">
<para>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</para>
</xsl:template>
<!-- Turn filename tags with href attrs into explicit links -->
<xsl:template match="db:filename">
<link xlink:href="{@xlink:href}">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</link>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View file

@ -1,13 +0,0 @@
# Summary
- [Introduction](./README.md)
- [Getting Started](./getting-started.md)
- [Working with `system`](./system.md)
- [Reference Documentation](./module-arguments.md)
- [Module Arguments](./module-arguments.md)
- [Options](./options/flake-parts.md)
- [Core `flake-parts`](./options/flake-parts.md)
- [`dream2nix beta`](./options/dream2nix.md)
- [`haskell-flake`](./options/haskell-flake.md)
- [`hercules-ci-effects`](./options/hercules-ci-effects.md)
- [`pre-commit-hooks.nix`](./options/pre-commit-hooks-nix.md)

View file

@ -1,38 +0,0 @@
# Getting Started
## New flake
If your project does not have a flake yet:
```console
nix flake init -t github:hercules-ci/flake-parts
```
## Existing flake
Otherwise, add the input,
```
flake-parts.url = "github:hercules-ci/flake-parts";
```
then slide `mkFlake` between your outputs function head and body,
```
outputs = { self, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit self; } {
flake = {
# Put your original flake attributes here.
};
systems = [
# systems for which you want to build the `perSystem` attributes
"x86_64-linux"
# ...
];
perSystem = { config, ... }: {
};
};
```
Now you can start using the flake-parts options.

View file

@ -1,7 +0,0 @@
<!-- prefaced by the README intro -->
# This documentation
You can find guides and the options reference in the menu (top left).
A site wide search is available by typing `s`.

View file

@ -1,58 +0,0 @@
# Module Arguments
The module system allows modules and submodules to be defined using plain
attribute sets, or functions that return attribute sets. When a module is a
function, various attributes may be passed to it.
# Top-level Module Arguments
Top-level refers to the module passed to `mkFlake`, or any of the modules
imported into it using `imports`.
The standard module system arguments are available in all modules and submodules. These are chiefly `config`, `options`, `lib`.
## `getSystem`
A function from [system](./system.md) string to the `config` of the appropriate `perSystem`.
## `moduleWithSystem`
A function that brings the `perSystem` module arguments.
This allows a module to reference the defining flake without introducing
global variables.
```nix
{ moduleWithSystem, ... }:
{
nixosModules.default = moduleWithSystem (
perSystem@{ config }: # NOTE: only explicit params will be in perSystem
nixos@{ ... }:
{
services.foo.package = perSystem.config.packages.foo;
imports = [ ./nixos-foo.nix ];
}
);
}
```
## `withSystem`
Enter the scope of a system. Worked example:
```nix
{ withSystem, ... }:
{
# perSystem = ...;
nixosConfigurations.foo = withSystem "x86_64-linux" (ctx@{ pkgs, ... }:
pkgs.nixos ({ config, lib, packages, pkgs, ... }: {
_module.args.packages = ctx.config.packages;
imports = [ ./nixos-configuration.nix ];
services.nginx.enable = true;
environment.systemPackages = [
packages.hello
];
}));
}
```

View file

@ -1,20 +0,0 @@
# `system`
In Nix, "system" generally refers to the cpu-os string, such as `"x86_64-linux"`.
In Flakes specifically, these strings are used as attribute names, so that the
Nix CLI can find a derivation for the right platform.
Many things, such as packages, can exist on multiple systems. For these, use
the [`perSystem`](options/flake-parts.html#opt-perSystem) submodule.
Other things do not exist on multiple systems. Examples are the configuration
of a specific machine, or a the execution of a deployment. These are not
written in `perSystem`, but in other top-level options, or directly into the
flake outputs' top level (e.g. [`flake.nixosConfigurations`](options/flake-parts.html#opt-flake.nixosConfigurations)).
Such top-level entities typically do need to read packages, etc that are defined
in `perSystem`. Instead of reading them from `config.flake.packages.<system>.<name>`,
it may be more convenient to bring all `perSystem` definitions for a system into
scope, using [`withSystem`](module-arguments.html#withsystem).