Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake.nix: add overlay that exposes a resume-building function #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,76 @@ nix build

The built resume will end up in `./result`.

Additionally, this project's flake overlay output exposes the function
`pandocResume.buildResume` for building a resume stored somewhere other than
[the default location](#instructions):

```nix
{
description = "Flake for building my resume";

inputs = { pandoc_resume.url = "github:mszep/pandoc_resume"; };

outputs = { self, nixpkgs, pandoc_resume }:
{
packages.x86_64-linux =
let
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ pandoc_resume.overlays.pandocResume ]; };

myResume = pkgs.pandocResume.buildResume {
# Mandatory.
#
# Must specify a directory containing a resume whose basename
# includes the extension `.md`.
inDir = "${self}/my-resume";

# Optional.
#
# The specified directory must contain the files `<style>.css` and
# `<style>.tex` for each supported style `<style>`.
#
# Defaults to "${pandoc_resume}/styles".
stylesDir = "${self}/my-styles";

# Optional.
#
# Given "my-style", `stylesDir` must contain `my-style.css` and
# `my-style.tex`.
#
# Defaults to "chmduquesne".
style = "my-style";
};
in
{
inherit myResume;
default = myResume;
};
};
}
```

In the example above, you can build your resume by running the following from
your flake's top-level directory (assuming you are on an `x86_64-linux`
system):

```
nix build
```

Or, equivalently:

```
nix build '.#myResume'
```

Or via any valid [flake reference](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references).
For instance, if the flake containing your resume is hosted at
`https://my.git.host/my-flake`, you can build it with:

```
nix build 'git+https://my.git.host/my-flake#myResume'
```

### Troubleshooting

#### Get versions
Expand Down
48 changes: 37 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,47 @@
];
in nixpkgs.lib.subtractLists unsupportedSystems nixpkgs.lib.systems.flakeExposed;

overlay = final: prev: {
pandocResume.buildResume =
{
inDir
, stylesDir ? null
, style ? null
}@args: let
overrides = prev.lib.filterAttrs (_: value: value != null) args;

arg2env = {
inDir = "IN_DIR";
stylesDir = "STYLES_DIR";
style = "STYLE";
};

env =
let
quoteIfNecessary = value: if builtins.isPath value then value else prev.lib.escapeShellArg value;
assign = name: "${arg2env.${name}}=${quoteIfNecessary overrides.${name}}";
in builtins.foldl' (a: name: a ++ [ (assign name) ]) [] (builtins.attrNames overrides);

in final.runCommand "build-resume" {
nativeBuildInputs = with final; [ pandoc texlive.combined.scheme-context ];
} ''
cd ${self}
make OUT_DIR="$out" ${toString env}
'';
};

perSystem = nixpkgs.lib.genAttrs supportedSystems;
pkgsFor = system: import nixpkgs { inherit system; };

buildResumeFor = system:
let pkgs = pkgsFor system;
in pkgs.runCommand "build-resume" {
nativeBuildInputs = with pkgs; [ pandoc texlive.combined.scheme-context ];
} ''
cd ${self}
make OUT_DIR="$out"
'';
pkgsFor = system: import nixpkgs { inherit system; overlays = [ self.overlays.default ]; };
in {
overlays = {
pandocResume = overlay;
default = overlay;
};

packages = perSystem (system:
let
resume = buildResumeFor system;
pkgs = pkgsFor system;
resume = pkgs.pandocResume.buildResume { inDir = "${self}/markdown"; };
in
{
inherit resume;
Expand Down