add compat thingy

This commit is contained in:
notgne2 2021-02-14 03:12:33 -07:00
parent 924661d9fc
commit 6fbcf18e3b
No known key found for this signature in database
GPG Key ID: BB661E172B42A7F8
3 changed files with 260 additions and 243 deletions

View File

@ -1,245 +1,17 @@
pkgs: inputs:
let
pnpm2nix = pkgs.callPackage inputs.pnpm2nix { };
# SPDX-FileCopyrightText: 2020 Serokell <https://serokell.io/>
#
# SPDX-License-Identifier: MPL-2.0
nodeCleanSourceFilter = name: type:
pkgs.lib.cleanSourceFilter name type
&& ((baseNameOf name) != "node_modules");
nodeCleanSource = src:
pkgs.lib.cleanSourceWith {
filter = nodeCleanSourceFilter;
inherit src;
};
elmCleanSourceFilter = name: type:
nodeCleanSourceFilter name type
&& ((baseNameOf name) != "elm-stuff" && (baseNameOf name) != "dist");
elmCleanSource = src:
pkgs.lib.cleanSourceWith {
filter = elmCleanSourceFilter;
inherit src;
};
builderPkg = pnpm2nix.mkPnpmPackage {
name = "builder-node-packages";
packageJSON = ./package.json;
pnpmLock = ./pnpm-lock.yaml;
src = nodeCleanSource ./.;
overrides = pnpm2nix.defaultPnpmOverrides // {
puppeteer = (
drv:
drv.overrideAttrs (
oldAttrs: {
preBuild = ''
# Define the local chromium directory
local_chromium=$HOME/node_modules/puppeteer/.local-chromium/linux-686378
# Make sure that directory exists
mkdir -p $local_chromium
# Link pkgs' standard google chrome into place
cp -r --no-preserve=mode,ownership ${pkgs.google-chrome}/share/google/chrome $local_chromium/chrome-linux
cp ${pkgs.google-chrome}/bin/google-chrome-stable $local_chromium/chrome-linux/chrome
chmod +x $local_chromium/chrome-linux/chrome
'';
}
)
);
imagemin-pngquant = (
drv:
drv.overrideAttrs
(oldAttrs: { buildInputs = oldAttrs.buildInputs ++ [ pkgs.libpng ]; })
);
pngquant-bin = (
drv:
drv.overrideAttrs (
oldAttrs: {
preBuild = ''
mkdir -p $HOME/node_modules/pngquant-bin/vendor
ln -s ${pkgs.pngquant}/bin/pngquant $HOME/node_modules/pngquant-bin/vendor/pngquant
'';
}
)
);
gifsicle = (
drv:
drv.overrideAttrs (
oldAttrs: {
buildInputs = oldAttrs.buildInputs ++ [ pkgs.autoconf pkgs.automake ];
}
)
);
optipng =
(drv: drv.overrideAttrs (oldAttrs: { buildInputs = [ pkgs.optipng ]; }));
optipng-bin = (
drv:
drv.overrideAttrs (
oldAttrs: {
preBuild = ''
mkdir -p $HOME/node_modules/optipng-bin/vendor
ln -s ${pkgs.optipng}/bin/optipng $HOME/node_modules/optipng-bin/vendor/optipng
'';
}
)
);
jpegtran =
(drv: drv.overrideAttrs (oldAttrs: { buildInputs = [ pkgs.libjpeg ]; }));
jpegtran-bin = (
drv:
drv.overrideAttrs (
oldAttrs: {
preBuild = ''
mkdir -p $HOME/node_modules/jpegtran-bin/vendor
ln -s ${pkgs.libjpeg}/bin/jpegtran $HOME/node_modules/jpegtran-bin/vendor/jpegtran
'';
}
)
);
cwebp-bin = (
drv:
drv.overrideAttrs (
oldAttrs: {
buildPhase = ''
mkdir -p $HOME/node_modules/cwebp-bin/vendor/
ln -s ${pkgs.libwebp}/bin/cwebp $HOME/node_modules/cwebp-bin/vendor/cwebp
'';
}
)
);
};
};
mkWandardFront =
{ name
, prettyName ? name
, description ? ""
, themeColor ? "#000000"
, backgroundColor ? "#000000"
, src
, nodePackages ? [ ]
, routes ? [ "/" ]
, extraHead ? ""
, extraBody ? ""
, extraPostBody ? ""
}:
(import
(
let
nodeSource = pkgs.symlinkJoin {
name = "${name}-node-sources";
paths = [ builderPkg.lib ] ++ nodePackages;
};
baseWebpackConfig = builtins.readFile ./webpack.config.js;
webpackConfig = ''
const ROUTES = ${builtins.toJSON routes}
const PRETTY_NAME = ${builtins.toJSON prettyName}
const DESCRIPTION = ${builtins.toJSON description}
const THEME_COLOR = ${builtins.toJSON themeColor}
const BACKGROUND_COLOR = ${builtins.toJSON backgroundColor}
'' + "\n" + baseWebpackConfig;
webpackConfigFile = pkgs.writeText "${name}-webpack-config" webpackConfig;
wandInit = pkgs.writeText "wand.js" ''
document.body.innerHTML = '''
const sourceTarget = document.createElement('script')
sourceTarget.src = '/main.js'
document.body.appendChild(sourceTarget)
'';
templateHtml = pkgs.writeText "template.html" ''
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>${prettyName}</title>
<link rel="apple-touch-icon" sizes="57x57" href="/appdata/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/appdata/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/appdata/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/appdata/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/appdata/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/appdata/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/appdata/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/appdata/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="167x167" href="/appdata/apple-touch-icon-167x167.png">
<link rel="apple-touch-icon" sizes="180x180" href="/appdata/apple-touch-icon-180x180.png">
<link rel="apple-touch-icon" sizes="1024x1024" href="/appdata/apple-touch-icon-1024x1024.png">
<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 1)" href="/appdata/apple-touch-startup-image-320x460.png">
<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)" href="/appdata/apple-touch-startup-image-640x920.png">
<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)" href="/appdata/apple-touch-startup-image-640x1096.png">
<link rel="apple-touch-startup-image" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2)" href="/appdata/apple-touch-startup-image-750x1294.png">
<link rel="apple-touch-startup-image" media="(device-width: 414px) and (device-height: 736px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 3)" href="/appdata/apple-touch-startup-image-1182x2208.png">
<link rel="apple-touch-startup-image" media="(device-width: 414px) and (device-height: 736px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 3)" href="/appdata/apple-touch-startup-image-1242x2148.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 1)" href="/appdata/apple-touch-startup-image-748x1024.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)" href="/appdata/apple-touch-startup-image-1496x2048.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 1)" href="/appdata/apple-touch-startup-image-768x1004.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" href="/appdata/apple-touch-startup-image-1536x2008.png">
<link rel="icon" type="image/png" sizes="16x16" href="/appdata/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="/appdata/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="228x228" href="/appdata/coast-228x228.png">
<link rel="manifest" href="/appdata/manifest.json">
<link rel="shortcut icon" href="/appdata/favicon.ico">
<link rel="yandex-tableau-widget" href="/appdata/yandex-browser-manifest.json">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title">
<meta name="application-name" content="${prettyName}">
<meta name="mobile-web-app-capable" content="yes">
<meta name="msapplication-TileColor" content="#fff">
<meta name="msapplication-TileImage" content="/appdata/mstile-144x144.png">
<meta name="msapplication-config" content="/appdata/browserconfig.xml">
<meta name="theme-color" content="${themeColor}">
${extraHead}
</head>
<body>
${extraBody}
</body>
${extraPostBody}
</html>
'';
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
pkgs.stdenv.mkDerivation {
inherit name;
src = elmCleanSource src;
buildInputs = with pkgs.elmPackages; [ elm nodeSource ];
patchPhase = ''
ln -sf ${nodeSource}/node_modules .
cp ${webpackConfigFile} webpack.config.js
cp ${
./imagemin-jpgify-webpack-plugin.js
} .imagemin-jpgify-webpack-plugin.js
cp ${wandInit} wand.js
cp ${templateHtml} template.html
'';
shellHook = ''
ln -sf ${nodeSource}/node_modules .
rm -f webpack.config.js
rm -f wand.js
rm -f template.html
cp ${webpackConfigFile} webpack.config.js
cp ${
./imagemin-jpgify-webpack-plugin.js
} .imagemin-jpgify-webpack-plugin.js
cp ${wandInit} wand.js
cp ${templateHtml} template.html
export NODE_PATH=$PWD/node_modules
'';
buildPhase = pkgs.elmPackages.fetchElmDeps {
elmPackages = import (src + "/elm-srcs.nix");
registryDat = src + "/registry.dat";
elmVersion = "0.19.1";
};
installPhase = ''
mkdir -p $out
${nodeSource}/node_modules/webpack-cli/bin/cli.js --mode production
mv dist/* $out
'';
};
in
{ inherit mkWandardFront; }
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{
src = ./.;
}).defaultNix

View File

@ -19,6 +19,6 @@
pkgs = import nixpkgs { inherit system; };
in
{
lib = import ./default.nix pkgs inputs;
lib = import ./wand.nix pkgs inputs;
});
}

245
wand.nix Normal file
View File

@ -0,0 +1,245 @@
pkgs: inputs:
let
pnpm2nix = pkgs.callPackage inputs.pnpm2nix { };
nodeCleanSourceFilter = name: type:
pkgs.lib.cleanSourceFilter name type
&& ((baseNameOf name) != "node_modules");
nodeCleanSource = src:
pkgs.lib.cleanSourceWith {
filter = nodeCleanSourceFilter;
inherit src;
};
elmCleanSourceFilter = name: type:
nodeCleanSourceFilter name type
&& ((baseNameOf name) != "elm-stuff" && (baseNameOf name) != "dist");
elmCleanSource = src:
pkgs.lib.cleanSourceWith {
filter = elmCleanSourceFilter;
inherit src;
};
builderPkg = pnpm2nix.mkPnpmPackage {
name = "builder-node-packages";
packageJSON = ./package.json;
pnpmLock = ./pnpm-lock.yaml;
src = nodeCleanSource ./.;
overrides = pnpm2nix.defaultPnpmOverrides // {
puppeteer = (
drv:
drv.overrideAttrs (
oldAttrs: {
preBuild = ''
# Define the local chromium directory
local_chromium=$HOME/node_modules/puppeteer/.local-chromium/linux-686378
# Make sure that directory exists
mkdir -p $local_chromium
# Link pkgs' standard google chrome into place
cp -r --no-preserve=mode,ownership ${pkgs.google-chrome}/share/google/chrome $local_chromium/chrome-linux
cp ${pkgs.google-chrome}/bin/google-chrome-stable $local_chromium/chrome-linux/chrome
chmod +x $local_chromium/chrome-linux/chrome
'';
}
)
);
imagemin-pngquant = (
drv:
drv.overrideAttrs
(oldAttrs: { buildInputs = oldAttrs.buildInputs ++ [ pkgs.libpng ]; })
);
pngquant-bin = (
drv:
drv.overrideAttrs (
oldAttrs: {
preBuild = ''
mkdir -p $HOME/node_modules/pngquant-bin/vendor
ln -s ${pkgs.pngquant}/bin/pngquant $HOME/node_modules/pngquant-bin/vendor/pngquant
'';
}
)
);
gifsicle = (
drv:
drv.overrideAttrs (
oldAttrs: {
buildInputs = oldAttrs.buildInputs ++ [ pkgs.autoconf pkgs.automake ];
}
)
);
optipng =
(drv: drv.overrideAttrs (oldAttrs: { buildInputs = [ pkgs.optipng ]; }));
optipng-bin = (
drv:
drv.overrideAttrs (
oldAttrs: {
preBuild = ''
mkdir -p $HOME/node_modules/optipng-bin/vendor
ln -s ${pkgs.optipng}/bin/optipng $HOME/node_modules/optipng-bin/vendor/optipng
'';
}
)
);
jpegtran =
(drv: drv.overrideAttrs (oldAttrs: { buildInputs = [ pkgs.libjpeg ]; }));
jpegtran-bin = (
drv:
drv.overrideAttrs (
oldAttrs: {
preBuild = ''
mkdir -p $HOME/node_modules/jpegtran-bin/vendor
ln -s ${pkgs.libjpeg}/bin/jpegtran $HOME/node_modules/jpegtran-bin/vendor/jpegtran
'';
}
)
);
cwebp-bin = (
drv:
drv.overrideAttrs (
oldAttrs: {
buildPhase = ''
mkdir -p $HOME/node_modules/cwebp-bin/vendor/
ln -s ${pkgs.libwebp}/bin/cwebp $HOME/node_modules/cwebp-bin/vendor/cwebp
'';
}
)
);
};
};
mkWandardFront =
{ name
, prettyName ? name
, description ? ""
, themeColor ? "#000000"
, backgroundColor ? "#000000"
, src
, nodePackages ? [ ]
, routes ? [ "/" ]
, extraHead ? ""
, extraBody ? ""
, extraPostBody ? ""
}:
let
nodeSource = pkgs.symlinkJoin {
name = "${name}-node-sources";
paths = [ builderPkg.lib ] ++ nodePackages;
};
baseWebpackConfig = builtins.readFile ./webpack.config.js;
webpackConfig = ''
const ROUTES = ${builtins.toJSON routes}
const PRETTY_NAME = ${builtins.toJSON prettyName}
const DESCRIPTION = ${builtins.toJSON description}
const THEME_COLOR = ${builtins.toJSON themeColor}
const BACKGROUND_COLOR = ${builtins.toJSON backgroundColor}
'' + "\n" + baseWebpackConfig;
webpackConfigFile = pkgs.writeText "${name}-webpack-config" webpackConfig;
wandInit = pkgs.writeText "wand.js" ''
document.body.innerHTML = '''
const sourceTarget = document.createElement('script')
sourceTarget.src = '/main.js'
document.body.appendChild(sourceTarget)
'';
templateHtml = pkgs.writeText "template.html" ''
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>${prettyName}</title>
<link rel="apple-touch-icon" sizes="57x57" href="/appdata/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/appdata/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/appdata/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/appdata/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/appdata/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/appdata/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/appdata/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/appdata/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="167x167" href="/appdata/apple-touch-icon-167x167.png">
<link rel="apple-touch-icon" sizes="180x180" href="/appdata/apple-touch-icon-180x180.png">
<link rel="apple-touch-icon" sizes="1024x1024" href="/appdata/apple-touch-icon-1024x1024.png">
<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 1)" href="/appdata/apple-touch-startup-image-320x460.png">
<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)" href="/appdata/apple-touch-startup-image-640x920.png">
<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)" href="/appdata/apple-touch-startup-image-640x1096.png">
<link rel="apple-touch-startup-image" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2)" href="/appdata/apple-touch-startup-image-750x1294.png">
<link rel="apple-touch-startup-image" media="(device-width: 414px) and (device-height: 736px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 3)" href="/appdata/apple-touch-startup-image-1182x2208.png">
<link rel="apple-touch-startup-image" media="(device-width: 414px) and (device-height: 736px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 3)" href="/appdata/apple-touch-startup-image-1242x2148.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 1)" href="/appdata/apple-touch-startup-image-748x1024.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)" href="/appdata/apple-touch-startup-image-1496x2048.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 1)" href="/appdata/apple-touch-startup-image-768x1004.png">
<link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" href="/appdata/apple-touch-startup-image-1536x2008.png">
<link rel="icon" type="image/png" sizes="16x16" href="/appdata/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="/appdata/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="228x228" href="/appdata/coast-228x228.png">
<link rel="manifest" href="/appdata/manifest.json">
<link rel="shortcut icon" href="/appdata/favicon.ico">
<link rel="yandex-tableau-widget" href="/appdata/yandex-browser-manifest.json">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title">
<meta name="application-name" content="${prettyName}">
<meta name="mobile-web-app-capable" content="yes">
<meta name="msapplication-TileColor" content="#fff">
<meta name="msapplication-TileImage" content="/appdata/mstile-144x144.png">
<meta name="msapplication-config" content="/appdata/browserconfig.xml">
<meta name="theme-color" content="${themeColor}">
${extraHead}
</head>
<body>
${extraBody}
</body>
${extraPostBody}
</html>
'';
in
pkgs.stdenv.mkDerivation {
inherit name;
src = elmCleanSource src;
buildInputs = with pkgs.elmPackages; [ elm nodeSource ];
patchPhase = ''
ln -sf ${nodeSource}/node_modules .
cp ${webpackConfigFile} webpack.config.js
cp ${
./imagemin-jpgify-webpack-plugin.js
} .imagemin-jpgify-webpack-plugin.js
cp ${wandInit} wand.js
cp ${templateHtml} template.html
'';
shellHook = ''
ln -sf ${nodeSource}/node_modules .
rm -f webpack.config.js
rm -f wand.js
rm -f template.html
cp ${webpackConfigFile} webpack.config.js
cp ${
./imagemin-jpgify-webpack-plugin.js
} .imagemin-jpgify-webpack-plugin.js
cp ${wandInit} wand.js
cp ${templateHtml} template.html
export NODE_PATH=$PWD/node_modules
'';
buildPhase = pkgs.elmPackages.fetchElmDeps {
elmPackages = import (src + "/elm-srcs.nix");
registryDat = src + "/registry.dat";
elmVersion = "0.19.1";
};
installPhase = ''
mkdir -p $out
${nodeSource}/node_modules/webpack-cli/bin/cli.js --mode production
mv dist/* $out
'';
};
in
{ inherit mkWandardFront; }