blog/flake.nix

126 lines
3.3 KiB
Nix
Raw Permalink Normal View History

2024-05-22 22:17:41 -07:00
{
2024-10-31 17:51:52 -07:00
description = "gradient ascent";
2024-05-22 22:17:41 -07:00
nixConfig = {
allow-import-from-derivation = "true";
bash-prompt = "[hakyll-nix]λ ";
extra-substituters = [
"https://cache.iog.io"
];
extra-trusted-public-keys = [
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
];
};
inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
2024-10-31 17:51:52 -07:00
outputs =
{
self,
nixpkgs,
flake-utils,
haskellNix,
}:
flake-utils.lib.eachDefaultSystem (
system:
2024-05-22 22:17:41 -07:00
let
2024-05-23 23:14:18 -07:00
hls = pkgs.haskell-language-server;
2024-10-31 17:51:52 -07:00
overlays = [
haskellNix.overlay
2024-05-22 22:17:41 -07:00
(final: prev: {
hakyllProject = final.haskell-nix.project' {
src = ./ssg;
compiler-nix-name = "ghc948";
2024-10-31 17:51:52 -07:00
modules = [ { doHaddock = false; } ];
2024-05-22 22:17:41 -07:00
shell.buildInputs = [
hakyll-site
2024-05-23 23:14:18 -07:00
hls
2024-10-31 22:41:33 -07:00
nodejs
pkgs.nodePackages.rollup
pkgs.nodePackages.npm
pkgs.node2nix
2024-05-22 22:17:41 -07:00
];
shell.tools = {
cabal = "latest";
hlint = "latest";
haskell-language-server = "latest";
};
};
})
];
pkgs = import nixpkgs {
inherit overlays system;
inherit (haskellNix) config;
};
2024-10-31 22:41:33 -07:00
nodejs = pkgs.nodejs;
nodeDeps = (pkgs.callPackage ./nix { inherit pkgs nodejs system; }).nodeDependencies;
2024-10-31 17:51:52 -07:00
flake = pkgs.hakyllProject.flake { };
2024-05-22 22:17:41 -07:00
executable = "ssg:exe:hakyll-site";
hakyll-site = flake.packages.${executable};
website = pkgs.stdenv.mkDerivation {
name = "website";
2024-10-31 22:41:33 -07:00
buildInputs = [
nodejs
pkgs.nodePackages.rollup
];
2024-05-22 22:17:41 -07:00
src = pkgs.nix-gitignore.gitignoreSourcePure [
./.gitignore
".git"
".github"
] ./.;
# LANG and LOCALE_ARCHIVE are fixes pulled from the community:
# https://github.com/jaspervdj/hakyll/issues/614#issuecomment-411520691
# https://github.com/NixOS/nix/issues/318#issuecomment-52986702
# https://github.com/MaxDaten/brutal-recipes/blob/source/default.nix#L24
LANG = "en_US.UTF-8";
2024-10-31 17:51:52 -07:00
LOCALE_ARCHIVE = pkgs.lib.optionalString (
pkgs.buildPlatform.libc == "glibc"
) "${pkgs.glibcLocales}/lib/locale/locale-archive";
2024-05-22 22:17:41 -07:00
buildPhase = ''
# remove the node_modules symlink
rm -rf node_modules
2024-05-22 22:17:41 -07:00
${flake.packages.${executable}}/bin/hakyll-site build --verbose
2024-10-31 22:41:33 -07:00
ln -s ${nodeDeps}/lib/node_modules ./node_modules
export PATH="${nodeDeps}/bin:$PATH"
rollup -c
2024-05-22 22:17:41 -07:00
'';
installPhase = ''
mkdir -p "$out/dist"
cp -a dist/. "$out/dist"
'';
};
2024-10-31 17:51:52 -07:00
in
flake
// {
2024-05-22 22:17:41 -07:00
apps = {
default = flake-utils.lib.mkApp {
drv = hakyll-site;
exePath = "/bin/hakyll-site";
};
};
packages = {
2024-10-31 22:41:33 -07:00
inherit hakyll-site website nodeDeps;
2024-05-22 22:17:41 -07:00
default = website;
};
2024-10-31 17:51:52 -07:00
formatter = pkgs.nixfmt-rfc-style;
2024-05-22 22:17:41 -07:00
}
);
}