Skip to content

Commit

Permalink
chore(web): switch to napalm from yarn2nix
Browse files Browse the repository at this point in the history
These days, support for npm's package-lock.json seems to besser than for
yarn, so let's drop yarn2nix which is not quite where it needs to be
yet (we pinned an experimental branch after all) and use napalm instead.
For this we have to migrate from yarn to npm completely.

Using npmlock2nix would be preferrable (as it doesn't require building a
Haskell registry server), but there we end up running into an unsolved
issue [1].

[1]: svanderburg/node2nix#106
  • Loading branch information
sternenseemann committed Feb 27, 2022
1 parent caadef5 commit c3b4186
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 66 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ Then you should be able to run `likely-music` from the command line (in the latt
First make sure you have the following prerequisites installed:

* Functional Haskell environment, i. e. `ghc` and `cabal-install`
* `yarn`
* `npm`
* `esbuild`
* A MIDI to WAV synthesizer
* One possibility is fluidsynth:
* `fluidsynth`
Expand All @@ -71,15 +72,13 @@ Then run the following commands:
```bash
cd /path/to/likely-music

cd web
yarn install --pure-lockfile
yarn run build:assets
yarn run build:prod
pushd web
make

# optionally if you want to avoid relative path problems
export LIKELY_MUSIC_FRONTEND=/path/to/web/dist
export LIKELY_MUSIC_FRONTEND=$(realpath dist)

cd ..
popd
cabal v2-build
cabal v2-run likely-music-backend
```
Expand Down
12 changes: 10 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{ pkgs ? import <nixpkgs> {} }:
let
napalmSrc = builtins.fetchTarball {
url = "https://github.com/nix-community/napalm/archive/master.tar.gz";
};
in

import ./pkgs.nix { inherit pkgs; }
{ pkgs ? import <nixpkgs> {}
, napalm ? pkgs.callPackage napalmSrc {}
}:

import ./pkgs.nix { inherit pkgs napalm; }
6 changes: 4 additions & 2 deletions pkgs.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{ pkgs }:
{ pkgs, napalm }:

rec {
# likely-music haskellPackage
likely-music-lib = likely-music-backend;
likely-music-backend = pkgs.haskellPackages.callPackage ./likely-music-backend.nix { };

likely-music-frontend = pkgs.callPackage ./web { };
likely-music-frontend = pkgs.callPackage ./web {
inherit napalm;
};

# executable wrapper around everything with correct paths
likely-music = pkgs.runCommand "likely-music" { } ''
Expand Down
4 changes: 2 additions & 2 deletions web/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
DIST ?= dist
# Change this to "development" for source maps and non-minifyed code
NODE_ENV ?= production
# If true, we don't attempt to fetch dependencies via yarn
# If true, we don't attempt to fetch dependencies via npm
OFFLINE ?= false

ifeq ($(NODE_ENV),production)
Expand All @@ -26,7 +26,7 @@ $(DIST):
mkdir -p $@

node_modules:
$(OFFLINE) || yarn install --frozen-lockfile --prod
$(OFFLINE) || npm install --production --omit=peer --omit=dev

$(DIST)/vis-network.min.css: node_modules $(DIST)
$(ESBUILD) node_modules/vis-network/dist/dist/vis-network.min.css --outfile=$@
Expand Down
50 changes: 15 additions & 35 deletions web/default.nix
Original file line number Diff line number Diff line change
@@ -1,50 +1,30 @@
{ stdenv, lib, fetchFromGitHub, callPackage, esbuild }:
{ stdenv, lib, esbuild, napalm, nix-gitignore }:

let
pkgInfo = lib.importJSON ./package.json;
src = yarn2nix-lib.removePrefixes [ "node_modules" "dist" ] ./.;
# yarn2nixSrc = /home/lukas/src/nix/yarn2nix;
yarn2nixSrc = fetchFromGitHub {
owner = "sternenseemann";
repo = "yarn2nix";
rev = "b0825bbe4b40f39763d53ba0044431a44b5f25cf";
sha256 = "1q8wc5rnb00xwzcqsgb6wfkmymipf2bv1g2i33l5wyadp0hd18cp";
src = builtins.path {
name = "likely-music-frontend-source";
path = ./.;
filter = nix-gitignore.gitignoreFilter (builtins.readFile ../.gitignore) ./..;
};
yarn2nix = import yarn2nixSrc { };
yarn2nix-lib = yarn2nix.nixLib;
deps = yarn2nix-lib.callYarnLock ./yarn.lock { };
template = yarn2nix-lib.callPackageJson ./package.json { };
calledTemplate = template (yarn2nix-lib.buildNodeDeps deps);
node_modules = yarn2nix-lib.linkNodeDeps {
inherit (pkgInfo) name;
dependencies = calledTemplate.nodeBuildInputs;
};

in

stdenv.mkDerivation rec {
pname = pkgInfo.name;
inherit (pkgInfo) version;
inherit src;

nativeBuildInputs = [ esbuild ];

makeFlags = [
"OFFLINE=true"
napalm.buildPackage src {
nativeBuildInputs = [
esbuild
];

NODE_PATH = node_modules;
preBuild = ''
ln -s ${node_modules} node_modules
'';
npmCommands = "make";

installPhase = ''
mkdir -p $out/share/
mv dist $out/share/${pname}
runHook preInstall
mkdir -p $out/share
mv dist $out/share/likely-music-frontend
runHook postInstall
'';

meta = calledTemplate.meta // {
meta = {
description = "Frontend of likely music, a probabilistic music notation software";
homepage = "https://github.com/sternenseemann/likely-music";
license = lib.licenses.agpl3Only;
};
}
198 changes: 198 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions web/yarn.lock

This file was deleted.

0 comments on commit c3b4186

Please sign in to comment.