1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2025-03-30 19:54:47 +00:00

Merge pull request #15 from hercules-ci/netlify-deploy

Deploy basic site with netlify
This commit is contained in:
Robert Hensing 2022-05-25 16:27:46 +02:00 committed by GitHub
commit 98bc2676c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 236 additions and 26 deletions

View file

@ -1,8 +1,9 @@
flakeModuleArgs@{ config, lib, inputs, ... }:
{ config, lib, inputs, ... }:
{
imports = [
inputs.pre-commit-hooks-nix.flakeModule
../site/flake-module.nix
];
systems = [ "x86_64-linux" "aarch64-darwin" ];
perSystem = system: { config, self', inputs', pkgs, ... }: {
@ -11,6 +12,9 @@ flakeModuleArgs@{ config, lib, inputs, ... }:
nativeBuildInputs = [
pkgs.nixpkgs-fmt
pkgs.pre-commit
pkgs.hci
pkgs.netlify-cli
pkgs.pandoc
];
shellHook = ''
${config.pre-commit.installationScript}
@ -24,28 +28,25 @@ flakeModuleArgs@{ config, lib, inputs, ... }:
};
};
packages = {
inherit (pkgs.nixosOptionsDoc { inherit (flakeModuleArgs) options; })
optionsDocBook;
optionsMarkdown = pkgs.runCommand "options-markdown"
{
inherit (config.packages) optionsDocBook;
nativeBuildInputs = [ pkgs.pandoc ];
} ''
mkdir $out
pandoc \
--from docbook \
--to markdown \
--output $out/options.md \
$optionsDocBook
'';
};
};
flake = {
options.herculesCI = lib.mkOption { type = lib.types.raw; };
config.herculesCI = {
config.herculesCI = { branch, ... }: {
onPush.default.outputs = {
inherit (config.flake) packages checks;
effects =
let
pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
effects = inputs.hercules-ci-effects.lib.withPkgs pkgs;
in
{
netlifyDeploy = effects.runIf (branch == "main") (effects.netlifyDeploy {
content = config.flake.packages.x86_64-linux.siteContent;
secretName = "default-netlify";
siteId = "29a153b1-3698-433c-bc73-62415efb8117";
productionDeployment = true;
});
};
};
};

49
dev/flake.lock generated
View file

@ -15,18 +15,52 @@
"type": "github"
}
},
"nixpkgs": {
"hercules-ci-effects": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1652734403,
"narHash": "sha256-pIp7mRuYQd4JY2Ih4QaDjKVFgu7f1yHRRAvpb/rU9Mg=",
"lastModified": 1653415319,
"narHash": "sha256-h+YUX7ZYujf73KL1R07LsEnhV7uV8oxSKEhH4bDj0Jc=",
"owner": "hercules-ci",
"repo": "nixpkgs",
"rev": "0b02135d3bdf49f9154f60e7a4c9d54d5e0ee70d",
"repo": "hercules-ci-effects",
"rev": "1f904af1824e7393702daaf40a8fed56ebead0d7",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"ref": "functionTo-properly",
"repo": "hercules-ci-effects",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1647297614,
"narHash": "sha256-ulGq3W5XsrBMU/u5k9d4oPy65pQTkunR4HKKtTq0RwY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "73ad5f9e147c0d2a2061f1d4bd91e05078dc0b58",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1653476104,
"narHash": "sha256-oVuWUnGQX+fRn/cFoNfbLEUGtsyyXuMLDQFEZ2OxP3k=",
"owner": "hercules-ci",
"repo": "nixpkgs",
"rev": "612e22e67eb6f8d5bfb6288abe515e9da3b96103",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"ref": "module-docs-update",
"repo": "nixpkgs",
"type": "github"
}
@ -55,7 +89,8 @@
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"hercules-ci-effects": "hercules-ci-effects",
"nixpkgs": "nixpkgs_2",
"pre-commit-hooks-nix": "pre-commit-hooks-nix"
}
}

View file

@ -4,10 +4,15 @@
inputs = {
# Flakes don't give us a good way to depend on .., so we don't.
# This has drastic consequences of course.
nixpkgs.url = "github:hercules-ci/nixpkgs/functionTo-properly";
# https://github.com/NixOS/nixpkgs/pull/174460
# https://github.com/NixOS/nixpkgs/pull/174470
nixpkgs.url = "github:hercules-ci/nixpkgs/module-docs-update";
pre-commit-hooks-nix.url = "github:hercules-ci/pre-commit-hooks.nix/flakeModule";
pre-commit-hooks-nix.inputs.nixpkgs.follows = "nixpkgs";
hercules-ci-effects.url = "github:hercules-ci/hercules-ci-effects";
};
outputs = { self, ... }:

74
site/flake-module.nix Normal file
View file

@ -0,0 +1,74 @@
{ ... }: {
perSystem = system: { config, self', inputs', pkgs, lib, ... }:
let
inherit (lib) filter any hasPrefix concatMap removePrefix;
libNix = import ../lib.nix { inherit lib; };
eval = libNix.evalFlakeModule { self = { }; } { };
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 "${sourceName}-doc"
{
nativeBuildInputs = [ pkgs.libxslt.bin ];
inputDoc = (pkgs.nixosOptionsDoc {
options = opts;
documentType = "none";
transformOptions = filterTransformOptions {
inherit sourceName baseUrl sourcePath;
};
}).optionsDocBook;
inherit title;
} ''
xsltproc --stringparam title "$title" \
-o $out ${./options.xsl} \
"$inputDoc"
'';
in
{
packages = {
siteContent = pkgs.stdenvNoCC.mkDerivation {
name = "site";
nativeBuildInputs = [ pkgs.pandoc pkgs.libxslt.bin ];
src = lib.cleanSourceWith {
filter = path: type:
path == ./.
|| baseNameOf path == "index.html";
src = ./.;
};
coreOptions = optionsDoc {
title = "Core Options";
sourceName = "flake-modules-core";
baseUrl = "https://github.com/hercules-ci/flake-modules-core/blob/main";
sourcePath = ../.;
};
buildPhase = ''
pandoc --verbose --from docbook --to html5 $coreOptions >options.html
'';
installPhase = ''
mkdir -p $out
cp *.html $out/
'';
};
};
};
}

42
site/index.html Normal file
View file

@ -0,0 +1,42 @@
<html>
<head>
<title>flake-modules-core</title>
</head>
<body>
<h1><code>flake-modules-core</code></h1>
<p>
Compose flakes with the (NixOS) module system.
</p>
<p>
Testimonials:
</p>
<blockquote>
yeah.. powerful stuff
</blockquote>
<blockquote>
I cannot tell you how freeing the flake-modules concept is<br/>
fucking hell<br/>
I feel like a hipster using it too
</blockquote>
<p>
Learn more:
</p>
<p>
<a href="https://github.com/hercules-ci/flake-modules-core">GitHub</a>
</p>
<p>
<a href="./options.html">Options Reference</a>
</p>
</body>
</html>

53
site/options.xsl Normal file
View file

@ -0,0 +1,53 @@
<?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>
<xsl:apply-templates />
</chapter>
</xsl:template>
<xsl:template match="db:varlistentry">
<section>
<xsl:attribute name="xml:id">
<xsl:value-of select="db:term/@xml:id"/>
</xsl:attribute>
<title>
<xsl:copy-of select="db:term/db:option"/>
</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>