update example to use mkNteDerivation

This commit is contained in:
jacekpoz 2024-09-12 23:09:29 +02:00
parent 5dc4fef45e
commit 06b709f9e1
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
2 changed files with 25 additions and 36 deletions

View file

@ -1,25 +1,30 @@
{ {
lib, lib,
nte, mkNteDerivation,
stdenv,
... ...
}: let }: let
inherit (lib.attrsets) listToAttrs; inherit (lib.attrsets) listToAttrs;
inherit (lib.lists) map; inherit (lib.lists) map;
inherit (lib.strings) replaceStrings toLower; inherit (lib.strings) replaceStrings toLower;
extraArgs = { extraArgs' = {
h = n: content: let h = n: content: let
id = replaceStrings [" " ";"] ["-" "-"] (toLower content); id = replaceStrings [" " ";"] ["-" "-"] (toLower content);
in /*html*/'' in /*html*/''
<h${toString n} id="${id}"><a href="#${id}">#</a> ${content}</h${toString n}> <h${toString n} id="${id}"><a href="#${id}">#</a> ${content}</h${toString n}>
''; '';
} };
// listToAttrs (map (n: { in mkNteDerivation {
name = "h${toString n}"; name = "nte-example";
value = text: extraArgs.h n text; version = "0.1.0";
}) [ 1 2 3 4 5 6 ] src = ./.;
);
extraArgs = extraArgs'
// listToAttrs (map (n: {
name = "h${toString n}";
value = text: extraArgs'.h n text;
}) [ 1 2 3 4 5 6 ]
);
entries = [ entries = [
./index.nix ./index.nix
@ -31,27 +36,9 @@
./templates/base.nix ./templates/base.nix
./templates/post.nix ./templates/post.nix
]; ];
in
stdenv.mkDerivation {
name = "nte-example";
version = "0.1.0";
src = ./.;
buildPhase = /*sh*/'' extraFiles = [
runHook preBuild { source = "./*.css"; destination = "/"; }
{ source = "./posts/*.css"; destination = "/posts"; }
${nte {inherit extraArgs entries templates;}} ];
}
runHook postBuild
'';
installPhase = /*sh*/''
runHook preInstall
mkdir -p $out
cp -r ./*.css $out
cp -r ./posts/*.css $out/posts
runHook postInstall
'';
}

View file

@ -10,14 +10,15 @@
forEachSystem = nixpkgs.lib.genAttrs (import systems); forEachSystem = nixpkgs.lib.genAttrs (import systems);
pkgsForEach = nixpkgs.legacyPackages; pkgsForEach = nixpkgs.legacyPackages;
enginesForEach = import ./engine.nix; enginesForEach = import ./engine.nix;
mkNteDerivationsForEach = import ./nte-drv.nix;
in { in {
functions = forEachSystem ( functions = forEachSystem (
system: let system: let
pkgs = pkgsForEach.${system}; pkgs = pkgsForEach.${system};
engine = enginesForEach pkgs; engine = enginesForEach pkgs;
mkNteDerivation = mkNteDerivationsForEach pkgs engine;
in { in {
inherit engine; inherit engine mkNteDerivation;
mkNteDerivation = import ./nte-drv.nix pkgs engine;
} }
); );
@ -33,10 +34,11 @@
system: let system: let
pkgs = pkgsForEach.${system}; pkgs = pkgsForEach.${system};
engine = enginesForEach pkgs; engine = enginesForEach pkgs;
mkNteDerivation = mkNteDerivationsForEach pkgs engine;
in { in {
default = import ./example/default.nix { default = import ./example/default.nix {
inherit (pkgs) lib stdenv; inherit (pkgs) lib;
nte = engine ./example; inherit mkNteDerivation;
}; };
} }
); );