From 6fbcf18e3bad6accdeca0f9ff5d25509b3e8536f Mon Sep 17 00:00:00 2001 From: notgne2 Date: Sun, 14 Feb 2021 03:12:33 -0700 Subject: [PATCH] add compat thingy --- default.nix | 256 +++------------------------------------------------- flake.nix | 2 +- wand.nix | 245 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 260 insertions(+), 243 deletions(-) create mode 100644 wand.nix diff --git a/default.nix b/default.nix index 93a424e..73df194 100644 --- a/default.nix +++ b/default.nix @@ -1,245 +1,17 @@ -pkgs: inputs: -let - pnpm2nix = pkgs.callPackage inputs.pnpm2nix { }; +# SPDX-FileCopyrightText: 2020 Serokell +# +# 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" '' - - - - - ${prettyName} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ${extraHead} - - - ${extraBody} - - ${extraPostBody} - - ''; + 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 diff --git a/flake.nix b/flake.nix index f74de0b..564a635 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,6 @@ pkgs = import nixpkgs { inherit system; }; in { - lib = import ./default.nix pkgs inputs; + lib = import ./wand.nix pkgs inputs; }); } diff --git a/wand.nix b/wand.nix new file mode 100644 index 0000000..93a424e --- /dev/null +++ b/wand.nix @@ -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" '' + + + + + ${prettyName} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${extraHead} + + + ${extraBody} + + ${extraPostBody} + + ''; + 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; }