website/flake.nix
2023-11-16 11:01:43 +01:00

91 lines
2.5 KiB
Nix

{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
parts.url = "github:hercules-ci/flake-parts";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
haskell-flake.url = "github:srid/haskell-flake";
devshell.url = "github:numtide/devshell";
};
outputs = inputs:
inputs.parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux"];
imports = [
inputs.haskell-flake.flakeModule
inputs.pre-commit-hooks.flakeModule
inputs.devshell.flakeModule
];
perSystem = {
pkgs,
lib,
config,
...
}: {
devshells.default = let
port = 8000;
in {
commands = [
{
name = "fmt";
help = "format all";
command = "pre-commit run --all";
}
{
name = "watch";
help = "watch website";
command = "cabal run website -- watch --port ${toString port}";
}
{
name = "open";
help = "open website";
command = "${lib.getExe' pkgs.xdg-utils "xdg-open"} http://localhost:${toString port}";
}
];
devshell = {
startup = {
pre-commit.text = config.pre-commit.installationScript;
};
packagesFrom = [config.devShells.ghc94];
packages = [
pkgs.static-web-server
];
};
};
haskellProjects.ghc94 = {
packages = {};
settings = {
website.haddock = true;
};
};
# haskell-flake doesn't set the default package, but you can do it here.
packages.generator = config.packages.ghc94-website;
packages.default = pkgs.stdenv.mkDerivation {
name = "website-built";
src = ./.;
LC_ALL = "C.UTF-8";
buildPhase = ''
${lib.getExe' config.packages.ghc94-website "site"} build
'';
installPhase = ''
mkdir $out
cp -r _site/* $out
'';
};
pre-commit = {
check.enable = true;
settings.hooks = {
cabal-fmt.enable = true;
fourmolu.enable = true;
hlint.enable = true;
alejandra.enable = true;
statix.enable = true;
deadnix.enable = true;
};
};
};
};
}