Skip to content

Commit

Permalink
feat(nix): expose buildResume function
Browse files Browse the repository at this point in the history
via a new `overlays` output.  This function is used for building resumes
stored in arbitrary locations.
  • Loading branch information
tomeon committed Feb 14, 2023
1 parent c5d0c4b commit e0b513e
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 10 deletions.
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
45 changes: 35 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,43 @@
];
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
pkgs = pkgsFor system;
Expand Down

0 comments on commit e0b513e

Please sign in to comment.