-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
85 lines (78 loc) · 2.37 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{
description = "nix-org-export";
inputs = {
emacs.url = "github:nix-community/emacs-overlay";
nixpkgs.url = "github:NixOS/nixpkgs";
};
outputs = inputs @ {
self,
nixpkgs,
...
}: let
supportedSystems = nixpkgs.lib.systems.flakeExposed;
perSystem = nixpkgs.lib.genAttrs supportedSystems;
pkgsFor = system:
import nixpkgs {
inherit system;
overlays = [inputs.emacs.overlay];
};
customEmacsFor = system:
(pkgsFor system).emacsWithPackagesFromUsePackage {
package = (pkgsFor system).emacs;
config = "";
extraEmacsPackages = epkgs: [
epkgs.org
];
};
elispScriptFor = system:
(pkgsFor system).writeTextFile {
name = "org-export.el";
text = ''
(message "Exporting org to pdf...")
(require 'org)
(find-file (getenv "NIX_ORG_EXPORT_FILE"))
(if (getenv "NIX_ORG_EXPORT_OUT")
(copy-file (org-latex-export-to-pdf) (getenv "NIX_ORG_EXPORT_OUT") 't)
(org-latex-export-to-pdf))
(message "Exporting org to pdf done!")
'';
};
in rec {
exportOrgFor = system: src: file:
(pkgsFor system).stdenv.mkDerivation {
name = "exported.pdf";
inherit src;
buildPhase = ''
cp -r $src .
stat ${file}
export NIX_ORG_EXPORT_OUT="$(mktemp out.XXXXXX)"
${self.apps.${system}.org2pdf.program} "${file}"
'';
installPhase = ''
cp $NIX_ORG_EXPORT_OUT $out
'';
};
apps = perSystem (system: {
default = self.apps.${system}.org2pdf;
org2pdf = {
type = "app";
program =
((pkgsFor system).writeShellScript "org2pdf.sh" ''
export PATH="${(pkgsFor system).texlive.combined.scheme-full}/bin:${(pkgsFor system).git}/bin"
if (($# == 1))
then
export NIX_ORG_EXPORT_FILE="$1"
${customEmacsFor system}/bin/emacs --batch --no-init --load ${elispScriptFor system}
else
echo "Usage: $0 <org-file>"
exit 1
fi
'')
.outPath;
};
});
# Example how to use `exportOrgFor`
readmeExported = perSystem (system: exportOrgFor system ./. "README.org");
formatter = perSystem (system: nixpkgs.legacyPackages.${system}.alejandra);
};
}