blog/flake.nix

80 lines
2.0 KiB
Nix
Raw Normal View History

2023-08-17 14:16:17 +00:00
{
2023-08-17 19:50:16 +00:00
description = "Kristian's Website";
2023-08-17 14:16:17 +00:00
inputs = {
2024-03-02 17:39:38 +00:00
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2023-08-17 14:16:17 +00:00
nostyleplease = {
url = "github:Masellum/hugo-theme-nostyleplease";
flake = false;
};
};
outputs = {
self,
nixpkgs,
nostyleplease,
2024-03-02 18:36:04 +00:00
}: 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);
2023-08-17 23:02:41 +00:00
2024-03-02 18:36:04 +00:00
packages = forAllSystems (system: {
default = pkgs.${system}.stdenv.mkDerivation {
2023-08-17 14:16:17 +00:00
name = "blog";
# Exclude themes and public folder from build sources
2024-03-02 18:36:04 +00:00
src = builtins.filterSource (path: type: !(type == "directory" && (baseNameOf path == "themes" || baseNameOf path == "public"))) ./.;
nativeBuildInputs = with pkgs.${system}; [
hugo
];
2023-08-17 14:16:17 +00:00
# Link theme to themes folder and build
buildPhase = ''
mkdir -p themes
ln -s ${nostyleplease} themes/nostyleplease
2024-03-02 18:36:04 +00:00
hugo --gc --minify
2023-08-17 14:16:17 +00:00
'';
installPhase = ''
2023-08-17 16:55:29 +00:00
cp -r public/. $out
2023-08-17 14:16:17 +00:00
'';
};
2024-03-02 18:36:04 +00:00
});
devShells = forAllSystems (system: {
default = pkgs.${system}.mkShellNoCC {
packages = with pkgs.${system}; [
hugo
];
2023-08-17 14:16:17 +00:00
# Link theme to themes folder
shellHook = ''
2024-03-02 18:36:04 +00:00
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"
2023-08-17 14:16:17 +00:00
'';
};
});
2024-03-02 18:36:04 +00:00
};
2023-08-17 14:16:17 +00:00
}