This commit is contained in:
notgne2 2021-02-14 03:05:08 -07:00
parent 617453769b
commit 4eae97a2ce
No known key found for this signature in database
GPG Key ID: BB661E172B42A7F8
3 changed files with 249 additions and 167 deletions

View File

@ -1,26 +1,6 @@
{ pkgs pkgs: inputs:
, google-chrome
, symlinkJoin
, stdenv
, elmPackages
, libjpeg
, optipng
, pngquant
, libwebp
, ...
}:
let let
workingElmPackages = if elmPackages.elmVersion == "0.19.1" then pnpm2nix = pkgs.callPackage inputs.pnpm2nix { };
elmPackages
else
(import <unstable> {}).elmPackages;
pnpm2nix = pkgs.callPackage (
builtins.fetchGit {
url = "https://github.com/notgne2/pnpm2nix.git";
rev = "909accd35d23664254b43109ee58cd0c3d83a6d9";
}
) {};
nodeCleanSourceFilter = name: type: nodeCleanSourceFilter = name: type:
pkgs.lib.cleanSourceFilter name type pkgs.lib.cleanSourceFilter name type
@ -48,85 +28,85 @@ let
overrides = pnpm2nix.defaultPnpmOverrides // { overrides = pnpm2nix.defaultPnpmOverrides // {
puppeteer = ( puppeteer = (
drv: drv:
drv.overrideAttrs ( drv.overrideAttrs (
oldAttrs: { oldAttrs: {
preBuild = '' preBuild = ''
# Define the local chromium directory # Define the local chromium directory
local_chromium=$HOME/node_modules/puppeteer/.local-chromium/linux-686378 local_chromium=$HOME/node_modules/puppeteer/.local-chromium/linux-686378
# Make sure that directory exists # Make sure that directory exists
mkdir -p $local_chromium mkdir -p $local_chromium
# Link pkgs' standard google chrome into place # Link pkgs' standard google chrome into place
cp -r --no-preserve=mode,ownership ${google-chrome}/share/google/chrome $local_chromium/chrome-linux cp -r --no-preserve=mode,ownership ${pkgs.google-chrome}/share/google/chrome $local_chromium/chrome-linux
cp ${google-chrome}/bin/google-chrome-stable $local_chromium/chrome-linux/chrome cp ${pkgs.google-chrome}/bin/google-chrome-stable $local_chromium/chrome-linux/chrome
chmod +x $local_chromium/chrome-linux/chrome chmod +x $local_chromium/chrome-linux/chrome
''; '';
} }
) )
); );
imagemin-pngquant = ( imagemin-pngquant = (
drv: drv:
drv.overrideAttrs drv.overrideAttrs
(oldAttrs: { buildInputs = oldAttrs.buildInputs ++ [ pkgs.libpng ]; }) (oldAttrs: { buildInputs = oldAttrs.buildInputs ++ [ pkgs.libpng ]; })
); );
pngquant-bin = ( pngquant-bin = (
drv: drv:
drv.overrideAttrs ( drv.overrideAttrs (
oldAttrs: { oldAttrs: {
preBuild = '' preBuild = ''
mkdir -p $HOME/node_modules/pngquant-bin/vendor mkdir -p $HOME/node_modules/pngquant-bin/vendor
ln -s ${pngquant}/bin/pngquant $HOME/node_modules/pngquant-bin/vendor/pngquant ln -s ${pkgs.pngquant}/bin/pngquant $HOME/node_modules/pngquant-bin/vendor/pngquant
''; '';
} }
) )
); );
gifsicle = ( gifsicle = (
drv: drv:
drv.overrideAttrs ( drv.overrideAttrs (
oldAttrs: { oldAttrs: {
buildInputs = oldAttrs.buildInputs ++ [ pkgs.autoconf pkgs.automake ]; buildInputs = oldAttrs.buildInputs ++ [ pkgs.autoconf pkgs.automake ];
} }
) )
); );
optipng = optipng =
(drv: drv.overrideAttrs (oldAttrs: { buildInputs = [ optipng ]; })); (drv: drv.overrideAttrs (oldAttrs: { buildInputs = [ pkgs.optipng ]; }));
optipng-bin = ( optipng-bin = (
drv: drv:
drv.overrideAttrs ( drv.overrideAttrs (
oldAttrs: { oldAttrs: {
preBuild = '' preBuild = ''
mkdir -p $HOME/node_modules/optipng-bin/vendor mkdir -p $HOME/node_modules/optipng-bin/vendor
ln -s ${optipng}/bin/optipng $HOME/node_modules/optipng-bin/vendor/optipng ln -s ${pkgs.optipng}/bin/optipng $HOME/node_modules/optipng-bin/vendor/optipng
''; '';
} }
) )
); );
jpegtran = jpegtran =
(drv: drv.overrideAttrs (oldAttrs: { buildInputs = [ libjpeg ]; })); (drv: drv.overrideAttrs (oldAttrs: { buildInputs = [ pkgs.libjpeg ]; }));
jpegtran-bin = ( jpegtran-bin = (
drv: drv:
drv.overrideAttrs ( drv.overrideAttrs (
oldAttrs: { oldAttrs: {
preBuild = '' preBuild = ''
mkdir -p $HOME/node_modules/jpegtran-bin/vendor mkdir -p $HOME/node_modules/jpegtran-bin/vendor
ln -s ${libjpeg}/bin/jpegtran $HOME/node_modules/jpegtran-bin/vendor/jpegtran ln -s ${pkgs.libjpeg}/bin/jpegtran $HOME/node_modules/jpegtran-bin/vendor/jpegtran
''; '';
} }
) )
); );
cwebp-bin = ( cwebp-bin = (
drv: drv:
drv.overrideAttrs ( drv.overrideAttrs (
oldAttrs: { oldAttrs: {
buildPhase = '' buildPhase = ''
mkdir -p $HOME/node_modules/cwebp-bin/vendor/ mkdir -p $HOME/node_modules/cwebp-bin/vendor/
ln -s ${libwebp}/bin/cwebp $HOME/node_modules/cwebp-bin/vendor/cwebp ln -s ${pkgs.libwebp}/bin/cwebp $HOME/node_modules/cwebp-bin/vendor/cwebp
''; '';
} }
) )
); );
}; };
}; };
@ -138,93 +118,94 @@ let
, themeColor ? "#000000" , themeColor ? "#000000"
, backgroundColor ? "#000000" , backgroundColor ? "#000000"
, src , src
, nodePackages ? [] , nodePackages ? [ ]
, routes ? [ "/" ] , routes ? [ "/" ]
, extraHead ? "" , extraHead ? ""
, extraBody ? "" , extraBody ? ""
, extraPostBody ? "" , extraPostBody ? ""
}: }:
let let
nodeSource = symlinkJoin { nodeSource = pkgs.symlinkJoin {
name = "${name}-node-sources"; name = "${name}-node-sources";
paths = [ builderPkg.lib ] ++ nodePackages; paths = [ builderPkg.lib ] ++ nodePackages;
}; };
baseWebpackConfig = builtins.readFile ./webpack.config.js; baseWebpackConfig = builtins.readFile ./webpack.config.js;
webpackConfig = '' webpackConfig = ''
const ROUTES = ${builtins.toJSON routes} const ROUTES = ${builtins.toJSON routes}
const PRETTY_NAME = ${builtins.toJSON prettyName} const PRETTY_NAME = ${builtins.toJSON prettyName}
const DESCRIPTION = ${builtins.toJSON description} const DESCRIPTION = ${builtins.toJSON description}
const THEME_COLOR = ${builtins.toJSON themeColor} const THEME_COLOR = ${builtins.toJSON themeColor}
const BACKGROUND_COLOR = ${builtins.toJSON backgroundColor} const BACKGROUND_COLOR = ${builtins.toJSON backgroundColor}
'' + "\n" + baseWebpackConfig; '' + "\n" + baseWebpackConfig;
webpackConfigFile = pkgs.writeText "${name}-webpack-config" webpackConfig; webpackConfigFile = pkgs.writeText "${name}-webpack-config" webpackConfig;
wandInit = pkgs.writeText "wand.js" '' wandInit = pkgs.writeText "wand.js" ''
document.body.innerHTML = ''' document.body.innerHTML = '''
const sourceTarget = document.createElement('script') const sourceTarget = document.createElement('script')
sourceTarget.src = '/main.js' sourceTarget.src = '/main.js'
document.body.appendChild(sourceTarget) document.body.appendChild(sourceTarget)
''; '';
templateHtml = pkgs.writeText "template.html" '' templateHtml = pkgs.writeText "template.html" ''
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/> <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>${prettyName}</title> <title>${prettyName}</title>
<link rel="apple-touch-icon" sizes="57x57" href="/appdata/apple-touch-icon-57x57.png"> <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="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="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="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="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="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="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="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="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="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-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: 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: 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: 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: 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: 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: 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: 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: 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: 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="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="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="32x32" href="/appdata/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="228x228" href="/appdata/coast-228x228.png"> <link rel="icon" type="image/png" sizes="228x228" href="/appdata/coast-228x228.png">
<link rel="manifest" href="/appdata/manifest.json"> <link rel="manifest" href="/appdata/manifest.json">
<link rel="shortcut icon" href="/appdata/favicon.ico"> <link rel="shortcut icon" href="/appdata/favicon.ico">
<link rel="yandex-tableau-widget" href="/appdata/yandex-browser-manifest.json"> <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-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title"> <meta name="apple-mobile-web-app-title">
<meta name="application-name" content="${prettyName}"> <meta name="application-name" content="${prettyName}">
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<meta name="msapplication-TileColor" content="#fff"> <meta name="msapplication-TileColor" content="#fff">
<meta name="msapplication-TileImage" content="/appdata/mstile-144x144.png"> <meta name="msapplication-TileImage" content="/appdata/mstile-144x144.png">
<meta name="msapplication-config" content="/appdata/browserconfig.xml"> <meta name="msapplication-config" content="/appdata/browserconfig.xml">
<meta name="theme-color" content="${themeColor}"> <meta name="theme-color" content="${themeColor}">
${extraHead} ${extraHead}
</head> </head>
<body> <body>
${extraBody} ${extraBody}
</body> </body>
${extraPostBody} ${extraPostBody}
</html> </html>
''; '';
in stdenv.mkDerivation { in
inherit name; pkgs.stdenv.mkDerivation {
inherit name;
src = elmCleanSource src; src = elmCleanSource src;
buildInputs = with workingElmPackages; [ elm nodeSource ]; buildInputs = with pkgs.elmPackages; [ elm nodeSource ];
patchPhase = '' patchPhase = ''
ln -sf ${nodeSource}/node_modules . ln -sf ${nodeSource}/node_modules .
cp ${webpackConfigFile} webpack.config.js cp ${webpackConfigFile} webpack.config.js
cp ${ cp ${
@ -232,9 +213,9 @@ let
} .imagemin-jpgify-webpack-plugin.js } .imagemin-jpgify-webpack-plugin.js
cp ${wandInit} wand.js cp ${wandInit} wand.js
cp ${templateHtml} template.html cp ${templateHtml} template.html
''; '';
shellHook = '' shellHook = ''
ln -sf ${nodeSource}/node_modules . ln -sf ${nodeSource}/node_modules .
rm -f webpack.config.js rm -f webpack.config.js
rm -f wand.js rm -f wand.js
@ -246,19 +227,19 @@ let
cp ${wandInit} wand.js cp ${wandInit} wand.js
cp ${templateHtml} template.html cp ${templateHtml} template.html
export NODE_PATH=$PWD/node_modules export NODE_PATH=$PWD/node_modules
''; '';
buildPhase = workingElmPackages.fetchElmDeps { buildPhase = pkgs.elmPackages.fetchElmDeps {
elmPackages = import (src + "/elm-srcs.nix"); elmPackages = import (src + "/elm-srcs.nix");
registryDat = src + "/registry.dat"; registryDat = src + "/registry.dat";
elmVersion = "0.19.1"; elmVersion = "0.19.1";
};
installPhase = ''
mkdir -p $out
${nodeSource}/node_modules/webpack-cli/bin/cli.js --mode production
mv dist/* $out
'';
}; };
installPhase = ''
mkdir -p $out
${nodeSource}/node_modules/webpack-cli/bin/cli.js --mode production
mv dist/* $out
'';
};
in in
{ inherit mkWandardFront; } { inherit mkWandardFront; }

77
flake.lock generated Normal file
View File

@ -0,0 +1,77 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1606424373,
"narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1612996220,
"narHash": "sha256-l2kzWXxL3vXr8VxUzRtORPJS0nFQ3E5kBPF/AYAK0wI=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "758b29b5a28b818e311ad540637a5c1e40867489",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pnpm2nix": {
"flake": false,
"locked": {
"lastModified": 1613295715,
"narHash": "sha256-bj4daCwh8AerFz65yUYRBkJTdP+PdvGKNozdbAdHiUI=",
"ref": "master",
"rev": "55487e9b92017d9cadf7e6ed4c090e15e7eaf8a9",
"revCount": 88,
"type": "git",
"url": "ssh://git@github.com/notgne2/pnpm2nix.git"
},
"original": {
"type": "git",
"url": "ssh://git@github.com/notgne2/pnpm2nix.git"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"nixpkgs": "nixpkgs",
"pnpm2nix": "pnpm2nix",
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1610051610,
"narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3982c9903e93927c2164caa727cd3f6a0e6d14cc",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

24
flake.nix Normal file
View File

@ -0,0 +1,24 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
pnpm2nix.url = "git+ssh://git@github.com/notgne2/pnpm2nix.git";
pnpm2nix.flake = false;
utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, utils, ... } @ inputs:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
lib = import ./default.nix pkgs inputs;
});
}