From 13fc0c610b95e05ea4f25f1c7ca6f5ab19b831bf Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 18 May 2022 00:41:17 +0200 Subject: [PATCH 1/2] Deploy basic site with netlify --- dev/flake-module.nix | 19 ++++++++++++++++- dev/flake.lock | 48 ++++++++++++++++++++++++++++++++++++------- dev/flake.nix | 4 +++- site/flake-module.nix | 22 ++++++++++++++++++++ site/index.html | 42 +++++++++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+), 9 deletions(-) create mode 100644 site/flake-module.nix create mode 100644 site/index.html diff --git a/dev/flake-module.nix b/dev/flake-module.nix index f4fb450..216cb2a 100644 --- a/dev/flake-module.nix +++ b/dev/flake-module.nix @@ -3,6 +3,7 @@ flakeModuleArgs@{ 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} @@ -43,9 +47,22 @@ flakeModuleArgs@{ config, lib, inputs, ... }: }; 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.websitePackage; + secretName = "default-netlify"; + siteId = "29a153b1-3698-433c-bc73-62415efb8117"; + productionDeployment = true; + }); + }; }; }; diff --git a/dev/flake.lock b/dev/flake.lock index 28eacfb..1165ae2 100644 --- a/dev/flake.lock +++ b/dev/flake.lock @@ -15,18 +15,51 @@ "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": 1653465299, + "narHash": "sha256-+1jyM4dsppYFgiJf+VkAAS/l5iF0y5J7D2l1fLzT8DA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5862243e1ab8c0a19cb448f523c27c167dcd826b", + "type": "github" + }, + "original": { + "owner": "NixOS", "repo": "nixpkgs", "type": "github" } @@ -55,7 +88,8 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs", + "hercules-ci-effects": "hercules-ci-effects", + "nixpkgs": "nixpkgs_2", "pre-commit-hooks-nix": "pre-commit-hooks-nix" } } diff --git a/dev/flake.nix b/dev/flake.nix index af815b4..41ac8a4 100644 --- a/dev/flake.nix +++ b/dev/flake.nix @@ -4,10 +4,12 @@ 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"; + nixpkgs.url = "github:NixOS/nixpkgs"; 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, ... }: diff --git a/site/flake-module.nix b/site/flake-module.nix new file mode 100644 index 0000000..827488c --- /dev/null +++ b/site/flake-module.nix @@ -0,0 +1,22 @@ +{ ... }: { + perSystem = system: { config, self', inputs', pkgs, lib, ... }: { + packages.websitePackage = pkgs.stdenvNoCC.mkDerivation { + name = "site"; + nativeBuildInputs = [ pkgs.pandoc ]; + src = lib.cleanSourceWith { + filter = path: type: + path == ./. + || baseNameOf path == "index.html"; + src = ./.; + }; + buildPhase = '' + pandoc --from docbook --to html5 \ + ${config.packages.optionsDocBook} >options.html + ''; + installPhase = '' + mkdir -p $out + cp *.html $out/ + ''; + }; + }; +} diff --git a/site/index.html b/site/index.html new file mode 100644 index 0000000..759f7be --- /dev/null +++ b/site/index.html @@ -0,0 +1,42 @@ + + + + flake-modules-core + + + +

flake-modules-core

+ +

+ Compose flakes with the (NixOS) module system. +

+ +

+ Testimonials: +

+ +
+ yeah.. powerful stuff +
+ +
+ I cannot tell you how freeing the flake-modules concept is
+ fucking hell
+ I feel like a hipster using it too +
+ +

+ Learn more: +

+ +

+ GitHub +

+ +

+ Options Reference +

+ + + + \ No newline at end of file From 3ff2098da2d0829dbcac02f42bed4e03c1cda292 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 25 May 2022 16:19:43 +0200 Subject: [PATCH 2/2] Improve option docs, update effect --- dev/flake-module.nix | 20 +--------- dev/flake.lock | 11 +++--- dev/flake.nix | 5 ++- site/flake-module.nix | 88 ++++++++++++++++++++++++++++++++++--------- site/options.xsl | 53 ++++++++++++++++++++++++++ 5 files changed, 135 insertions(+), 42 deletions(-) create mode 100644 site/options.xsl diff --git a/dev/flake-module.nix b/dev/flake-module.nix index 216cb2a..60da698 100644 --- a/dev/flake-module.nix +++ b/dev/flake-module.nix @@ -1,4 +1,4 @@ -flakeModuleArgs@{ config, lib, inputs, ... }: +{ config, lib, inputs, ... }: { imports = [ @@ -28,22 +28,6 @@ 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; }; @@ -57,7 +41,7 @@ flakeModuleArgs@{ config, lib, inputs, ... }: in { netlifyDeploy = effects.runIf (branch == "main") (effects.netlifyDeploy { - content = config.flake.packages.x86_64-linux.websitePackage; + content = config.flake.packages.x86_64-linux.siteContent; secretName = "default-netlify"; siteId = "29a153b1-3698-433c-bc73-62415efb8117"; productionDeployment = true; diff --git a/dev/flake.lock b/dev/flake.lock index 1165ae2..2dcc47f 100644 --- a/dev/flake.lock +++ b/dev/flake.lock @@ -51,15 +51,16 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1653465299, - "narHash": "sha256-+1jyM4dsppYFgiJf+VkAAS/l5iF0y5J7D2l1fLzT8DA=", - "owner": "NixOS", + "lastModified": 1653476104, + "narHash": "sha256-oVuWUnGQX+fRn/cFoNfbLEUGtsyyXuMLDQFEZ2OxP3k=", + "owner": "hercules-ci", "repo": "nixpkgs", - "rev": "5862243e1ab8c0a19cb448f523c27c167dcd826b", + "rev": "612e22e67eb6f8d5bfb6288abe515e9da3b96103", "type": "github" }, "original": { - "owner": "NixOS", + "owner": "hercules-ci", + "ref": "module-docs-update", "repo": "nixpkgs", "type": "github" } diff --git a/dev/flake.nix b/dev/flake.nix index 41ac8a4..1b1d4e1 100644 --- a/dev/flake.nix +++ b/dev/flake.nix @@ -4,7 +4,10 @@ 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:NixOS/nixpkgs"; + + # 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"; diff --git a/site/flake-module.nix b/site/flake-module.nix index 827488c..3543cb4 100644 --- a/site/flake-module.nix +++ b/site/flake-module.nix @@ -1,22 +1,74 @@ { ... }: { - perSystem = system: { config, self', inputs', pkgs, lib, ... }: { - packages.websitePackage = pkgs.stdenvNoCC.mkDerivation { - name = "site"; - nativeBuildInputs = [ pkgs.pandoc ]; - src = lib.cleanSourceWith { - filter = path: type: - path == ./. - || baseNameOf path == "index.html"; - src = ./.; + 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/ + ''; + }; }; - buildPhase = '' - pandoc --from docbook --to html5 \ - ${config.packages.optionsDocBook} >options.html - ''; - installPhase = '' - mkdir -p $out - cp *.html $out/ - ''; }; - }; } diff --git a/site/options.xsl b/site/options.xsl new file mode 100644 index 0000000..70f725d --- /dev/null +++ b/site/options.xsl @@ -0,0 +1,53 @@ + + + + + + + + + <xsl:value-of select="$title"/> + + + + + +
+ + + + + <xsl:copy-of select="db:term/db:option"/> + + +
+
+ + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file