Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Lehmanator committed Jun 17, 2024
1 parent 939ff2d commit e365598
Show file tree
Hide file tree
Showing 20 changed files with 460 additions and 313 deletions.
138 changes: 87 additions & 51 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
{
description = "Personal resume built with jsonresume in Nix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
hercules-ci-effects.url = "github:hercules-ci/hercules-ci-effects";
mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
hercules-ci-effects.url = "github:hercules-ci/hercules-ci-effects";
mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix";
haumea.url = "github:nix-community/haumea";
incl.url = "github:divnix/incl";
haumea.url = "github:nix-community/haumea";
incl.url = "github:divnix/incl";
#std.url = "github:divnix/std";
devshell = { url = "github:numtide/devshell"; inputs.nixpkgs.follows = "nixpkgs"; };
nix2container = { url = "github:nlewo/nix2container"; inputs.nixpkgs.follows = "nixpkgs"; };
treefmt-nix = { url = "github:numtide/treefmt-nix"; inputs.nixpkgs.follows = "nixpkgs"; };
pyproject-nix = { url = "github:nix-community/pyproject.nix"; inputs.nixpkgs.follows = "nixpkgs"; };
rendercv = { url = "github:Lehmanator/rendercv"; flake = false; };
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
nix2container = {
url = "github:nlewo/nix2container";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pyproject-nix = {
url = "github:nix-community/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
rendercv = {
url = "github:Lehmanator/rendercv";
flake = false;
};
#"github:sinaatalay/rendercv";
};
outputs = { self, nixpkgs, flake-parts, haumea, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs self; } {
imports = [ ./parts ];
outputs = {
self,
nixpkgs,
flake-parts,
haumea,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs self;} {
imports = [./parts];
debug = true;
perSystem = { config, lib, pkgs, ... }: {
perSystem = {
config,
lib,
pkgs,
...
}: {
formatter = pkgs.alejandra;
#overlayAttrs = { inherit (packages) jsonresume-data; };
apps = rec {
Expand Down Expand Up @@ -85,39 +111,48 @@
packages = let
# TODO: Add attr `passthru.updaterScript` to make updating source revisions/hashes easier?
# TODO: Add more themes
jsonresume = (haumea.lib.load {
src = ./packages/jsonresume;
loader = haumea.lib.loaders.callPackage;
inputs = {
lib = lib // builtins // self.lib;
src = ./src/jsonresume.nix;
inherit (pkgs)
buildNpmPackage
fetchFromGitHub
formats
python3
resumed puppeteer-cli
symlinkJoin stdenv runCommand runCommandLocal writeText writeTextFile
jsonresume = haumea.lib.load {
src = ./packages/jsonresume;
loader = haumea.lib.loaders.callPackage;
inputs = {
lib = lib // builtins // self.lib;
src = ./src/jsonresume.nix;
inherit
(pkgs)
buildNpmPackage
fetchFromGitHub
formats
python3
resumed
puppeteer-cli
symlinkJoin
stdenv
runCommand
runCommandLocal
writeText
writeTextFile
;
};
});
jsonresume-themes = (lib.mapAttrs' (n: v: lib.nameValuePair "jsonresume-theme-${n}" v) jsonresume.themes);
jsonresume-formats = (lib.mapAttrs' (n: v: lib.nameValuePair "jsonresume-format-${n}" v) jsonresume.formats);
jsonresume-builders = {
jsonresume-builder-pdf = pkgs.writeShellScriptBin "jsonresume-builder-pdf" ''
if [[ $# -gt 0 ]]; then
outfile=$1
else
outfile='./jsonresume.pdf'
fi
${lib.getExe pkgs.puppeteer-cli} print \
${config.packages.jsonresume-format-html}/index.html \
$outfile
'';
};
};
jsonresume-themes = lib.mapAttrs' (n: v: lib.nameValuePair "jsonresume-theme-${n}" v) jsonresume.themes;
jsonresume-formats = lib.mapAttrs' (n: v: lib.nameValuePair "jsonresume-format-${n}" v) jsonresume.formats;
jsonresume-builders = {
jsonresume-builder-pdf = pkgs.writeShellScriptBin "jsonresume-builder-pdf" ''
if [[ $# -gt 0 ]]; then
outfile=$1
else
outfile='./jsonresume.pdf'
fi
${lib.getExe pkgs.puppeteer-cli} print \
${config.packages.jsonresume-format-html}/index.html \
$outfile
'';
};
in
jsonresume-builders //
jsonresume-themes // jsonresume-formats // {
jsonresume-builders
// jsonresume-themes
// jsonresume-formats
// {
inherit (pkgs) resumed puppeteer-cli;
#wkhtmltopdf pnmp-lock-export corepack_latest;
inherit (pkgs.python3Packages) weasyprint;
Expand All @@ -131,16 +166,17 @@
rendercv = let
src-cfg = inputs.rendercv.outPath + "/pyproject.toml";
cfg-orig = lib.importTOML src-cfg;
cfg-over = { build-system.requires = [ "hatchling>=1.21.1" ]; };
cfg-over = {build-system.requires = ["hatchling>=1.21.1"];};
project = inputs.pyproject-nix.lib.project.loadPyproject {
pyproject = lib.recursiveUpdate cfg-orig cfg-over;
projectRoot = inputs.rendercv.outPath;
};
in pkgs.callPackage ./packages/rendercv {
inherit (inputs) rendercv;
inherit (project.renderers) buildPythonPackage;
python3 = pkgs.callPackage ./packages/rendercv/python.nix { };
};
in
pkgs.callPackage ./packages/rendercv {
inherit (inputs) rendercv;
inherit (project.renderers) buildPythonPackage;
python3 = pkgs.callPackage ./packages/rendercv/python.nix {};
};
#resume-cli = pkgs.callPackage ./packages/resume-cli {};

# TODO: Wrap with webserver?
Expand Down
81 changes: 45 additions & 36 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
{ self, super, root
, lib
# , pkgs
, ...
}:
let
l = lib // builtins;
in
{
getFileExtension = file: lib.last (lib.splitString "." (builtins.baseNameOf file));
getFileBasename = file: builtins.head (lib.splitString "." (builtins.baseNameOf file));
importData = src:
if ( (lib.hasSuffix ".yaml" src) || (lib.hasSuffix ".yml" src)) then lib.importJSON src
else if lib.hasSuffix ".json" src then lib.importJSON src
else if lib.hasSuffix ".toml" src then lib.importTOML src
else if lib.hasSuffix ".nix" src then import src
self,
super,
root,
lib,
# , pkgs
...
}: let
l = lib // builtins;
in {
getFileExtension = file: lib.last (lib.splitString "." (builtins.baseNameOf file));
getFileBasename = file: builtins.head (lib.splitString "." (builtins.baseNameOf file));
importData = src:
if ((lib.hasSuffix ".yaml" src) || (lib.hasSuffix ".yml" src))
then lib.importJSON src
else if lib.hasSuffix ".json" src
then lib.importJSON src
else if lib.hasSuffix ".toml" src
then lib.importTOML src
else if lib.hasSuffix ".nix" src
then import src
else import src;

# --- Data Manipulation ----------------------------------
Expand All @@ -23,18 +28,19 @@ in
# - Auto add project link to jsonresume data?

# Replaces the theme in a resume.
replaceTheme = src: theme: (self.importData src) // (lib.setAttrByPath ["meta" "theme"] theme);
replaceTheme = src: theme: (self.importData src) // (lib.setAttrByPath ["meta" "theme"] theme);
version = {
get = data: lib.removePrefix "v" data.meta.version;
increment = data: let
old = self.version.get data;
in lib.attrsets.recursiveUpdate {
meta = {
#lastModified = "";
#canonical = "https://raw.githubusercontent.com/${u}/${r}/${b}/${p}";
version = "${lib.versions.majorMinor old}.${(lib.versions.patch old)+1}";
in
lib.attrsets.recursiveUpdate {
meta = {
#lastModified = "";
#canonical = "https://raw.githubusercontent.com/${u}/${r}/${b}/${p}";
version = "${lib.versions.majorMinor old}.${(lib.versions.patch old) + 1}";
};
};
};
};

# --- Conversion Process ---------------------------------
Expand All @@ -44,23 +50,26 @@ in

# TODO: Insert wrappers here to pretty-print
convertFile = src: dst: self.writeFile dst (self.importData src);

# --- Mappers -------------------------------------------
# TODO: Make similar for pretty-print wrapper
# Map file extensions to associated generator
mapToGenerator = ext: ({
# lib.generators
nix = lib.generators.toPretty; # Pretty-printed Nix
lua = lib.generators.toLua; # Pretty-printed Lua
dhall = lib.generators.toDhall; # Not pretty-printed
dconf = lib.generators.toDconfINI; # Broken, unknown reason, probably same as INI
plist = lib.generators.toPlist; # Pretty-printed
ini = lib.generators.toINI; # Broken, attrsets not supported
gitconfig = lib.generators.toGitINI; # Broken, attrsets not supported
json = lib.generators.toJSON; # Not pretty-printed, wrap with jq to format
kv = lib.generators.toKeyValue; # Broken, attrsets not supported
yaml = lib.generators.toYAML; # Same as JSON, wrapper with json2yaml needed
}).${ext} or lib.generators.toJSON;
mapToGenerator = ext:
{
# lib.generators
nix = lib.generators.toPretty; # Pretty-printed Nix
lua = lib.generators.toLua; # Pretty-printed Lua
dhall = lib.generators.toDhall; # Not pretty-printed
dconf = lib.generators.toDconfINI; # Broken, unknown reason, probably same as INI
plist = lib.generators.toPlist; # Pretty-printed
ini = lib.generators.toINI; # Broken, attrsets not supported
gitconfig = lib.generators.toGitINI; # Broken, attrsets not supported
json = lib.generators.toJSON; # Not pretty-printed, wrap with jq to format
kv = lib.generators.toKeyValue; # Broken, attrsets not supported
yaml = lib.generators.toYAML; # Same as JSON, wrapper with json2yaml needed
}
.${ext}
or lib.generators.toJSON;

# mapToFormat = ext: (({
# # pkgs.formats
Expand Down
6 changes: 5 additions & 1 deletion packages/_sources/generated.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# This file was generated by nvfetcher, please do not modify it manually.
{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }:
{
fetchgit,
fetchurl,
fetchFromGitHub,
dockerTools,
}: {
mkdocs-macros-plugin = {
pname = "mkdocs-macros-plugin";
version = "1.0.5";
Expand Down
2 changes: 1 addition & 1 deletion packages/jsonresume-data.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ writeTextFile }:
{writeTextFile}:
# TODO: Handle validation against schema
writeTextFile {
name = "resume.json";
Expand Down
46 changes: 24 additions & 22 deletions packages/jsonresume/formats/html.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{ lib
, stdenv
, resumed
, self, super, root
, src
, ...
}:
let
{
lib,
stdenv,
resumed,
self,
super,
root,
src,
...
}: let
jsonresume-theme-all = root.themes.all;
data = import src;
inherit (data.meta) theme version;
in
stdenv.mkDerivation {
inherit (data.meta) version;
pname = "jsonresume-html";
src = ../../../src;
in
stdenv.mkDerivation {
inherit (data.meta) version;
pname = "jsonresume-html";
src = ../../../src;

# propagatedBuildInputs = [super.json];
buildInputs = [jsonresume-theme-all resumed];
buildPhase = ''
mkdir -p $out
${lib.getExe resumed} render ${super.json} \
--theme ${jsonresume-theme-all}/lib/node_modules/jsonresume-theme-${theme}/index.js \
--output $out/index.html
'';
}
# propagatedBuildInputs = [super.json];
buildInputs = [jsonresume-theme-all resumed];
buildPhase = ''
mkdir -p $out
${lib.getExe resumed} render ${super.json} \
--theme ${jsonresume-theme-all}/lib/node_modules/jsonresume-theme-${theme}/index.js \
--output $out/index.html
'';
}
25 changes: 14 additions & 11 deletions packages/jsonresume/formats/json.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{ lib
, stdenv
, writeText
, src ? ./src/jsonresume.nix
, self, super, root
, ...
}:
let
{
lib,
stdenv,
writeText,
src ? ./src/jsonresume.nix,
self,
super,
root,
...
}: let
basename = builtins.head (lib.splitString "." (builtins.baseNameOf src));
in
writeText "${basename}.json" (lib.generators.toJSON {} ((import src) // {
"$schema" = "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json";
}))
writeText "${basename}.json" (lib.generators.toJSON {} ((import src)
// {
"$schema" = "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json";
}))
20 changes: 11 additions & 9 deletions packages/jsonresume/formats/nix.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{ lib
, stdenv
, writeText
, src ? ./src/jsonresume.nix
, self, super, root
, ...
}:
let
{
lib,
stdenv,
writeText,
src ? ./src/jsonresume.nix,
self,
super,
root,
...
}: let
basename = builtins.head (lib.splitString "." (builtins.baseNameOf src));
in
writeText "${basename}.nix" (lib.generators.toPretty {} (import src))
writeText "${basename}.nix" (lib.generators.toPretty {} (import src))
Loading

0 comments on commit e365598

Please sign in to comment.