Update nix flake

This commit is contained in:
Yannik Rödel 2021-10-07 14:40:55 +02:00
parent ed95bc6967
commit a0eb7d3443
3 changed files with 79 additions and 46 deletions

View file

@ -27,6 +27,8 @@ terminal to watch for changes.
This repository also contains a [Nix flake](https://nixos.wiki/wiki/Flakes)
which contains the full development environment. `nix develop` will open a
shell with all required tools you don't need to run `npm install` anymore.
Run `nix build ".#angestoepseltSiteEnv" -o .dev` to get a running Node
environment in the *.dev* folder (for example to configure an IDE).
When Node dependencies are updated (this will change `package.json`), make sure
to run `./_nix/update.sh` to update the npm lockfile and the Nix environment.
@ -34,7 +36,7 @@ to run `./_nix/update.sh` to update the npm lockfile and the Nix environment.
The flake also contains a second package for building the production output:
```shell
nix build .#angestoepselt-site
nix build # Will create an output derivation in 'result'
```
The final derivation contains a `www` folder that can be served.

22
flake.lock generated
View file

@ -1,12 +1,27 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1631561581,
"narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1632660378,
"narHash": "sha256-sjA8eQlnyDjDLyAyq3XlJmN0nqW0ftl/pb7VnMg86L0=",
"lastModified": 1633528625,
"narHash": "sha256-AGj5q58eHACAe0RQGxObrGwMUsjMozTsiznhsLCYisQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "31ffc50c571e6683e9ecc9dbcbd4a8e9914b4497",
"rev": "5e2018f7b383aeca6824a30c0cd1978c9532a46a",
"type": "github"
},
"original": {
@ -17,6 +32,7 @@
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}

View file

@ -2,26 +2,24 @@
description = "Angestöpselt Homepage";
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
outputs = {self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
pkgs = import nixpkgs { inherit system; };
nodejs = pkgs.nodejs-16_x;
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;
};
nodePackages = import ./nix/default.nix { inherit pkgs system nodejs; };
nodeDependencies = nodePackages.nodeDependencies.override {
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ vips ];
dontNpmInstall = true;
};
in
{
packages.${system} = {
angestoepselt-site = pkgs.stdenv.mkDerivation {
name = "angestoepselt-site";
angestoepseltSite = pkgs.stdenv.mkDerivation {
name = "angestoepseltSite";
src = self;
buildInputs = [ nodejs nodeDependencies ];
@ -35,35 +33,52 @@
cp -r _site "$out/www"
'';
};
in
rec {
apps = { inherit angestoepseltSite; };
defaultApp = apps.angestoepseltSite;
# 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.
angestoepselt-site-dev = pkgs.symlinkJoin {
name = "angestoepselt-site-dev";
paths = [ nodejs nodeDependencies ];
packages = {
inherit angestoepseltSite;
shellHook = ''
export NODE_PATH=${nodeDependencies}/lib/node_modules
export PATH="${nodeDependencies}/bin:$PATH"
# 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.
angestoepseltSiteEnv = pkgs.symlinkJoin {
name = "angestoepseltSiteEnv";
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 ""
'';
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:$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;
defaultPackage.${system} = self.packages.${system}.angestoepselt-site-dev;
};
devShell = packages.angestoepseltSiteEnv;
}
);
}