Skip to content

Commit

Permalink
Remove obsolete test, add a simple test for buildNpmPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyavinogradov committed Nov 29, 2019
1 parent 06f5059 commit 9c9ef7d
Show file tree
Hide file tree
Showing 8 changed files with 3,751 additions and 13 deletions.
18 changes: 6 additions & 12 deletions .travis.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# TODO:
# * replace w/ more generic test
# * also test npm packages
# * unhide badge

{ pkgs ? import <nixpkgs> {} }:
let
bp = pkgs.callPackage ./default.nix {};
# we pin nixpkgs revision for tests
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs {};

npm-buildpackage = pkgs.callPackage ./default.nix {};
in
import (fetchGit {
url = "https://github.com/obfusk/nix-vault-with-ui.git";
rev = "664d3d9a1f30626d0277a62c520cf82df0e0a2a1";
ref = "664d3d9-tag-you-are-it"; # TODO: "v0.1.0"
}) { inherit pkgs; npm-buildpackage = bp; }
import ./tests/buildNpmPackage { inherit pkgs npm-buildpackage; }
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: nix
nix: 2.1.3
nix: 2.3.1
script: nix-build .travis.nix
14 changes: 14 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"nixpkgs": {
"branch": "master",
"description": "Nix Packages collection",
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a36b2925a5082e821ad80b3a7bfedcc6e488b91c",
"sha256": "14sx173cg1g1lpd5hcarxxz8n78jsffr6pv9l05a58aq0ilgk328",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/a36b2925a5082e821ad80b3a7bfedcc6e488b91c.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
93 changes: 93 additions & 0 deletions nix/sources.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# This file has been generated by Niv.

# A record, from name to path, of the third-party packages
with rec
{
pkgs =
if hasNixpkgsPath
then
if hasThisAsNixpkgsPath
then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}
else import <nixpkgs> {}
else
import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {};

sources_nixpkgs =
if builtins.hasAttr "nixpkgs" sources
then sources.nixpkgs
else abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';

# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball =
{ url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
else
fetchTarball attrs;

# fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl =
{ url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12" then
fetchurl { inherit url; }
else
fetchurl attrs;

# A wrapper around pkgs.fetchzip that has inspectable arguments,
# annoyingly this means we have to specify them
fetchzip = { url, sha256 }@attrs: pkgs.fetchzip attrs;

# A wrapper around pkgs.fetchurl that has inspectable arguments,
# annoyingly this means we have to specify them
fetchurl = { url, sha256 }@attrs: pkgs.fetchurl attrs;

hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success;
hasThisAsNixpkgsPath =
(builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.;

sources = builtins.fromJSON (builtins.readFile ./sources.json);

mapAttrs = builtins.mapAttrs or
(f: set: with builtins;
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));

# borrowed from nixpkgs
functionArgs = f: f.__functionArgs or (builtins.functionArgs f);
callFunctionWith = autoArgs: f: args:
let auto = builtins.intersectAttrs (functionArgs f) autoArgs;
in f (auto // args);

getFetcher = spec:
let fetcherName =
if builtins.hasAttr "type" spec
then builtins.getAttr "type" spec
else "builtin-tarball";
in builtins.getAttr fetcherName {
"tarball" = fetchzip;
"builtin-tarball" = builtins_fetchTarball;
"file" = fetchurl;
"builtin-url" = builtins_fetchurl;
};
};
# NOTE: spec must _not_ have an "outPath" attribute
mapAttrs (_: spec:
if builtins.hasAttr "outPath" spec
then abort
"The values in sources.json should not have an 'outPath' attribute"
else
if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
then
spec //
{ outPath = callFunctionWith spec (getFetcher spec) { }; }
else spec
) sources
2 changes: 2 additions & 0 deletions tests/buildNpmPackage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
out/
8 changes: 8 additions & 0 deletions tests/buildNpmPackage/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ pkgs, npm-buildpackage }:

npm-buildpackage.buildNpmPackage {
packageJson = ./package.json;
packageLockJson = ./package-lock.json;
src = builtins.filterSource (path: type: baseNameOf path != "node_modules" && baseNameOf path != "out") ./.;
npmBuild = "npm run build";
}
Loading

0 comments on commit 9c9ef7d

Please sign in to comment.