Skip to content

Commit

Permalink
Merge pull request #476 from r-k-b/elm-review-offline
Browse files Browse the repository at this point in the history
let `elm-review --offline` succeed in Nix sandboxed builds
  • Loading branch information
r-k-b authored Sep 15, 2024
2 parents fabea0a + 9b7c36b commit 3d88cb0
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 238 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ TODO: include these in `nix flake check`:
# keeping dependencies up to date

dependabot should keep the elm.json dependencies up to date;
to keep the elm2nix / elm-srcs.nix dependencies up to date,
run `just update`.
to keep the nix dependencies up to date, run `just update`.

NB, these commands assume you've entered the provided dev shell.
`direnv allow` or `nix develop` should get you there.
Expand Down
129 changes: 126 additions & 3 deletions flake.lock

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

39 changes: 28 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@
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;
};
mkElmDerivation = {
url =
"github:r-k-b/mkElmDerivation?rev=ff580f55d0aad443d6f8fde2ab308275ce2fc3a7";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils }:
outputs =
{ elm-review-tool-src, self, mkElmDerivation, nixpkgs, flake-utils }:
let supportedSystems = with flake-utils.lib.system; [ x86_64-linux ];
in flake-utils.lib.eachSystem supportedSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pkgs = import nixpkgs {
inherit system;
overlays = [ mkElmDerivation.overlays.makeDotElmDirectoryCmd ];
};
inherit (pkgs) lib stdenv callPackage;
inherit (lib) fileset hasInfix hasSuffix;

Expand All @@ -26,7 +39,6 @@
(fileset.fileFilter (file: file.hasExt "elm") ./app)
./dist
./elm.json
./nix/elm/registry.dat
];

testsSrc = toSource [
Expand All @@ -40,17 +52,22 @@
./review/elm.json
];

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

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

built = callPackage ./nix/built.nix {
inherit elm2nix minimalElmSrc;
inherit compiledElmApp minimalElmSrc;
sourceInfo = self.sourceInfo;
};

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

peekSrc = name: src:
stdenv.mkDerivation {
Expand All @@ -61,15 +78,15 @@
};
in {
packages = {
inherit built;
inherit built compiledElmApp 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; };
devShells.default =
import ./nix/shell.nix { inherit elm-review-tool pkgs; };
apps.default = {
type = "app";
program = "${pkgs.writeScript "tularsApp" ''
Expand Down
6 changes: 1 addition & 5 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ live:
check:
nix flake check

# Regenerates the pinned dependency hashes for the sandboxed Nix builds.
update-elm:
update-elm-nix-deps

update-nix:
nix flake update

update: update-elm update-nix
update: update-nix

# Open the UI testing tool, Cypress.
e2e:
Expand Down
4 changes: 2 additions & 2 deletions nix/built.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ elm2nix, minimalElmSrc, pkgs, sourceInfo, stdenv }:
{ compiledElmApp, minimalElmSrc, pkgs, sourceInfo, stdenv }:
stdenv.mkDerivation {
name = "tulars";
src = minimalElmSrc;
Expand All @@ -21,6 +21,6 @@ stdenv.mkDerivation {
installPhase = ''
mkdir -p $out
cp -r dist/* $out/
cp ${elm2nix}/*.js $out/
cp ${compiledElmApp}/*.js $out/
'';
}
15 changes: 5 additions & 10 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@
# 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 {
inherit name src;

buildInputs = [ elmPackages.elm ]
nativeBuildInputs = [ elmPackages.elm ]
++ lib.optional outputJavaScript nodePackages.uglify-js;

buildPhase = pkgs.elmPackages.fetchElmDeps {
elmPackages = import srcs;
elmVersion = "0.19.1";
inherit registryDat;
};

installPhase = let
elmfile = module:
"${srcdir}/${builtins.replaceStrings [ "." ] [ "/" ] module}.elm";
extension = if outputJavaScript then "js" else "html";
in ''
${pkgs.makeDotElmDirectoryCmd { elmJson = ../elm.json; }}
mkdir -p $out/share/doc
${lib.concatStrings (map (module: ''
echo "compiling ${elmfile module}"
Expand All @@ -41,8 +36,8 @@ let
'';
};
in mkDerivation {
name = "tulars-elm2nix-0.1.0";
srcs = ./elm/elm-srcs.nix;
name = "tulars-mkElmDerivation-0.1.0";
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
'';
}
Loading

0 comments on commit 3d88cb0

Please sign in to comment.