-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
68 lines (66 loc) · 2.19 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# inspired by https://www.nmattia.com/posts/2022-12-18-lockfile-trick-package-npm-project-with-nix/
{
description = "The Gren programming language";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-24.05";
systems.url = "github:nix-systems/default";
};
outputs = {
self,
systems,
nixpkgs,
}: let
eachSystem = nixpkgs.lib.genAttrs (import systems);
pkgJson = builtins.fromJSON (builtins.readFile ./package.json);
pkgLock = builtins.fromJSON (builtins.readFile ./package-lock.json);
nodePkg = "nodejs_20";
in {
devShells = eachSystem (system: {
default = with import nixpkgs {inherit system;};
mkShell {
buildInputs = [
pkgs.${nodePkg}
pkgs.alejandra
];
};
});
packages = eachSystem (system: {
default = with import nixpkgs {inherit system;}; let
# Download all packages that end up in node_modules so they can be
# pulled from cache in the build phase when we are sandboxed.
gren = pkgs.fetchurl {
url = pkgLock.packages.${"node_modules/gren-lang"}.resolved;
hash = pkgLock.packages.${"node_modules/gren-lang"}.integrity;
};
postject = pkgs.fetchurl {
url = pkgLock.packages.${"node_modules/postject"}.resolved;
hash = pkgLock.packages.${"node_modules/postject"}.integrity;
};
commander = pkgs.fetchurl {
url = pkgLock.packages.${"node_modules/commander"}.resolved;
hash = pkgLock.packages.${"node_modules/commander"}.integrity;
};
in
pkgs.stdenv.mkDerivation {
src = ./.;
pname = "gren";
version = pkgJson.dependencies.${"gren-lang"};
buildInputs = [pkgs.${nodePkg}];
buildPhase = ''
export HOME=$PWD/.home
export npm_config_cache=$PWD/.npm
mkdir -p $out/js
cd $out/js
cp -r $src/. .
npm cache add "${gren}"
npm cache add "${postject}"
npm cache add "${commander}"
npm ci
'';
installPhase = ''
ln -s $out/js/node_modules/.bin $out/bin
'';
};
});
};
}