Port to flake
This commit is contained in:
parent
799ca53fde
commit
0b4d625001
24
default.nix
24
default.nix
|
@ -1,16 +1,13 @@
|
|||
{ stdenv, lib, hugo, fetchgit, pkgs, nodejs, ruby }:
|
||||
{ blog-source, blog-source-localized, pkgs }:
|
||||
|
||||
with pkgs;
|
||||
|
||||
let
|
||||
url = "https://dev.danilafe.com/Web-Projects/blog-static.git";
|
||||
requiredPackages = import ./required-packages.nix { inherit pkgs nodejs; };
|
||||
website = settings: stdenv.mkDerivation {
|
||||
name = "blog-static";
|
||||
version = settings.rev;
|
||||
src = fetchgit {
|
||||
inherit url;
|
||||
inherit (settings) rev sha256;
|
||||
fetchSubmodules = true;
|
||||
};
|
||||
version = settings.source.rev;
|
||||
src = settings.source;
|
||||
urlSub =
|
||||
let
|
||||
regexEscape = lib.escape [ "/" "(" ")" "[" "]" "+" "*" "\\" ];
|
||||
|
@ -31,20 +28,16 @@ let
|
|||
(ruby.withPackages (ps: [ ps.nokogiri ]))
|
||||
];
|
||||
};
|
||||
rev = "b3ff2fe135fd57a646d5d3271db64886d745ff8c";
|
||||
sha256 = "1nljx2wsc25fciwc5ixmwvf8sx4v9n9brx37dhlr4knsadcp89jy";
|
||||
localizationRev = "0b5748cc5a19b5d1d78bfcfa58d4027cc10524dd";
|
||||
localizationSha256 = "12pqh534z3ppvgzy0a77s9j1qzzmiyxwvlmh5y76pccf32wvi9wz";
|
||||
in
|
||||
{
|
||||
english = website {
|
||||
inherit rev sha256;
|
||||
source = blog-source;
|
||||
path = ".";
|
||||
drafts = false;
|
||||
};
|
||||
drafts = {
|
||||
english = website {
|
||||
inherit rev sha256;
|
||||
source = blog-source;
|
||||
path = ".";
|
||||
drafts = true;
|
||||
replaceUrl = {
|
||||
|
@ -53,8 +46,7 @@ in
|
|||
};
|
||||
};
|
||||
russian = website {
|
||||
rev = localizationRev;
|
||||
sha256 = localizationSha256;
|
||||
source = blog-source-localized;
|
||||
path = "ru";
|
||||
drafts = true;
|
||||
replaceUrl = {
|
||||
|
|
34
flake.nix
Normal file
34
flake.nix
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
blog-source = {
|
||||
flake = false;
|
||||
url = "https://dev.danilafe.com/Web-Projects/blog-static.git";
|
||||
type = "git";
|
||||
submodules = true;
|
||||
};
|
||||
blog-source-localized = {
|
||||
flake = false;
|
||||
url = "https://dev.danilafe.com/Web-Projects/blog-static.git";
|
||||
ref = "localization";
|
||||
type = "git";
|
||||
submodules = true;
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, blog-source, blog-source-localized, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
blog = import ./default.nix {
|
||||
inherit blog-source blog-source-localized pkgs;
|
||||
};
|
||||
in
|
||||
{
|
||||
packages = flake-utils.lib.flattenTree blog;
|
||||
defaultPackage = blog.english;
|
||||
}
|
||||
);
|
||||
}
|
83
node-env.nix
83
node-env.nix
|
@ -1,8 +1,11 @@
|
|||
# This file originates from node2nix
|
||||
|
||||
{stdenv, nodejs, python2, utillinux, libtool, runCommand, writeTextFile}:
|
||||
{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile}:
|
||||
|
||||
let
|
||||
# Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master
|
||||
utillinux = if pkgs ? utillinux then pkgs.utillinux else pkgs.util-linux;
|
||||
|
||||
python = if nodejs ? python then nodejs.python else python2;
|
||||
|
||||
# Create a tar wrapper that filters all the 'Ignoring unknown extended header keyword' noise
|
||||
|
@ -38,8 +41,8 @@ let
|
|||
};
|
||||
|
||||
includeDependencies = {dependencies}:
|
||||
stdenv.lib.optionalString (dependencies != [])
|
||||
(stdenv.lib.concatMapStrings (dependency:
|
||||
lib.optionalString (dependencies != [])
|
||||
(lib.concatMapStrings (dependency:
|
||||
''
|
||||
# Bundle the dependencies of the package
|
||||
mkdir -p node_modules
|
||||
|
@ -100,7 +103,7 @@ let
|
|||
cd "$DIR/${packageName}"
|
||||
${includeDependencies { inherit dependencies; }}
|
||||
cd ..
|
||||
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
|
||||
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
|
||||
'';
|
||||
|
||||
pinpointDependencies = {dependencies, production}:
|
||||
|
@ -161,12 +164,12 @@ let
|
|||
''
|
||||
node ${pinpointDependenciesFromPackageJSON} ${if production then "production" else "development"}
|
||||
|
||||
${stdenv.lib.optionalString (dependencies != [])
|
||||
${lib.optionalString (dependencies != [])
|
||||
''
|
||||
if [ -d node_modules ]
|
||||
then
|
||||
cd node_modules
|
||||
${stdenv.lib.concatMapStrings (dependency: pinpointDependenciesOfPackage dependency) dependencies}
|
||||
${lib.concatMapStrings (dependency: pinpointDependenciesOfPackage dependency) dependencies}
|
||||
cd ..
|
||||
fi
|
||||
''}
|
||||
|
@ -183,7 +186,7 @@ let
|
|||
cd "${packageName}"
|
||||
${pinpointDependencies { inherit dependencies production; }}
|
||||
cd ..
|
||||
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
|
||||
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
|
||||
fi
|
||||
'';
|
||||
|
||||
|
@ -242,8 +245,8 @@ let
|
|||
if(fs.existsSync("./package-lock.json")) {
|
||||
var packageLock = JSON.parse(fs.readFileSync("./package-lock.json"));
|
||||
|
||||
if(packageLock.lockfileVersion !== 1) {
|
||||
process.stderr.write("Sorry, I only understand lock file version 1!\n");
|
||||
if(![1, 2].includes(packageLock.lockfileVersion)) {
|
||||
process.stderr.write("Sorry, I only understand lock file versions 1 and 2!\n");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
@ -344,8 +347,8 @@ let
|
|||
cd "${packageName}"
|
||||
runHook preRebuild
|
||||
|
||||
${stdenv.lib.optionalString bypassCache ''
|
||||
${stdenv.lib.optionalString reconstructLock ''
|
||||
${lib.optionalString bypassCache ''
|
||||
${lib.optionalString reconstructLock ''
|
||||
if [ -f package-lock.json ]
|
||||
then
|
||||
echo "WARNING: Reconstruct lock option enabled, but a lock file already exists!"
|
||||
|
@ -361,14 +364,14 @@ let
|
|||
node ${addIntegrityFieldsScript}
|
||||
''}
|
||||
|
||||
npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} rebuild
|
||||
npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${lib.optionalString production "--production"} rebuild
|
||||
|
||||
if [ "''${dontNpmInstall-}" != "1" ]
|
||||
then
|
||||
# NPM tries to download packages even when they already exist if npm-shrinkwrap is used.
|
||||
rm -f npm-shrinkwrap.json
|
||||
|
||||
npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install
|
||||
npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${lib.optionalString production "--production"} install
|
||||
fi
|
||||
'';
|
||||
|
||||
|
@ -396,8 +399,8 @@ let
|
|||
stdenv.mkDerivation ({
|
||||
name = "node_${name}-${version}";
|
||||
buildInputs = [ tarWrapper python nodejs ]
|
||||
++ stdenv.lib.optional (stdenv.isLinux) utillinux
|
||||
++ stdenv.lib.optional (stdenv.isDarwin) libtool
|
||||
++ lib.optional (stdenv.isLinux) utillinux
|
||||
++ lib.optional (stdenv.isDarwin) libtool
|
||||
++ buildInputs;
|
||||
|
||||
inherit nodejs;
|
||||
|
@ -445,8 +448,8 @@ let
|
|||
'';
|
||||
} // extraArgs);
|
||||
|
||||
# Builds a development shell
|
||||
buildNodeShell =
|
||||
# Builds a node environment (a node_modules folder and a set of binaries)
|
||||
buildNodeDependencies =
|
||||
{ name
|
||||
, packageName
|
||||
, version
|
||||
|
@ -465,13 +468,13 @@ let
|
|||
|
||||
let
|
||||
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ];
|
||||
|
||||
nodeDependencies = stdenv.mkDerivation ({
|
||||
in
|
||||
stdenv.mkDerivation ({
|
||||
name = "node-dependencies-${name}-${version}";
|
||||
|
||||
buildInputs = [ tarWrapper python nodejs ]
|
||||
++ stdenv.lib.optional (stdenv.isLinux) utillinux
|
||||
++ stdenv.lib.optional (stdenv.isDarwin) libtool
|
||||
++ lib.optional (stdenv.isLinux) utillinux
|
||||
++ lib.optional (stdenv.isDarwin) libtool
|
||||
++ buildInputs;
|
||||
|
||||
inherit dontStrip; # Stripping may fail a build for some package deployments
|
||||
|
@ -491,7 +494,7 @@ let
|
|||
# Create fake package.json to make the npm commands work properly
|
||||
cp ${src}/package.json .
|
||||
chmod 644 package.json
|
||||
${stdenv.lib.optionalString bypassCache ''
|
||||
${lib.optionalString bypassCache ''
|
||||
if [ -f ${src}/package-lock.json ]
|
||||
then
|
||||
cp ${src}/package-lock.json .
|
||||
|
@ -500,23 +503,44 @@ let
|
|||
|
||||
# Go to the parent folder to make sure that all packages are pinpointed
|
||||
cd ..
|
||||
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
|
||||
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
|
||||
|
||||
${prepareAndInvokeNPM { inherit packageName bypassCache reconstructLock npmFlags production; }}
|
||||
|
||||
# Expose the executables that were installed
|
||||
cd ..
|
||||
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
|
||||
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
|
||||
|
||||
mv ${packageName} lib
|
||||
ln -s $out/lib/node_modules/.bin $out/bin
|
||||
'';
|
||||
} // extraArgs);
|
||||
|
||||
# Builds a development shell
|
||||
buildNodeShell =
|
||||
{ name
|
||||
, packageName
|
||||
, version
|
||||
, src
|
||||
, dependencies ? []
|
||||
, buildInputs ? []
|
||||
, production ? true
|
||||
, npmFlags ? ""
|
||||
, dontNpmInstall ? false
|
||||
, bypassCache ? false
|
||||
, reconstructLock ? false
|
||||
, dontStrip ? true
|
||||
, unpackPhase ? "true"
|
||||
, buildPhase ? "true"
|
||||
, ... }@args:
|
||||
|
||||
let
|
||||
nodeDependencies = buildNodeDependencies args;
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
name = "node-shell-${name}-${version}";
|
||||
|
||||
buildInputs = [ python nodejs ] ++ stdenv.lib.optional (stdenv.isLinux) utillinux ++ buildInputs;
|
||||
buildInputs = [ python nodejs ] ++ lib.optional (stdenv.isLinux) utillinux ++ buildInputs;
|
||||
buildCommand = ''
|
||||
mkdir -p $out/bin
|
||||
cat > $out/bin/shell <<EOF
|
||||
|
@ -529,14 +553,15 @@ let
|
|||
|
||||
# Provide the dependencies in a development shell through the NODE_PATH environment variable
|
||||
inherit nodeDependencies;
|
||||
shellHook = stdenv.lib.optionalString (dependencies != []) ''
|
||||
shellHook = lib.optionalString (dependencies != []) ''
|
||||
export NODE_PATH=${nodeDependencies}/lib/node_modules
|
||||
export PATH="${nodeDependencies}/bin:$PATH"
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
buildNodeSourceDist = stdenv.lib.makeOverridable buildNodeSourceDist;
|
||||
buildNodePackage = stdenv.lib.makeOverridable buildNodePackage;
|
||||
buildNodeShell = stdenv.lib.makeOverridable buildNodeShell;
|
||||
buildNodeSourceDist = lib.makeOverridable buildNodeSourceDist;
|
||||
buildNodePackage = lib.makeOverridable buildNodePackage;
|
||||
buildNodeDependencies = lib.makeOverridable buildNodeDependencies;
|
||||
buildNodeShell = lib.makeOverridable buildNodeShell;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# This file has been generated by node2nix 1.8.0. Do not edit!
|
||||
# This file has been generated by node2nix 1.9.0. Do not edit!
|
||||
|
||||
{nodeEnv, fetchurl, fetchgit, globalBuildInputs ? []}:
|
||||
{nodeEnv, fetchurl, fetchgit, nix-gitignore, stdenv, lib, globalBuildInputs ? []}:
|
||||
|
||||
let
|
||||
sources = {
|
||||
|
@ -157,13 +157,13 @@ let
|
|||
sha512 = "aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==";
|
||||
};
|
||||
};
|
||||
"forwarded-0.1.2" = {
|
||||
"forwarded-0.2.0" = {
|
||||
name = "forwarded";
|
||||
packageName = "forwarded";
|
||||
version = "0.1.2";
|
||||
version = "0.2.0";
|
||||
src = fetchurl {
|
||||
url = "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz";
|
||||
sha1 = "98c23dab1175657b8c0573e8ceccd91b0ff18c84";
|
||||
url = "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz";
|
||||
sha512 = "buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==";
|
||||
};
|
||||
};
|
||||
"fresh-0.5.2" = {
|
||||
|
@ -247,22 +247,22 @@ let
|
|||
sha512 = "x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==";
|
||||
};
|
||||
};
|
||||
"mime-db-1.44.0" = {
|
||||
"mime-db-1.50.0" = {
|
||||
name = "mime-db";
|
||||
packageName = "mime-db";
|
||||
version = "1.44.0";
|
||||
version = "1.50.0";
|
||||
src = fetchurl {
|
||||
url = "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz";
|
||||
sha512 = "/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==";
|
||||
url = "https://registry.npmjs.org/mime-db/-/mime-db-1.50.0.tgz";
|
||||
sha512 = "9tMZCDlYHqeERXEHO9f/hKfNXhre5dK2eE/krIvUjZbS2KPcqGDfNShIWS1uW9XOTKQKqK6qbeOci18rbfW77A==";
|
||||
};
|
||||
};
|
||||
"mime-types-2.1.27" = {
|
||||
"mime-types-2.1.33" = {
|
||||
name = "mime-types";
|
||||
packageName = "mime-types";
|
||||
version = "2.1.27";
|
||||
version = "2.1.33";
|
||||
src = fetchurl {
|
||||
url = "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz";
|
||||
sha512 = "JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==";
|
||||
url = "https://registry.npmjs.org/mime-types/-/mime-types-2.1.33.tgz";
|
||||
sha512 = "plLElXp7pRDd0bNZHw+nMd52vRYjLwQjygaNg7ddJ2uJtTlmnTCjWuPKxVu6//AdaRuME84SvLW91sIkBqGT0g==";
|
||||
};
|
||||
};
|
||||
"ms-2.0.0" = {
|
||||
|
@ -319,13 +319,13 @@ let
|
|||
sha1 = "df604178005f522f15eb4490e7247a1bfaa67f8c";
|
||||
};
|
||||
};
|
||||
"proxy-addr-2.0.6" = {
|
||||
"proxy-addr-2.0.7" = {
|
||||
name = "proxy-addr";
|
||||
packageName = "proxy-addr";
|
||||
version = "2.0.6";
|
||||
version = "2.0.7";
|
||||
src = fetchurl {
|
||||
url = "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz";
|
||||
sha512 = "dh/frvCBVmSsDYzw6n926jv974gddhkFPfiN8hPOi30Wax25QZyZEGveluCgliBnqmuM+UJmBErbAUFIoDbjOw==";
|
||||
url = "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz";
|
||||
sha512 = "llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==";
|
||||
};
|
||||
};
|
||||
"qs-6.7.0" = {
|
||||
|
@ -471,7 +471,7 @@ in
|
|||
buildInputs = globalBuildInputs;
|
||||
meta = {
|
||||
description = "Fast math typesetting for the web.";
|
||||
homepage = https://katex.org/;
|
||||
homepage = "https://katex.org/";
|
||||
license = "MIT";
|
||||
};
|
||||
production = true;
|
||||
|
@ -503,7 +503,7 @@ in
|
|||
sources."escape-html-1.0.3"
|
||||
sources."etag-1.8.1"
|
||||
sources."finalhandler-1.1.2"
|
||||
sources."forwarded-0.1.2"
|
||||
sources."forwarded-0.2.0"
|
||||
sources."fresh-0.5.2"
|
||||
sources."http-errors-1.7.2"
|
||||
sources."iconv-lite-0.4.24"
|
||||
|
@ -513,14 +513,14 @@ in
|
|||
sources."merge-descriptors-1.0.1"
|
||||
sources."methods-1.1.2"
|
||||
sources."mime-1.6.0"
|
||||
sources."mime-db-1.44.0"
|
||||
sources."mime-types-2.1.27"
|
||||
sources."mime-db-1.50.0"
|
||||
sources."mime-types-2.1.33"
|
||||
sources."ms-2.0.0"
|
||||
sources."negotiator-0.6.2"
|
||||
sources."on-finished-2.3.0"
|
||||
sources."parseurl-1.3.3"
|
||||
sources."path-to-regexp-0.1.7"
|
||||
sources."proxy-addr-2.0.6"
|
||||
sources."proxy-addr-2.0.7"
|
||||
sources."qs-6.7.0"
|
||||
sources."range-parser-1.2.1"
|
||||
sources."raw-body-2.4.0"
|
||||
|
@ -543,7 +543,7 @@ in
|
|||
buildInputs = globalBuildInputs;
|
||||
meta = {
|
||||
description = "Fast, unopinionated, minimalist web framework";
|
||||
homepage = http://expressjs.com/;
|
||||
homepage = "http://expressjs.com/";
|
||||
license = "MIT";
|
||||
};
|
||||
production = true;
|
||||
|
@ -568,8 +568,8 @@ in
|
|||
sources."iconv-lite-0.4.24"
|
||||
sources."inherits-2.0.3"
|
||||
sources."media-typer-0.3.0"
|
||||
sources."mime-db-1.44.0"
|
||||
sources."mime-types-2.1.27"
|
||||
sources."mime-db-1.50.0"
|
||||
sources."mime-types-2.1.33"
|
||||
sources."ms-2.0.0"
|
||||
sources."on-finished-2.3.0"
|
||||
sources."qs-6.7.0"
|
||||
|
@ -591,4 +591,4 @@ in
|
|||
bypassCache = true;
|
||||
reconstructLock = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# This file has been generated by node2nix 1.8.0. Do not edit!
|
||||
# This file has been generated by node2nix 1.9.0. Do not edit!
|
||||
|
||||
{pkgs ? import <nixpkgs> {
|
||||
inherit system;
|
||||
|
@ -6,12 +6,12 @@
|
|||
|
||||
let
|
||||
nodeEnv = import ./node-env.nix {
|
||||
inherit (pkgs) stdenv python2 utillinux runCommand writeTextFile;
|
||||
inherit nodejs;
|
||||
inherit (pkgs) stdenv lib python2 runCommand writeTextFile;
|
||||
inherit pkgs nodejs;
|
||||
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
|
||||
};
|
||||
in
|
||||
import ./node-packages.nix {
|
||||
inherit (pkgs) fetchurl fetchgit;
|
||||
inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit;
|
||||
inherit nodeEnv;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user