blog/flake.nix

80 lines
2.0 KiB
Nix

{
description = "Kristian's Website";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nostyleplease = {
url = "github:Masellum/hugo-theme-nostyleplease";
flake = false;
};
};
outputs = {
self,
nixpkgs,
nostyleplease,
}: let
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
in {
formatter = forAllSystems (system: pkgs.${system}.alejandra);
packages = forAllSystems (system: {
default = pkgs.${system}.stdenv.mkDerivation {
name = "blog";
# Exclude themes and public folder from build sources
src = builtins.filterSource (path: type: !(type == "directory" && (baseNameOf path == "themes" || baseNameOf path == "public"))) ./.;
nativeBuildInputs = with pkgs.${system}; [
hugo
];
# Link theme to themes folder and build
buildPhase = ''
mkdir -p themes
ln -s ${nostyleplease} themes/nostyleplease
hugo --gc --minify
'';
installPhase = ''
cp -r public/. $out
'';
};
});
devShells = forAllSystems (system: {
default = pkgs.${system}.mkShellNoCC {
packages = with pkgs.${system}; [
hugo
];
# Link theme to themes folder
shellHook = ''
if [ ! -d ./themes ]; then
mkdir ./themes
fi
if [ ! -d ./themes/nostyleplease ]; then
ln -s ${nostyleplease} ./themes/nostyleplease
fi
alias new='hugo new content'
alias serve='hugo serve --buildDrafts'
greeter_text="
* Create new content with:
new posts/name-of-post.md
* Render drafts with:
serve
"
echo "$greeter_text"
'';
};
});
};
}