website/flake.nix

128 lines
3.9 KiB
Nix
Raw Normal View History

2021-03-07 14:36:26 +01:00
{
inputs = {
nixpkgs.url = "nixpkgs";
org-thtml = { url = "github:juanjosegarciaripoll/org-thtml"; flake = false; };
emacs-htmlize = { url = "github:hniksic/emacs-htmlize"; flake = false; };
modus-themes = { url = "github:protesilaos/modus-themes"; flake = false; };
web-mode = { url = "github:fxbois/web-mode"; flake = false; };
hcl-mode = { url = "github:purcell/emacs-hcl-mode"; flake = false; };
yaml-mode = { url = "github:yoshiki/yaml-mode"; flake = false; };
2021-03-07 14:36:26 +01:00
};
outputs = { self
, nixpkgs
, nixng
, org-thtml
, emacs-htmlize
, modus-themes
, web-mode
, hcl-mode
, yaml-mode
, ...
}@inputs:
2021-03-07 14:36:26 +01:00
let
supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
site = pkgs: which:
pkgs.stdenv.mkDerivation {
name = which;
version = "0.1";
src = ./.;
nativeBuildInputs = [ pkgs.utillinux pkgs.emacs ];
buildPhase = ''
export TMPDIR="$(mktemp -d)" HOME=$(pwd)/tmp
emacs -nw --fg-daemon &
timeout 10 bash -c 'until [ -e $TMPDIR/emacs$(id -u) ] ; do sleep 0.1 ; done'
emacsclient -e $'(add-to-list \'load-path "${org-thtml}")'
emacsclient -e $'(add-to-list \'load-path "${modus-themes}")'
emacsclient -e $'(add-to-list \'load-path "${emacs-htmlize}")'
emacsclient -e $'(add-to-list \'load-path "${web-mode}")'
emacsclient -e $'(add-to-list \'load-path "${hcl-mode}")'
emacsclient -e $'(add-to-list \'load-path "${yaml-mode}")'
emacsclient -e '(load-file "./make.el")'
emacsclient -e '(magic_rb/publish-website "${which}")'
emacsclient -e '(kill-emacs)'
find public_html -name 'sitemap.*' -exec rm {} \;
'';
installPhase = ''
mkdir -p $out
cp -r public_html/* $out
'';
};
in
{
redalder = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
in
site pkgs "redalder.org"
);
nixng = forAllSystems (system:
2021-03-07 14:36:26 +01:00
let
pkgs = import nixpkgs { inherit system; };
in
site pkgs "nixng.org"
);
website = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
in
pkgs.runCommandNoCC "website" {}
''
mkdir -p $out/
ln -s ${self.redalder.${system}} $out/redalder
ln -s ${self.nixng.${system}} $out/nixng
''
);
generateCss = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
script = pkgs.writeText "init.el"
''
(add-to-list 'load-path "${modus-themes}")
(add-to-list 'load-path "${emacs-htmlize}")
(require 'org)
(require 'ox)
(require 'ox-html)
(require 'modus-themes)
(load-theme 'modus-operandi t nil)
(org-html-htmlize-generate-css)
(with-current-buffer "*html*"
(write-file (getenv "OUTFILE")))
(kill-emacs)
'';
in
pkgs.writeShellScript "generate-css"
''
export PATH=$PATH:${pkgs.emacs}/bin
export OUTFILE="$(mktemp)" TMPDIR="$(mktemp -d)" HOME=$TMPDIR
emacs -l ${script}
mv $OUTFILE ./assets/css/org.css
rm -r $TMPDIR
''
);
defaultPackage = forAllSystems (system:
self.website.${system}
2021-03-07 14:36:26 +01:00
);
};
}