Skip to content

Commit 06c5be4

Browse files
committedSep 17, 2022
init
0 parents  commit 06c5be4

File tree

5 files changed

+816
-0
lines changed

5 files changed

+816
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
result*

‎LICENSE

+674
Large diffs are not rendered by default.

‎README.org

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
* =nix-org-export=
2+
3+
Use =nix-org-export= to export org files to PDFs using =(org-latex-export-to-pdf)=.
4+
5+
** Usage
6+
7+
*** Using flakes
8+
9+
- Ensure you have flakes enabled
10+
- Add =github:t4ccer/nix-org-export= to your inputs
11+
- Call =exportOrgFor "your-system" ./path-to-org-file=
12+
13+
** Example
14+
15+
Example exposes README of your project in PDF as a flake output.
16+
17+
#+begin_src nix
18+
{
19+
description = "nix-org-export example";
20+
inputs.nix-org-export.url = "github:t4ccer/nix-org-export";
21+
outputs = { nix-org-export, ... }: {
22+
readmeExported = nix-org-export.exportOrgFor "x86_64-linux" ./README.org;
23+
};
24+
}
25+
#+end_src
26+
27+
** License
28+
29+
Copyright (C) 2022 Tomasz Maciosowski (t4ccer)
30+
31+
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
32+
33+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
34+
35+
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

‎flake.lock

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
description = "nix-org-export";
3+
4+
inputs = {
5+
emacs.url = "github:nix-community/emacs-overlay";
6+
nixpkgs.url = "github:NixOS/nixpkgs";
7+
};
8+
9+
outputs = inputs @ {
10+
self,
11+
nixpkgs,
12+
...
13+
}: let
14+
supportedSystems = nixpkgs.lib.systems.flakeExposed;
15+
perSystem = nixpkgs.lib.genAttrs supportedSystems;
16+
pkgsFor = system:
17+
import nixpkgs {
18+
inherit system;
19+
overlays = [inputs.emacs.overlay];
20+
};
21+
22+
customEmacsFor = system:
23+
(pkgsFor system).emacsWithPackagesFromUsePackage {
24+
package = (pkgsFor system).emacs;
25+
config = "";
26+
extraEmacsPackages = epkgs: [
27+
epkgs.org
28+
];
29+
};
30+
31+
elispScriptFor = system:
32+
(pkgsFor system).writeTextFile {
33+
name = "org-export.el";
34+
text = ''
35+
(message "Exporting org to pdf...")
36+
(setenv "PATH" (concat (getenv "PATH") ":${(pkgsFor system).texlive.combined.scheme-full}/bin"))
37+
(require 'org)
38+
(find-file "file.org")
39+
(org-latex-export-to-pdf)
40+
(message "Exporting org to pdf done!")
41+
'';
42+
};
43+
in rec {
44+
exportOrgFor = system: file:
45+
derivation {
46+
name = "exported.pdf";
47+
inherit system;
48+
builder = "${(pkgsFor system).bash}/bin/bash";
49+
args = [
50+
"-c"
51+
''
52+
${(pkgsFor system).coreutils}/bin/cp ${file} file.org
53+
${customEmacsFor system}/bin/emacs --batch --no-init --load ${elispScriptFor system}
54+
${(pkgsFor system).coreutils}/bin/mv file.pdf $out
55+
''
56+
];
57+
};
58+
59+
# Example how to use `exportOrgFor`
60+
readmeExported = perSystem (system: exportOrgFor system ./README.org);
61+
62+
formatter = perSystem (system: nixpkgs.legacyPackages.${system}.alejandra);
63+
};
64+
}

0 commit comments

Comments
 (0)
Please sign in to comment.