This commit is contained in:
Sandro - 2024-01-08 00:39:51 +01:00
parent 90bace38df
commit 2898c47279
Signed by: sandro
GPG Key ID: 3AF5A43A3EECC2E5
4 changed files with 147 additions and 24 deletions

44
.github/workflows/gh-pages.yaml vendored Normal file
View File

@ -0,0 +1,44 @@
name: "pages"
on:
push:
branches:
- master
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v24
- name: Build docs
run: nix build .#docbook
- name: Prepare assets for upload
run: cp -r --dereference --no-preserve=mode,ownership result/ public/
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: public/
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v3

View File

@ -1,23 +1,58 @@
{
"nodes": {
"nixpkgs-lib": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1701564385,
"narHash": "sha256-um5ce7hnsQ8Do+oKf90zGKVmEqufr4Q6T8zfY9Hon38=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "152c00fc19bc45af5dd65bd41d1d020c2ba0b4ca",
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1704194953,
"narHash": "sha256-RtDKd8Mynhe5CFnVT8s0/0yqtWFMM9LmCzXv/YKxnq4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "bd645e8668ec6612439a9ee7e71f7eac4099d4f6",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},

View File

@ -2,15 +2,17 @@
description = "Opinionated shared nixos configurations";
inputs = {
nixpkgs-lib.url = "github:nix-community/nixpkgs.lib";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs-lib, ... }:
outputs = { self, flake-utils, nixpkgs, ... }:
let
inherit (nixpkgs-lib) lib;
inherit (nixpkgs) lib;
src = builtins.filterSource (path: type: type == "directory" || lib.hasSuffix ".nix" (baseNameOf path)) ./.;
ls = dir: lib.attrNames (builtins.readDir (src + "/${dir}"));
fileList = dir: map (file: ./. + "/${dir}/${file}") (ls dir);
importDirToKey = dir: args: lib.listToAttrs (map
(file: {
name = lib.removeSuffix ".nix" file;
@ -18,6 +20,10 @@
})
(ls dir)
);
importLibS = args: {
_module.args.libS = lib.mkOverride 1000 (self.lib args);
};
in
{
lib = args:
@ -25,24 +31,35 @@
lib' = importDirToKey "lib" args;
in
lib' // {
# some functions get promoted to be directly under libS
inherit (lib'.doc) mkModuleDoc;
inherit (lib'.modules) mkOpinionatedOption mkRecursiveDefault;
inherit (lib'.ssh) mkPubKey;
};
nixosModules = lib.foldr (a: b: a // b) { } (map
(
name: {
"${lib.removeSuffix ".nix" name}" = {
imports = [ ./modules/${name} ];
(name: {
"${lib.removeSuffix ".nix" name}" = { config, lib, pkgs, ... }:
(importLibS { inherit config lib pkgs; }) // {
imports = [
./modules
./modules/${name}
];
};
}
)
(ls "modules"));
})
(ls "modules")
);
nixosModule = { config, ... }: {
_module.args.libS = lib.mkOverride 1000 (self.lib { inherit lib config; });
imports = fileList "modules";
nixosModule = { config, lib, pkgs, ... }:
(importLibS { inherit config lib pkgs; }) // {
imports = fileList "modules";
};
} // flake-utils.lib.eachDefaultSystem (system: let
libS = self.lib { config = { }; inherit lib; pkgs = nixpkgs.legacyPackages.${system}; };
in {
packages.options-doc = libS.mkModuleDoc {
module = self.nixosModule;
urlPrefix = "https://github.com/SuperSandro2000/nixos-modules/tree/master/";
};
};
});
}

27
lib/doc.nix Normal file
View File

@ -0,0 +1,27 @@
{ lib, pkgs, ... }:
{
# based on https://github.com/j-brn/nixos-vfio/blob/master/lib/mkModuleDoc.nix
mkModuleDoc = { module, urlPrefix }: let
inherit (lib.evalModules {
modules = [ {
config._module.check = false;
} module ];
}) options;
filteredOptions = lib.filterAttrs (key: _: key != "_module") options;
docs = pkgs.nixosOptionsDoc {
options = filteredOptions;
warningsAreErrors = false;
};
url = lib.escape [ ":" "." "-" ] urlPrefix;
in pkgs.runCommand "options.md" { } /* bash */ ''
mkdir $out
cat ${docs.optionsCommonMark} \
| sed -r -e 's|\[/nix/store/.+\-source/(.+\.nix)\]|[\1]|g' \
-e 's|\[/nix/store/.+\-source/(.+)\]|[\1/default\.nix]|g' \
-e 's|\[flake\\.nix\\#nixosModules\\.(\w+)\/default\.nix\]|\[modules\/\1\/default\.nix\]|g' \
-e 's|file\:///nix/store/.+\-source/(.+\.nix)|${url}\1|g' \
-e 's|file\:///nix/store/.+\-source/(.+)\)|${url}/\1/default\.nix\)|g' \
> $out/options.md
'';
}