Skip to content

Commit

Permalink
Merge pull request #78 from charlesbaynham/nix
Browse files Browse the repository at this point in the history
Define environment as nix flake and build in GitHub workflow
  • Loading branch information
kudrykv authored Mar 16, 2023
2 parents e4b39ec + 1ae1bec commit a321d94
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Build 2023"
on:
pull_request:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v19
- name: Build PDFs
run: nix build
- name: Copy PDFs
run: cp result/*.pdf .
- name: Output PDFs
uses: actions/upload-artifact@v3
with:
name: result
path: ./*.pdf
if-no-files-found: error

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.pdf
.vscode
result
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ If you encounter any problems related to '.sty' files you likely need to
install some Latex related dependencies. Copying the error and search using
your favorite search engine should get you on track to resolving the
dependency issues. All the best!

### Alternative install

Instead of installing the dependencies manually, this repository is defined as a Nix flake which specifies fixed versions of all the required dependencies.

1. [Install Nix](https://nixos.org/download.html)
2. Build a planner pdf using `nix build`
3. Or, if you want to develop the code, enter a shell with all the dependencies present using `nix develop`

# Preview examples
<img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/01_annual.png" width="419"><img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/02_quarter.png" width="419"><img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/03_month.png" width="419"><img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/04_week.png" width="419"><img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/05_day.png" width="419"><img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/06_day_notes.png" width="419"><img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/07_day_reflect.png" width="419"><img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/08_todos_index.png" width="419"><img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/09_todos_page.png" width="419"><img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/10_notes_index.png" width="419"><img src="https://github.com/kudrykv/latex-yearly-planner/blob/main/examples/pictures/sn_a5x.planner/11_notes_page.png" width="419">
41 changes: 41 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
description = "Install latex reqs";

inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};

# Build the plannergen as a binary using fixed input versions
# This means that the subsequent pdf generation does not need internet access
# and is therefore a "pure" nix output
plannergen = pkgs.buildGoModule {
src = self;
name = "plannergen";
vendorSha256 = "sha256:F3cln/CPSAonLTCvjSCMHhrzEQgWIOWw0vWwb6BG+pI=";
};

# Go is packaged into the devShell for developing the package,
# but is not used for the "nix build" outputs - these use the pre-built
# binary instead
goDeps = [
pkgs.go
];

# Dependencies for building the latex files
texDeps = with pkgs; [
libuuid # for the "rev" utility
ps # Used by build.sh
python3 # used in the build scripts
(texlive.combine {
inherit (texlive)
metafont
scheme-basic
xcolor
pgf
wrapfig
makecell
multirow
leading
marginnote
adjustbox
multido
varwidth
blindtext
setspace
ifmtarg
extsizes
dashrule
;
})
];
in
rec
{
devShell = pkgs.mkShell {
shellHook = ''
unset GOPATH
unset GOROOT
unset GO_VERSION
'';
buildInputs = [
pkgs.nixpkgs-fmt # utility for pretty formatting of .nix files
] ++ goDeps ++ texDeps;
};

defaultPackage = pdfs;

pdfs = pkgs.stdenv.mkDerivation
{
name = "pdfs";
# Minimal set of dependencies to build the pdfs
# Latex, "rev" and the built plannergen binary
buildInputs = texDeps ++ [ plannergen ];
PLANNER_YEAR = 2023;
src = "${self}";
buildCommand = ''
cp -r $src/* .
patchShebangs .
chmod -R 770 *
chmod +x *.sh
PLANNERGEN_BINARY=plannergen eval $PWD/build.sh
mkdir $out
cp *.pdf $out/.
'';
};

}
);
}
11 changes: 9 additions & 2 deletions single.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

set -eo pipefail

if [ -z "$PLANNERGEN_BINARY" ]; then
export GO_CMD="go run cmd/plannergen/plannergen.go"
else
export GO_CMD="$PLANNERGEN_BINARY"
echo "Building using plannergen binary at \"${PLANNERGEN_BINARY}\""
fi

if [ -z "$PREVIEW" ]; then
go run cmd/plannergen/plannergen.go --config "${CFG}"
eval $GO_CMD --config "${CFG}"
else
go run cmd/plannergen/plannergen.go --preview --config "${CFG}"
eval $GO_CMD --preview --config "${CFG}"
fi


Expand Down

0 comments on commit a321d94

Please sign in to comment.