summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquentin@aristote.fr <quentin@aristote.fr>2025-02-16 23:55:26 +0100
committerquentin@aristote.fr <quentin@aristote.fr>2025-02-22 21:14:40 +0100
commitf9e2ddae012c56c2690f6fc99627a7996dccee6f (patch)
tree2028e0abc072f85e00748841bb1fdb8e400536d2
parentaf3f5ba54e4c044316d6cceb1564abc318aa80c0 (diff)
move building inside package
-rw-r--r--default.nix171
-rw-r--r--flake.lock18
-rw-r--r--flake.nix36
-rw-r--r--make.nix21
-rw-r--r--src.nix7
-rw-r--r--static/robots.txt3
6 files changed, 141 insertions, 115 deletions
diff --git a/default.nix b/default.nix
index 2eaa55e..8b4a24a 100644
--- a/default.nix
+++ b/default.nix
@@ -1,96 +1,99 @@
{
- pkgs,
- html,
+ stdenvNoCC,
+ # Packages
+ line-awesome,
+ line-awesome-css,
+ uncss,
+ yuicompressor,
+ imagemagick,
+ nix,
+ perlPackages,
+ # Source files
+ nixpkgsSrc,
+ src,
data,
}: let
- commonArgs = {
- inherit data html make;
- inherit (pkgs) lib;
- };
- make = path: overrides: let
- f = import path;
- in
- f ((builtins.intersectAttrs (builtins.functionArgs f) commonArgs)
- // overrides);
-
- indexHTML = builtins.toFile "index.html" (make ./html {});
- classlessCSS = let
- setOption = option: value: {"${option}" = value;};
- setOptions = options: value:
- builtins.foldl' (tmp: option: tmp // setOption option value) {} options;
- enable = options: setOptions options true;
- disable = options: setOptions options false;
- in
- builtins.toFile "classless.css" (make ./css/classless.nix
- (disable ["tables" "hr"]
- // enable [
- "tooltip-citations"
- "navbar"
- "details-cards"
- "big-first-letter"
- "printing"
- "grid"
- ]));
-
- robotsTXT = builtins.toFile "robots.txt" ''
- user-agent: *
- disallow: /static/
- allow: /static/icon.png
+ compress = "${yuicompressor}/bin/yuicompressor";
+ clean = "${uncss}/bin/uncss";
+ compressJPEG = size: image: ''
+ ${imagemagick}/bin/magick ${image} \
+ -sampling-factor 4:2:0 \
+ -strip \
+ -quality 85 \
+ -interlace JPEG \
+ -colorspace RGB \
+ -resize ${size}x${size} \
+ -colorspace sRGB \
+ ${image}.${size}
'';
+ mkPushDir = dir: ''mkdir -p ${dir} && pushd "$_"'';
+ nixEvalExpr = "${nix}/bin/nix --extra-experimental-features nix-command --extra-experimental-features flakes eval --impure --raw --expr";
+ make = "import $src/make.nix {pkgs = import ${nixpkgsSrc} {}; dataSrc = $src/data;}";
in
- pkgs.callPackage ({
- # Packages
- line-awesome,
- line-awesome-css,
- uncss,
- yuicompressor,
- imagemagick,
- # Source files
- index-html ? indexHTML,
- classless-css ? classlessCSS,
- files ? data.files,
- icon ? ./static/icon.png,
- }: let
- compress = "${yuicompressor}/bin/yuicompressor";
- clean = "${uncss}/bin/uncss";
- compressJPEG = size: ''
- ${imagemagick}/bin/convert -sampling-factor 4:2:0 \
- -strip \
- -quality 85 \
- -interlace JPEG \
- -colorspace RGB \
- -resize ${size} \
- -colorspace sRGB \
+ stdenvNoCC.mkDerivation {
+ name = "webpage";
+ requiredSystemFeatures = ["recursive-nix"];
+ subsrcs = [src data];
+ src = "webpage-src";
+ unpackPhase = ''
+ read -ra srcs <<< "$subsrcs"
+ mkdir $src
+ ln -s ''${srcs[0]}/* $src/
+ ln -s ''${srcs[1]} $src/data
+ ls $src
'';
- in
- pkgs.runCommand "webpage" {} ''
- set -o xtrace
- mkdir $out && pushd "$_"
- ln -sT ${index-html} index.html
- ln -sT ${robotsTXT} robots.txt
+ installPhase = ''
+ # set -o xtrace
+ pushd $src
+ src=$(pwd)
popd
+ ${mkPushDir "$out"} # $out/
- mkdir $out/static && pushd "$_"
- ln -sT ${icon} icon.png
- cp -r ${files} files
- chmod a+w files
- pushd files
- ${compressJPEG "128x128"} avatar.jpg avatar.jpg.128
- ${compressJPEG "256x256"} avatar.jpg avatar.jpg.256
- ${compressJPEG "512x512"} avatar.jpg avatar.jpg.512
- popd
- chmod a-w files
- popd
+ # build HTML
+ ${nixEvalExpr} "
+ ${make} $src/html {}
+ " > index.html
+ ${perlPackages.HTMLClean}/bin/htmlclean index.html
+ rm index.html.bak
- mkdir -p $out/static/css && pushd "$_"
- ${clean} ${index-html} --stylesheets file://${classless-css} \
- | ${compress} --type css >classless.min.css
- popd
+ # copy static files
+ cp -r $src/static/ .
+ ln -s static/robots.txt
+ chmod 777 static
+ pushd static # $out/static/
+ cp -r ${data}/files .
+ chmod 777 files
+ pushd files # $out/static/files/
+ ${compressJPEG "128" "avatar.jpg"}
+ ${compressJPEG "256" "avatar.jpg"}
+ ${compressJPEG "512" "avatar.jpg"}
+
+ popd # $out/static/
- mkdir -p $out/static/css/fonts/line-awesome && pushd "$_"
- ln -sT ${line-awesome}/share/fonts/woff2 webfonts
- ${clean} ${index-html} --stylesheets file://${line-awesome-css} \
+ # build and compress CSS
+ ${mkPushDir "css"} # $out/static/css/
+ ${nixEvalExpr} "
+ ${make} $src/css/classless.nix {
+ big-first-letter = true;
+ details-cards = true;
+ grid = true;
+ hr = false;
+ navbar = true;
+ tables = false;
+ tooltip-citations = true;
+ printing = true;
+ }
+ " > classless.css
+ ${clean} $out/index.html --stylesheets file://$(pwd)/classless.css \
+ | ${compress} --type css >classless.min.css
+ rm classless.css
+ ${mkPushDir "fonts/line-awesome"} # $out/static/css/fonts/lineawesome
+ ln -s ${line-awesome}/share/fonts/woff2 webfonts
+ ${clean} $out/index.html --stylesheets file://${line-awesome-css} \
| ${compress} --type css >line-awesome.min.css
- popd
- '') {}
+ popd # $out/static
+ popd # $out/
+ popd #
+ '';
+ }
diff --git a/flake.lock b/flake.lock
index fd21381..3399db0 100644
--- a/flake.lock
+++ b/flake.lock
@@ -7,11 +7,11 @@
"nixpkgs": "nixpkgs_3"
},
"locked": {
- "lastModified": 1739738530,
- "narHash": "sha256-C/FO/51EhSVUeZL0ZqHegZ92wVxyVF15/9DH24wBfpQ=",
+ "lastModified": 1740255237,
+ "narHash": "sha256-AOL4A5EUEKzXM0ZyfUjjKO52BTIPMSQLOiMnwz3Ps38=",
"owner": "qaristote",
"repo": "info",
- "rev": "700aae6e4ae56034d105eab95be5fcb969b3853a",
+ "rev": "2a3777c4639383ed7aa84462d34ca6e1c959b797",
"type": "github"
},
"original": {
@@ -250,11 +250,11 @@
"nur": "nur_2"
},
"locked": {
- "lastModified": 1739561505,
- "narHash": "sha256-hQwXL6BvgvA5p+V9h6W0qI0vaxQKok+ak7BKiaXUH1g=",
+ "lastModified": 1740235172,
+ "narHash": "sha256-aSrpkhCsZM16WznghmrBYEfAHwObzgfRS3kFPYPv20o=",
"owner": "qaristote",
"repo": "my-nixpkgs",
- "rev": "e4fdb9e23fa4d0ac7a7394c281d5402bcff83cc7",
+ "rev": "27a7ae1d1933121c250ce7073bde1f83889e6151",
"type": "github"
},
"original": {
@@ -457,11 +457,11 @@
},
"nixpkgs_6": {
"locked": {
- "lastModified": 1739482815,
- "narHash": "sha256-/5Lwtmp/8j+ro32gXzitucSdyjJ6QehfJCL58WNA7N0=",
+ "lastModified": 1740019556,
+ "narHash": "sha256-vn285HxnnlHLWnv59Og7muqECNMS33mWLM14soFIv2g=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "ba0939c506a03c60a765cd7f7c43794816540eec",
+ "rev": "dad564433178067be1fbdfcce23b546254b6d641",
"type": "github"
},
"original": {
diff --git a/flake.nix b/flake.nix
index 8b2e6ad..1229594 100644
--- a/flake.nix
+++ b/flake.nix
@@ -18,11 +18,7 @@
my-nixpkgs,
...
} @ inputs:
- flake-parts.lib.mkFlake {inherit inputs;} ({
- self,
- lib,
- ...
- }: {
+ flake-parts.lib.mkFlake {inherit inputs;} ({lib, ...}: {
imports = builtins.attrValues {inherit (my-nixpkgs.flakeModules) personal;};
flake.lib = import ./lib {inherit lib;};
@@ -32,24 +28,20 @@
pkgs,
system,
...
- }: {
- packages = let
- pkgs' = pkgs.extend (
- _: _: {
- uncss = inputs.uncss.packages."${system}".default;
- line-awesome-css = my-nixpkgs.packages."${system}".static_css_lineAwesome;
- }
- );
- html = self.lib.pp.html;
- in {
+ }: let
+ pkgs' = pkgs.extend (
+ _: _: {
+ uncss = inputs.uncss.packages."${system}".default;
+ line-awesome-css = my-nixpkgs.packages."${system}".static_css_lineAwesome;
+ }
+ );
+ in {
+ packages = {
default = self'.packages.webpage;
- webpage = import ./default.nix {
- inherit html;
- pkgs = pkgs';
- data = inputs.data.lib.formatWith {
- inherit pkgs;
- markup = html;
- };
+ webpage = pkgs'.callPackage ./default.nix {
+ nixpkgsSrc = inputs.nixpkgs.outPath;
+ src = pkgs'.callPackage ./src.nix {};
+ data = inputs.data.packages."${system}".src;
};
};
};
diff --git a/make.nix b/make.nix
new file mode 100644
index 0000000..d19b7ad
--- /dev/null
+++ b/make.nix
@@ -0,0 +1,21 @@
+{
+ pkgs,
+ dataSrc,
+}: let
+ html = (import ./lib {inherit (pkgs) lib;}).pp.html;
+ data = import dataSrc {
+ inherit pkgs;
+ markup = html;
+ };
+ commonArgs = {
+ inherit data make;
+ inherit (pkgs) lib;
+ inherit html;
+ };
+ make = path: overrides: let
+ f = import path;
+ in
+ f ((builtins.intersectAttrs (builtins.functionArgs f) commonArgs)
+ // overrides);
+in
+ make
diff --git a/src.nix b/src.nix
new file mode 100644
index 0000000..a8c1d74
--- /dev/null
+++ b/src.nix
@@ -0,0 +1,7 @@
+{lib, ...}: let
+ fs = lib.fileset;
+in
+ fs.toSource {
+ root = ./.;
+ fileset = fs.unions [./html ./lib ./css ./static ./make.nix];
+ }
diff --git a/static/robots.txt b/static/robots.txt
new file mode 100644
index 0000000..213a586
--- /dev/null
+++ b/static/robots.txt
@@ -0,0 +1,3 @@
+user-agent: *
+disallow: /static/
+allow: /static/icon.png