Skip to content

Commit

Permalink
Merge pull request #204 from input-output-hk/SRE-124_implement_yarn_w…
Browse files Browse the repository at this point in the history
…orkspaces

[SRE 124] Use local offline cache
  • Loading branch information
rhyslbw committed Jul 7, 2020
2 parents 232e274 + 03ea324 commit d26f06f
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 78 deletions.
94 changes: 43 additions & 51 deletions nix/cardano-graphql.nix
@@ -1,67 +1,59 @@
{ mkYarnPackage
, lib
, cardano-graphql-src
, runtimeShell
{ stdenv
, nix-inclusive
, nodejs
, python
, nodePackages
, runtimeShell
, sources
, yarn
}:

let
packageJSON = cardano-graphql-src + "/package.json";
version = (__fromJSON (__readFile packageJSON)).version;

in mkYarnPackage {
pname = "cardano-graphql";
inherit packageJSON version;
yarnLock = cardano-graphql-src + "/yarn.lock";
src = lib.cleanSourceWith {
filter = name: type: let
baseName = baseNameOf (toString name);
sansPrefix = lib.removePrefix (toString ../.) name;
in_blacklist =
lib.hasPrefix "/node_modules" sansPrefix ||
lib.hasPrefix "/build" sansPrefix ||
lib.hasPrefix "/.git" sansPrefix;
in_whitelist =
(type == "directory") ||
(lib.hasSuffix ".yml" name) ||
(lib.hasSuffix ".ts" name) ||
(lib.hasSuffix ".json" name) ||
(lib.hasSuffix ".graphql" name) ||
baseName == "package.json" ||
baseName == "yarn.lock" ||
(lib.hasPrefix "/deploy" sansPrefix);
in (
(!in_blacklist) && in_whitelist
);
src = cardano-graphql-src;
packageJSON = builtins.fromJSON (builtins.readFile ../package.json);

src = stdenv.mkDerivation {
pname = "${packageJSON.name}-src";
version = packageJSON.version;
buildInputs = [ yarn nodejs ];
src = nix-inclusive ./.. [
../yarn.lock
../.yarnrc
../package.json
../packages
../packages-cache
../tsconfig.json
../docker-compose.yml
];
buildCommand = ''
mkdir -p $out
cp -r $src/. $out/
cd $out
chmod -R u+w .
yarn --offline --frozen-lockfile --non-interactive
'';
};
yarnPreBuild = ''
mkdir -p $HOME/.node-gyp/${nodejs.version}
echo 9 > $HOME/.node-gyp/${nodejs.version}/installVersion
ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version}
'';

installPhase = ''
export PATH="$PATH:$node_modules/.bin"
in stdenv.mkDerivation {
pname = packageJSON.name;
version = packageJSON.version;
inherit src;
buildInputs = [ nodejs yarn ];
buildCommand = ''
mkdir -p $out
cp -r $src/. $out/
chmod -R u+w $out
patchShebangs $out
yarn run build
cd $out
pwd
ls -hal
cp -r deps/cardano-graphql/packages/server/dist $out
yarn build
find . -name node_modules -type d -print0 | xargs -0 rm -rf
yarn --production --offline --frozen-lockfile --non-interactive
mkdir -p $out/bin
cat <<EOF > $out/bin/cardano-graphql
#!${runtimeShell}
exec ${nodejs}/bin/node $out/index.js
exec ${nodejs}/bin/node $out/packages/server/dist/index.js
EOF
chmod +x $out/bin/cardano-graphql
'';

distPhase = ''
cp -r . $out
'';
}
1 change: 1 addition & 0 deletions nix/graphql-engine/hs-overlay.nix
Expand Up @@ -5,6 +5,7 @@ self: super: {
graphql-engine = haskell.lib.dontHaddock (haskell.lib.dontCheck (self.callPackage ./graphql-engine.nix { inherit sources; }));
graphql-parser = self.callPackage ./graphql-parser.nix {};
pg-client = self.callPackage ./pg-client.nix {};
network-uri = self.callPackage ./network-uri.nix { };
regex-tdfa = self.callHackageDirect { pkg = "regex-tdfa"; ver = "1.3.1.0"; sha256 = "1a0l7kdjzp98smfp969mgkwrz60ph24xy0kh2dajnymnr8vd7b8g"; } {};
regex-base = self.callHackageDirect { pkg = "regex-base"; ver = "0.94.0.0"; sha256 = "0x2ip8kn3sv599r7yc9dmdx7hgh5x632m45ga99ib5rnbn6kvn8x"; } {};
regex-posix = self.callHackageDirect { pkg = "regex-posix"; ver = "0.96.0.0"; sha256 = "0js977ahpz10642sbpb55mw9h01pilai6z201wgkncgkg2d69hl3"; } {};
Expand Down
18 changes: 18 additions & 0 deletions nix/graphql-engine/network-uri.nix
@@ -0,0 +1,18 @@
{ mkDerivation, base, deepseq, HUnit, parsec, stdenv
, test-framework, test-framework-hunit, test-framework-quickcheck2
}:
mkDerivation {
pname = "network-uri";
version = "2.6.1.0";
sha256 = "423e0a2351236f3fcfd24e39cdbc38050ec2910f82245e69ca72a661f7fc47f0";
revision = "1";
editedCabalFile = "141nj7q0p9wkn5gr41ayc63cgaanr9m59yym47wpxqr3c334bk32";
libraryHaskellDepends = [ base deepseq parsec ];
testHaskellDepends = [
base HUnit test-framework test-framework-hunit
test-framework-quickcheck2
];
homepage = "https://github.com/haskell/network-uri";
description = "URI manipulation";
license = stdenv.lib.licenses.bsd3;
}
5 changes: 1 addition & 4 deletions nix/packages.nix
@@ -1,14 +1,11 @@
{ pkgs, lib }:

let
# TODO: filter src to just the files needed to build
src = ../.;
packages = self: {
sources = import ./sources.nix;
cardano-graphql-src = src;
nodejs = pkgs.nodejs-12_x;
inherit (self.callPackage self.sources.yarn2nix {}) yarn2nix mkYarnModules mkYarnPackage;
inherit (import self.sources.niv {}) niv;
nix-inclusive = pkgs.callPackage "${self.sources.nix-inclusive}/inclusive.nix" {};
cardano-graphql = self.callPackage ./cardano-graphql.nix {};
hasura-cli-ext = self.callPackage ./hasura-cli-ext/impure.nix {};
persistgraphql = (self.callPackage ./persistgraphql {}).persistgraphql;
Expand Down
34 changes: 17 additions & 17 deletions nix/sources.json
Expand Up @@ -12,8 +12,8 @@
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"graphql-engine": {
"builtin": false,
"branch": "master",
"builtin": false,
"description": "Blazing fast, instant realtime GraphQL APIs on Postgres with fine grained access control, also trigger webhooks on database events.",
"homepage": "https://hasura.io",
"owner": "hasura",
Expand All @@ -36,16 +36,28 @@
"url": "https://github.com/input-output-hk/niv/archive/89da7b2e7ae0779fd351618fc74df1b1da5e6214.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"nix-inclusive": {
"branch": "master",
"description": "Simple inclusive file selection implementation for Nix",
"homepage": "",
"owner": "input-output-hk",
"repo": "nix-inclusive",
"rev": "dd80ddcc6850d130b591fbc9b0aacacfbb3cf47c",
"sha256": "0lv3vxfs17lh38s44pshdd1lz0asp2vxmm3fdm6vnfm4ypvv755m",
"type": "tarball",
"url": "https://github.com/input-output-hk/nix-inclusive/archive/dd80ddcc6850d130b591fbc9b0aacacfbb3cf47c.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "nixos-20.03",
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
"homepage": "https://github.com/NixOS/nixpkgs",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "933a5c89fdf0db2a41a1b3cf4a7e6538f91737b4",
"sha256": "1h31jahfch250slqy8nz3kp5ywq231zcyx3a5i7bn8drkmx68gya",
"rev": "f1a79c86358c5464c64b4fad00fca07a10e62a74",
"sha256": "1rjhw32j0bi464d4nwywcbnb1qi4gj27cqdpbqx9r61975zv84mm",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/933a5c89fdf0db2a41a1b3cf4a7e6538f91737b4.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/f1a79c86358c5464c64b4fad00fca07a10e62a74.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"vgo2nix": {
Expand All @@ -59,17 +71,5 @@
"type": "tarball",
"url": "https://github.com/nix-community/vgo2nix/archive/9286b289764831bd40c2a82fe311caef019056f4.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"yarn2nix": {
"branch": "master",
"description": "Generate nix expressions from a yarn.lock file",
"homepage": null,
"owner": "moretea",
"repo": "yarn2nix",
"rev": "9e7279edde2a4e0f5ec04c53f5cd64440a27a1ae",
"sha256": "0zz2lrwn3y3rb8gzaiwxgz02dvy3s552zc70zvfqc0zh5dhydgn7",
"type": "tarball",
"url": "https://github.com/moretea/yarn2nix/archive/9e7279edde2a4e0f5ec04c53f5cd64440a27a1ae.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
6 changes: 5 additions & 1 deletion release.nix
Expand Up @@ -21,7 +21,11 @@ pkgs.lib.fix (self: {
required = pkgs.releaseTools.aggregate {
name = "required";
constituents = with self; [
self.cardano-graphql
self.cardano-graphql.cardano-graphql-api-cardano-db-hasura
self.cardano-graphql.cardano-graphql-cli
self.cardano-graphql.cardano-graphql-client-ts
self.cardano-graphql.cardano-graphql-server
self.cardano-graphql.cardano-graphql-util
graphql-engine
hasura-cli
hasura-cli-ext
Expand Down
11 changes: 6 additions & 5 deletions shell.nix
Expand Up @@ -19,15 +19,15 @@ let
nix # Purely Functional Package Manager
nodePackages.node2nix # Generates a set of Nix expressions from a NPM package's package.json
packages.nodejs # Event-driven I/O framework for the V8 JavaScript engine
packages.cardano-graphql.cardano-graphql-server
pkgconfig # Allows packages to find out information about other packages
pkgs.packages.cardano-graphql
pkgs.packages.persistgraphql
pkgs.packages.hasura-cli
python # The Python Programming language
tmux # Terminal multiplexer
yarn # Dependency management for javascript
packages.vgo2nix # Convert go.mod files to nixpkgs buildGoPackage compatible deps.nix files
packages.yarn2nix # Generate nix expressions from a yarn.lock file
yarn2nix-moretea.yarn2nix # Converts yarn.lock files into nix expression
];

shellHook = ''
Expand All @@ -50,9 +50,10 @@ let
devops = pkgs.stdenv.mkDerivation {
name = "devops-shell";
buildInputs = [
niv # Dependency management for Nix projects
nodePackages.node2nix # Generates a set of Nix expressions from a NPM package's package.json
packages.vgo2nix # Convert go.mod files to nixpkgs buildGoPackage compatible deps.nix files
niv # Dependency management for Nix projects
nodePackages.node2nix # Generates a set of Nix expressions from a NPM package's package.json
packages.vgo2nix # Convert go.mod files to nixpkgs buildGoPackage compatible deps.nix files
yarn2nix-moretea.yarn2nix # Converts yarn.lock files into nix expression
];
shellHook = ''
echo "DevOps Tools" \
Expand Down

0 comments on commit d26f06f

Please sign in to comment.