Skip to content

Commit

Permalink
wip: try to bring elm-review inside the sandboxed build
Browse files Browse the repository at this point in the history
  • Loading branch information
r-k-b committed Jul 28, 2024
1 parent 149f214 commit 0d2de4f
Show file tree
Hide file tree
Showing 13 changed files with 362 additions and 20 deletions.
17 changes: 17 additions & 0 deletions flake.lock

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

24 changes: 19 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/nixos-unstable";
elm-review-tool-src = {
url = "github:jfmengels/node-elm-review";
flake = false;
};
};

outputs = { self, nixpkgs, flake-utils }:
outputs = { elm-review-tool-src, self, nixpkgs, flake-utils }:
let supportedSystems = with flake-utils.lib.system; [ x86_64-linux ];
in flake-utils.lib.eachSystem supportedSystems (system:
let
Expand All @@ -26,7 +30,7 @@
(fileset.fileFilter (file: file.hasExt "elm") ./app)
./dist
./elm.json
./nix/elm/registry.dat
#./nix/elm/registry.dat
];

testsSrc = toSource [
Expand All @@ -43,6 +47,12 @@
failIfDepsOutOfSync =
callPackage ./nix/failIfDepsOutOfSync.nix { inherit minimalElmSrc; };

elm-review-tool = callPackage ./nix/elm-review-tool.nix {
inherit elm-review-tool-src;
};

fetchElmDepsWithDocs = callPackage ./nix/fetchElmDepsWithDocs.nix { };

elm2nix = callPackage ./nix/default.nix { inherit minimalElmSrc; };

built = callPackage ./nix/built.nix {
Expand All @@ -51,6 +61,9 @@
};

elmtests = callPackage ./nix/elmtests.nix { inherit testsSrc; };
elmReviewed = callPackage ./nix/elmReviewed.nix {
inherit elm-review-tool fetchElmDepsWithDocs reviewSrc;
};

peekSrc = name: src:
stdenv.mkDerivation {
Expand All @@ -61,15 +74,16 @@
};
in {
packages = {
inherit built;
inherit built elm-review-tool;
default = built;
rawElm2Nix = elm2nix;
minimalElmSrc = peekSrc "minimal-elm" minimalElmSrc;
testsSrc = peekSrc "tests" testsSrc;
reviewSrc = peekSrc "elm-review" reviewSrc;
};
checks = { inherit built elmtests failIfDepsOutOfSync; };
devShells.default = import ./nix/shell.nix { inherit pkgs; };
checks = { inherit built elmReviewed elmtests failIfDepsOutOfSync; };
devShells.default =
import ./nix/shell.nix { inherit elm-review-tool pkgs; };
apps.default = {
type = "app";
program = "${pkgs.writeScript "tularsApp" ''
Expand Down
6 changes: 3 additions & 3 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# with (import nixpkgs config);
{ elmPackages, lib, pkgs, minimalElmSrc, nodePackages, stdenv }:
let
mkDerivation = { srcs ? ./elm/elm-srcs.nix, src, name, srcdir ? "../src"
mkDerivation = { srcs ? ./elm/elm-srcs-main.nix, src, name, srcdir ? "../src"
, targets ? [ ], registryDat ? ./elm/registry.dat, outputJavaScript ? false
}:
stdenv.mkDerivation {
Expand All @@ -15,7 +15,7 @@ let
buildInputs = [ elmPackages.elm ]
++ lib.optional outputJavaScript nodePackages.uglify-js;

buildPhase = pkgs.elmPackages.fetchElmDeps {
buildPhase = elmPackages.fetchElmDeps {
elmPackages = import srcs;
elmVersion = "0.19.1";
inherit registryDat;
Expand All @@ -42,7 +42,7 @@ let
};
in mkDerivation {
name = "tulars-elm2nix-0.1.0";
srcs = ./elm/elm-srcs.nix;
srcs = ./elm/elm-srcs-main.nix;
src = minimalElmSrc;
targets = [ "Main" ];
srcdir = "./app";
Expand Down
48 changes: 48 additions & 0 deletions nix/elm-review-offline-details.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Index: lib/project-dependencies.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/project-dependencies.js b/lib/project-dependencies.js
--- a/lib/project-dependencies.js (revision f0894b30a252e7db739546efa17f2ded174d167a)
+++ b/lib/project-dependencies.js (date 1722160229220)
@@ -33,6 +33,7 @@
packageVersion
).catch(() => {
hasDependenciesThatCouldNotBeDownloaded = true;
+ console.log('getDocsJson failed:', {elmVersion, name, packageVersion});
return [];
}),
ProjectJsonFiles.getElmJson(
@@ -42,6 +43,7 @@
packageVersion
).catch(() => {
hasDependenciesThatCouldNotBeDownloaded = true;
+ console.log('getElmJson failed:', {elmVersion, name, packageVersion})
return defaultElmJson(name, packageVersion);
})
]);
Index: lib/project-json-files.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/project-json-files.js b/lib/project-json-files.js
--- a/lib/project-json-files.js (revision f0894b30a252e7db739546efa17f2ded174d167a)
+++ b/lib/project-json-files.js (date 1722162109928)
@@ -46,6 +46,7 @@
} catch (error) {
// Finally, try to download it from the packages website
if (options.offline) {
+ console.log('getElmJson read failed', {cacheLocation})
// Unless we're in offline mode
throw error;
}
@@ -147,6 +148,7 @@
} catch (error) {
// Finally, try to download it from the packages website
if (options.offline) {
+ console.log('getDocsJson read failed', {cacheLocation})
// Unless we're in offline mode
throw error;
}
27 changes: 27 additions & 0 deletions nix/elm-review-tool.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ elm-review-tool-src, elmPackages, pkgs, stdenv }:
pkgs.buildNpmPackage {
name = "elm-review";
src = elm-review-tool-src;
npmDepsHash =
# pkgs.lib.fakeHash;
"sha256-BnvEdkKiFbUtEFGom9ZaCqZzId4ViGU3PlZ/BJCmX4A=";
patches = [ ./elm-review-offline-details.patch ];
nativeBuildInputs = with pkgs; [ coreutils ];
buildInputs = with elmPackages; [ elm elm-format ];
buildPhase = ''
substituteInPlace ./package.json \
--replace-fail '"elm-tooling install"' '"echo skipping elm-tooling"'
mkdir -p "$out"
cp -r * "$out"/
mv $out/bin/elm-review $out/bin/elm-review.js
cat << EOF > $out/bin/elm-review
#!${pkgs.bash}/bin/bash
${pkgs.nodejs}/bin/node ./elm-review.js \
--namespace="elm-review-nix-from-src" \
--compiler="${elmPackages.elm}/bin/elm \
--elm-format-path="${elmPackages.elm-format}/bin/elm-format \
"$@"
EOF
chmod +x $out/bin/elm-review
'';
}
File renamed without changes.
117 changes: 117 additions & 0 deletions nix/elm/elm-srcs-review.nix

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

44 changes: 44 additions & 0 deletions nix/elmReviewed.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{ elm-review-tool, elmPackages, fetchElmDepsWithDocs, lib, pkgs, stdenv
, reviewSrc }:
let
elmVersion = "0.19.1";
elmPkgDeps = import ./elm/elm-srcs-main.nix
// import ./elm/elm-srcs-review.nix;

mkDocs = lib.mapAttrsToList (name: info:
let _ = "";
in ''
base="$PWD"
echo "zzz base is $base"
echo "zzz EH is $ELM_HOME"
echo .elm/${elmVersion}/packages/${name}/${info.version}
cd .elm/${elmVersion}/packages/${name}/${info.version}
elm make --docs=docs.json
cd "$base"
'') elmPkgDeps;
in stdenv.mkDerivation {
name = "elm-reviewed";
src = reviewSrc;

buildInputs = with elmPackages; [
elm
elm-json
elm-review-tool
pkgs.breakpointHook
];

buildPhase = elmPackages.fetchElmDeps {
inherit elmVersion;
elmPackages = elmPkgDeps;
registryDat = ./elm/registry.dat;
};

installPhase = ''
set -e
'' + (lib.concatStrings mkDocs) + ''
mkdir -p .elm/elm-review/2.12.0
ln -s ../../${elmVersion} .elm/elm-review/2.12.0/${elmVersion}
elm-review --offline
echo "passed" > $out
'';
}
2 changes: 1 addition & 1 deletion nix/elmtests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stdenv.mkDerivation {
buildInputs = with elmPackages; [ elm elm-test ];

buildPhase = pkgs.elmPackages.fetchElmDeps {
elmPackages = import ./elm/elm-srcs.nix;
elmPackages = import ./elm/elm-srcs-main.nix;
elmVersion = "0.19.1";
registryDat = ./elm/registry.dat;
};
Expand Down
2 changes: 1 addition & 1 deletion nix/failIfDepsOutOfSync.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ stdenv.mkDerivation {
jq . --sort-keys < ${
pkgs.writeText "elmSrcsNixFlattened.json" (builtins.toJSON
(builtins.mapAttrs (k: value: value.version)
(import ./elm/elm-srcs.nix)))
(import ./elm/elm-srcs-main.nix)))
} > flat-nix-deps.json
if diff flat-elm-deps.json flat-nix-deps.json; then
Expand Down
11 changes: 11 additions & 0 deletions nix/fetchElmDepsWithDocs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# based on https://github.com/NixOS/nixpkgs/blob/ae5eab1bf17d71ab2e7c467aa13ccd3811d73fff/pkgs/development/compilers/elm/lib/fetchElmDeps.nix
{ pkgs, fetchurl }:

{ elmPackages, registryDat, elmVersion }:

let
makeDotElm =
pkgs.callPackage ./makeDotElmWithDocs.nix { inherit registryDat; };
in ''
export ELM_HOME=`pwd`/.elm
'' + (makeDotElm elmVersion elmPackages)
Loading

0 comments on commit 0d2de4f

Please sign in to comment.