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) This repository also contains a [Nix flake](https://nixos.wiki/wiki/Flakes)
which contains the full development environment. `nix develop` will open a 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. 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 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. 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: The flake also contains a second package for building the production output:
```shell ```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. The final derivation contains a `www` folder that can be served.

22
flake.lock generated
View file

@ -1,12 +1,27 @@
{ {
"nodes": { "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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1632660378, "lastModified": 1633528625,
"narHash": "sha256-sjA8eQlnyDjDLyAyq3XlJmN0nqW0ftl/pb7VnMg86L0=", "narHash": "sha256-AGj5q58eHACAe0RQGxObrGwMUsjMozTsiznhsLCYisQ=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "31ffc50c571e6683e9ecc9dbcbd4a8e9914b4497", "rev": "5e2018f7b383aeca6824a30c0cd1978c9532a46a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -17,6 +32,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
} }

View file

@ -2,11 +2,11 @@
description = "Angestöpselt Homepage"; description = "Angestöpselt Homepage";
inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs }: outputs = {self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
nodejs = pkgs.nodejs-16_x; nodejs = pkgs.nodejs-16_x;
@ -17,11 +17,9 @@
buildInputs = with pkgs; [ vips ]; buildInputs = with pkgs; [ vips ];
dontNpmInstall = true; dontNpmInstall = true;
}; };
in
{ angestoepseltSite = pkgs.stdenv.mkDerivation {
packages.${system} = { name = "angestoepseltSite";
angestoepselt-site = pkgs.stdenv.mkDerivation {
name = "angestoepselt-site";
src = self; src = self;
buildInputs = [ nodejs nodeDependencies ]; buildInputs = [ nodejs nodeDependencies ];
@ -35,6 +33,13 @@
cp -r _site "$out/www" cp -r _site "$out/www"
''; '';
}; };
in
rec {
apps = { inherit angestoepseltSite; };
defaultApp = apps.angestoepseltSite;
packages = {
inherit angestoepseltSite;
# This package isn't actually the fully-built site, but rather a # This package isn't actually the fully-built site, but rather a
# derivation that contains the relevant programs (with correctly set up # derivation that contains the relevant programs (with correctly set up
@ -42,13 +47,21 @@
# `nix develop` see the repository's readme for details or compiled # `nix develop` see the repository's readme for details or compiled
# with `nix build`. The latter will output a folder which contains node # with `nix build`. The latter will output a folder which contains node
# and npm binaries that can be used in an IDE. # and npm binaries that can be used in an IDE.
angestoepselt-site-dev = pkgs.symlinkJoin { angestoepseltSiteEnv = pkgs.symlinkJoin {
name = "angestoepselt-site-dev"; name = "angestoepseltSiteEnv";
buildInputs = [ pkgs.makeWrapper ];
paths = [ nodejs nodeDependencies ]; paths = [ nodejs nodeDependencies ];
postBuild = ''
wrapProgram "$out/bin/node" \
--prefix PATH : "$out/lib/node_modules/.bin" \
--prefix NODE_PATH : "$out/lib/node_modules"
'';
shellHook = '' shellHook = ''
export NODE_PATH=${nodeDependencies}/lib/node_modules export NODE_PATH=${nodeDependencies}/lib/node_modules
export PATH="${nodeDependencies}/bin:$PATH" export PATH="${nodeDependencies}/bin:${nodejs}/bin:$PATH"
echo "" echo ""
echo " To start editing content, run:" echo " To start editing content, run:"
@ -63,7 +76,9 @@
''; '';
}; };
}; };
defaultPackage = packages.angestoepseltSite;
defaultPackage.${system} = self.packages.${system}.angestoepselt-site-dev; devShell = packages.angestoepseltSiteEnv;
}; }
);
} }