mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 11:45:45 +03:00
web-devmode: call as package
This commit is contained in:
parent
2f0c10a073
commit
849cf13725
3 changed files with 56 additions and 61 deletions
|
@ -1,20 +1,13 @@
|
||||||
let
|
let
|
||||||
pkgs = import ../. {
|
pkgs = import ../. {
|
||||||
config = {};
|
config = { };
|
||||||
overlays = [];
|
overlays = [ ];
|
||||||
};
|
};
|
||||||
|
|
||||||
common = import ./common.nix;
|
common = import ./common.nix;
|
||||||
inherit (common) outputPath indexPath;
|
inherit (common) outputPath indexPath;
|
||||||
|
in
|
||||||
web-devmode = import ../pkgs/tools/nix/web-devmode.nix {
|
pkgs.callPackage ../pkgs/tools/nix/web-devmode.nix {
|
||||||
inherit pkgs;
|
|
||||||
buildArgs = "./.";
|
buildArgs = "./.";
|
||||||
open = "/${outputPath}/${indexPath}";
|
open = "/${outputPath}/${indexPath}";
|
||||||
};
|
}
|
||||||
in
|
|
||||||
pkgs.mkShell {
|
|
||||||
packages = [
|
|
||||||
web-devmode
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
let
|
let
|
||||||
pkgs = import ../../.. {
|
pkgs = import ../../.. {
|
||||||
config = {};
|
config = { };
|
||||||
overlays = [];
|
overlays = [ ];
|
||||||
};
|
};
|
||||||
|
|
||||||
common = import ./common.nix;
|
common = import ./common.nix;
|
||||||
inherit (common) outputPath indexPath;
|
inherit (common) outputPath indexPath;
|
||||||
|
in
|
||||||
web-devmode = import ../../../pkgs/tools/nix/web-devmode.nix {
|
pkgs.callPackage ../../../pkgs/tools/nix/web-devmode.nix {
|
||||||
inherit pkgs;
|
|
||||||
buildArgs = "../../release.nix -A manualHTML.${builtins.currentSystem}";
|
buildArgs = "../../release.nix -A manualHTML.${builtins.currentSystem}";
|
||||||
open = "/${outputPath}/${indexPath}";
|
open = "/${outputPath}/${indexPath}";
|
||||||
};
|
}
|
||||||
in
|
|
||||||
pkgs.mkShell {
|
|
||||||
packages = [
|
|
||||||
web-devmode
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
{
|
{
|
||||||
pkgs,
|
lib,
|
||||||
|
findutils,
|
||||||
|
mkShell,
|
||||||
|
nodejs_latest,
|
||||||
|
parallel,
|
||||||
|
rsync,
|
||||||
|
watchexec,
|
||||||
|
writeShellScriptBin,
|
||||||
# arguments to `nix-build`, e.g. `"foo.nix -A bar"`
|
# arguments to `nix-build`, e.g. `"foo.nix -A bar"`
|
||||||
buildArgs,
|
buildArgs,
|
||||||
# what path to open a browser at
|
# what path to open a browser at
|
||||||
open,
|
open,
|
||||||
}: let
|
}:
|
||||||
inherit (pkgs) lib;
|
let
|
||||||
|
inherit (nodejs_latest.pkgs) live-server;
|
||||||
|
|
||||||
error_page = pkgs.writeShellScriptBin "error_page" ''
|
error_page = writeShellScriptBin "error_page" ''
|
||||||
echo "<!DOCTYPE html>
|
echo "<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -30,7 +38,7 @@
|
||||||
# Using rsync here, instead of `cp`, to get as close to an atomic
|
# Using rsync here, instead of `cp`, to get as close to an atomic
|
||||||
# directory copy operation as possible. `--delay-updates` should
|
# directory copy operation as possible. `--delay-updates` should
|
||||||
# also go towards that.
|
# also go towards that.
|
||||||
build_and_copy = pkgs.writeShellScriptBin "build_and_copy" ''
|
build_and_copy = writeShellScriptBin "build_and_copy" ''
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
@ -41,7 +49,7 @@
|
||||||
if [ $exit_status -eq 0 ];
|
if [ $exit_status -eq 0 ];
|
||||||
then
|
then
|
||||||
# setting permissions to be able to clean up
|
# setting permissions to be able to clean up
|
||||||
${lib.getBin pkgs.rsync}/bin/rsync \
|
${lib.getBin rsync}/bin/rsync \
|
||||||
--recursive \
|
--recursive \
|
||||||
--chmod=u=rwX \
|
--chmod=u=rwX \
|
||||||
--delete-before \
|
--delete-before \
|
||||||
|
@ -53,7 +61,7 @@
|
||||||
${lib.getBin error_page}/bin/error_page "$stderr" > $error_page_absolute
|
${lib.getBin error_page}/bin/error_page "$stderr" > $error_page_absolute
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
${lib.getBin pkgs.findutils}/bin/find $serve \
|
${lib.getBin findutils}/bin/find $serve \
|
||||||
-type f \
|
-type f \
|
||||||
! -name $error_page_relative \
|
! -name $error_page_relative \
|
||||||
-delete
|
-delete
|
||||||
|
@ -61,10 +69,10 @@
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# https://watchexec.github.io/
|
# https://watchexec.github.io/
|
||||||
watcher = pkgs.writeShellScriptBin "watcher" ''
|
watcher = writeShellScriptBin "watcher" ''
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
${lib.getBin pkgs.watchexec}/bin/watchexec \
|
${lib.getBin watchexec}/bin/watchexec \
|
||||||
--shell=none \
|
--shell=none \
|
||||||
--restart \
|
--restart \
|
||||||
--print-events \
|
--print-events \
|
||||||
|
@ -74,10 +82,10 @@
|
||||||
# A Rust alternative to live-server exists, but it was not in nixpkgs.
|
# A Rust alternative to live-server exists, but it was not in nixpkgs.
|
||||||
# `--no-css-inject`: without this it seems that only CSS is auto-reloaded.
|
# `--no-css-inject`: without this it seems that only CSS is auto-reloaded.
|
||||||
# https://www.npmjs.com/package/live-server
|
# https://www.npmjs.com/package/live-server
|
||||||
server = pkgs.writeShellScriptBin "server" ''
|
server = writeShellScriptBin "server" ''
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
${lib.getBin pkgs.nodePackages_latest.live-server}/bin/live-server \
|
${lib.getBin live-server}/bin/live-server \
|
||||||
--host=127.0.0.1 \
|
--host=127.0.0.1 \
|
||||||
--verbose \
|
--verbose \
|
||||||
--no-css-inject \
|
--no-css-inject \
|
||||||
|
@ -86,9 +94,7 @@
|
||||||
$serve
|
$serve
|
||||||
'';
|
'';
|
||||||
|
|
||||||
devmode =
|
devmode = writeShellScriptBin "devmode" ''
|
||||||
pkgs.writeShellScriptBin "devmode"
|
|
||||||
''
|
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
function handle_exit {
|
function handle_exit {
|
||||||
|
@ -105,7 +111,7 @@
|
||||||
export error_page_absolute=$serve/$error_page_relative
|
export error_page_absolute=$serve/$error_page_relative
|
||||||
${lib.getBin error_page}/bin/error_page "building …" > $error_page_absolute
|
${lib.getBin error_page}/bin/error_page "building …" > $error_page_absolute
|
||||||
|
|
||||||
${lib.getBin pkgs.parallel}/bin/parallel \
|
${lib.getBin parallel}/bin/parallel \
|
||||||
--will-cite \
|
--will-cite \
|
||||||
--line-buffer \
|
--line-buffer \
|
||||||
--tagstr '{/}' \
|
--tagstr '{/}' \
|
||||||
|
@ -114,4 +120,7 @@
|
||||||
"${lib.getBin server}/bin/server"
|
"${lib.getBin server}/bin/server"
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
devmode
|
mkShell {
|
||||||
|
name = "web-devmode";
|
||||||
|
packages = [ devmode ];
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue