homepage/flake.nix
2022-02-27 07:40:01 +01:00

97 lines
2.9 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
description = "Angestöpselt Homepage";
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = {self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
nodejs = pkgs.nodejs-16_x;
nodePackages = import ./nix/default.nix { inherit pkgs system nodejs; };
nodeDependencies = nodePackages.nodeDependencies.override {
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ vips ];
dontNpmInstall = true;
};
site = pkgs.stdenv.mkDerivation {
name = "angestoepselt-site";
src = self;
buildInputs = [ nodejs nodeDependencies ];
buildPhase = ''
npm run build
'';
installPhase = ''
mv dist $out
'';
};
container = pkgs.dockerTools.buildImage {
name = "angestoepselt-site";
tag = "latest";
config = {
Cmd = [
"${pkgs.caddy}/bin/caddy"
"file-server"
"-root" "${site}"
];
};
};
in
rec {
packages = {
inherit site container;
# This package isn't actually the fully-built site, but rather a
# derivation that contains the relevant programs (with correctly set up
# environment) to develop and build the site. It can either be used with
# `nix develop` see the repository's readme for details or compiled
# with `nix build`. The latter will output a folder which contains node
# and npm binaries that can be used in an IDE.
devEnv = pkgs.symlinkJoin {
name = "devEnv";
buildInputs = [ pkgs.makeWrapper ];
paths = [ nodejs nodeDependencies ];
postBuild = ''
wrapProgram "$out/bin/node" \
--prefix PATH : "$out/lib/node_modules/.bin" \
--prefix NODE_PATH : "$out/lib/node_modules"
'';
shellHook = ''
export NODE_PATH=${nodeDependencies}/lib/node_modules
export PATH="${nodeDependencies}/bin:${nodejs}/bin:${pkgs.nodePackages.npm-check-updates}/bin:$PATH"
echo ""
echo " To start editing content, run:"
echo ""
echo "npm run build:styles"
echo "npm run dev:site"
echo ""
echo " The site will be available under http://localhost:8080/ for"
echo " local development and rebuilds automatically when content"
echo " changes."
echo ""
'';
};
};
defaultPackage = packages.angestoepseltSite;
devShell = packages.devEnv;
hydraJobs = {
container = packages.container;
};
}
);
}