Fixup flake.nix

Signed-off-by: magic_rb <richard@brezak.sk>
This commit is contained in:
magic_rb 2023-12-30 19:24:24 +01:00
parent 033a14fbf0
commit d704b7a023
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E

389
flake.nix
View file

@ -2,189 +2,240 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
org-thtml = { url = "github:MagicRB/org-thtml"; flake = false; }; org-thtml = {
emacs-htmlize = { url = "github:hniksic/emacs-htmlize"; flake = false; }; url = "github:MagicRB/org-thtml";
modus-themes = { url = "github:protesilaos/modus-themes"; flake = false; }; flake = false;
web-mode = { url = "github:fxbois/web-mode"; flake = false; }; };
hcl-mode = { url = "github:purcell/emacs-hcl-mode"; flake = false; }; emacs-htmlize = {
yaml-mode = { url = "github:yoshiki/yaml-mode"; flake = false; }; url = "github:hniksic/emacs-htmlize";
nix-mode = { url = "github:NixOS/nix-mode"; flake = false; }; flake = false;
magit = { url = "github:magit/magit"; flake = false; }; };
compat = { url = "github:emacs-straight/compat"; flake = false; }; modus-themes = {
dash = { url = "github:magnars/dash.el"; flake = false; }; url = "github:protesilaos/modus-themes";
s-el = { url = "github:magnars/s.el"; flake = false; }; flake = false;
dockerfile-mode = { url = "github:spotify/dockerfile-mode"; flake = false; }; };
org-special-block-extras = { url = "github:alhassy/org-special-block-extras"; flake = false; }; web-mode = {
lf = { url = "github:alhassy/lf"; flake = false; }; 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;
};
nix-mode = {
url = "github:NixOS/nix-mode";
flake = false;
};
magit = {
url = "github:magit/magit";
flake = false;
};
compat = {
url = "github:emacs-straight/compat";
flake = false;
};
dash = {
url = "github:magnars/dash.el";
flake = false;
};
s-el = {
url = "github:magnars/s.el";
flake = false;
};
dockerfile-mode = {
url = "github:spotify/dockerfile-mode";
flake = false;
};
org-special-block-extras = {
url = "github:alhassy/org-special-block-extras";
flake = false;
};
lf = {
url = "github:alhassy/lf";
flake = false;
};
}; };
outputs = { self outputs = {
, nixpkgs self,
, nixng nixpkgs,
, org-thtml nixng,
, emacs-htmlize org-thtml,
, modus-themes emacs-htmlize,
, web-mode modus-themes,
, hcl-mode web-mode,
, yaml-mode hcl-mode,
, nix-mode yaml-mode,
, magit nix-mode,
, compat magit,
, dash compat,
, s-el dash,
, dockerfile-mode s-el,
, org-special-block-extras dockerfile-mode,
, lf org-special-block-extras,
, ... lf,
}@inputs: ...
let } @ inputs: let
inherit (nixpkgs.lib) inherit
genAttrs (nixpkgs.lib)
concatMapStringsSep; genAttrs
concatMapStringsSep
fix
getExe
;
supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ]; supportedSystems = ["x86_64-linux" "i686-linux" "aarch64-linux"];
forAllSystems = f: genAttrs supportedSystems (system: f system); forAllSystems = f: genAttrs supportedSystems (system: f system);
packages = [ packages = [
"modus-themes" "modus-themes"
"org-thtml" "org-thtml"
"emacs-htmlize" "emacs-htmlize"
"magit" "magit"
"web-mode" "web-mode"
"hcl-mode" "hcl-mode"
"yaml-mode" "yaml-mode"
"nix-mode" "nix-mode"
"compat" "compat"
"dash" "dash"
"s-el" "s-el"
"dockerfile-mode" "dockerfile-mode"
"org-special-block-extras" "org-special-block-extras"
"lf" "lf"
]; ];
loadPackages = pkgs: loadPackages = pkgs:
pkgs.writeText "packages.el" pkgs.writeText "packages.el"
((concatMapStringsSep "\n" (x: '' ((concatMapStringsSep "\n" (x: ''
(if (file-exists-p "${inputs.${x}}/lisp") (if (file-exists-p "${inputs.${x}}/lisp")
(add-to-list 'load-path "${inputs.${x}}/lisp") (add-to-list 'load-path "${inputs.${x}}/lisp")
(add-to-list 'load-path "${inputs.${x}}")) (add-to-list 'load-path "${inputs.${x}}"))
'') packages) '')
+ packages)
"\n" + "\n"
+ + (concatMapStringsSep "\n" (x: ''
(concatMapStringsSep "\n" (x: ''
(when (string-match-p "^.*-mode$" "${x}") (when (string-match-p "^.*-mode$" "${x}")
(require '${x})) (require '${x}))
'') packages)); '')
site = pkgs: which: packages));
pkgs.stdenv.mkDerivation { site = pkgs: which:
name = which; pkgs.stdenv.mkDerivation {
version = "0.1"; name = which;
src = ./.; version = "0.1";
nativeBuildInputs = [ pkgs.utillinux pkgs.emacs ]; src = ./.;
nativeBuildInputs = [pkgs.utillinux pkgs.emacs];
# xvfb-run -s '-screen 0 800x600x24' make test # xvfb-run -s '-screen 0 800x600x24' make test
buildPhase = '' buildPhase = ''
export TMPDIR="$(mktemp -d)" HOME=$(pwd)/tmp export TMPDIR="$(mktemp -d)" HOME=$(pwd)/tmp
emacs -nw --fg-daemon --debug-init & emacs -nw --fg-daemon --debug-init &
timeout 10 bash -c 'until [ -e $TMPDIR/emacs$(id -u) ] ; do sleep 0.1 ; done' timeout 10 bash -c 'until [ -e $TMPDIR/emacs$(id -u) ] ; do sleep 0.1 ; done'
emacsclient -e $'(load-file "${loadPackages pkgs}")' emacsclient -e $'(load-file "${loadPackages pkgs}")'
emacsclient -e $'(add-to-list \'load-path "'"$(pwd)"'/lisp")' emacsclient -e $'(add-to-list \'load-path "'"$(pwd)"'/lisp")'
emacsclient -e '(load-file "./make.el")' emacsclient -e '(load-file "./make.el")'
emacsclient -e '(magic_rb/publish-website "${which}")' emacsclient -e '(magic_rb/publish-website "${which}")'
emacsclient -e '(kill-emacs)' emacsclient -e '(kill-emacs)'
find public_html -name 'sitemap.*' -exec rm {} \; find public_html -name 'sitemap.*' -exec rm {} \;
''; '';
installPhase = '' installPhase = ''
mkdir -p $out mkdir -p $out
cp -r public_html/* $out cp -r public_html/* $out
''; '';
};
in
{
redalder = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
in
site pkgs "redalder.org"
);
nixng = forAllSystems (system:
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"
''
(load-file "${loadPackages pkgs}")
(require 'org)
(require 'ox)
(require 'ox-html)
(require 'modus-themes)
(defface modus-themes-cyan-subtle
'((t :inherit modus-themes-subtle-cyan))
"")
(load-theme 'modus-vivendi 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 ${builtins.trace "modus: ${modus-themes}" script} --debug-init
mv $OUTFILE ./assets/css/org.css
rm -r $TMPDIR
''
);
defaultPackage = forAllSystems (system:
self.website.${system}
);
devShells = forAllSystems (system:
let pkgs = import nixpkgs { inherit system; };
in
{
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
httplz
];
};
}
);
}; };
in {
apps = forAllSystems (
system: let
pkgs = import nixpkgs {inherit system;};
in {
live-server = {
type = "app";
program = toString (pkgs.writeShellScript "live-server.sh" ''
nix build .#
${getExe pkgs.nodePackages.live-server} result/redalder "$@"
'');
};
generateCSS = let
script =
pkgs.writeText "init.el"
''
(load-file "${loadPackages pkgs}")
(require 'org)
(require 'ox)
(require 'ox-html)
(require 'modus-themes)
(defface modus-themes-cyan-subtle
'((t :inherit modus-themes-subtle-cyan))
"")
(load-theme 'modus-vivendi t nil)
(org-html-htmlize-generate-css)
(with-current-buffer "*html*"
(write-file (getenv "OUTFILE")))
(kill-emacs)
'';
in {
type = "app";
program = toString (
pkgs.writeShellScript "generate-css"
''
export PATH=$PATH:${pkgs.emacs}/bin
export OUTFILE="$(mktemp)" TMPDIR="$(mktemp -d)" HOME=$TMPDIR
emacs -l ${builtins.trace "modus: ${modus-themes}" script} --debug-init
mv $OUTFILE ./assets/css/org.css
rm -r $TMPDIR
''
);
};
}
);
packages = forAllSystems (
system: let
pkgs = import nixpkgs {inherit system;};
in
fix (this: {
redalder = site pkgs "redalder.org";
nixng = site pkgs "nixng.org";
website =
pkgs.runCommandNoCC "website" {}
''
mkdir -p $out/
ln -s ${this.redalder} $out/redalder
ln -s ${this.nixng} $out/nixng
'';
default = this.website;
})
);
devShells = forAllSystems (
system: let
pkgs = import nixpkgs {inherit system;};
in {
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
httplz
alejandra
];
};
}
);
};
} }