nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 runCommand,
4 srcOnly,
5 hello,
6 emptyDirectory,
7 zlib,
8 stdenv,
9 testers,
10}:
11
12let
13 emptySrc = srcOnly emptyDirectory;
14 zlibSrc = srcOnly zlib;
15
16 # It can be invoked in a number of ways. Let's make sure they're equivalent.
17 zlibSrcDrvAttrs = srcOnly zlib.drvAttrs;
18 # zlibSrcFreeform = # ???;
19 helloSrc = srcOnly hello;
20 helloSrcDrvAttrs = srcOnly hello.drvAttrs;
21
22 # The srcOnly <drv> invocation leaks a lot of attrs into the srcOnly derivation,
23 # so for comparing with the freeform invocation, we need to make a selection.
24 # Otherwise, we'll be comparing against whatever attribute the fancy hello drv
25 # has.
26 helloDrvSimple = stdenv.mkDerivation {
27 inherit (hello)
28 name
29 pname
30 version
31 src
32 patches
33 ;
34 };
35 helloDrvSimpleSrc = srcOnly helloDrvSimple;
36 helloDrvSimpleSrcFreeform = srcOnly (
37 {
38 inherit (helloDrvSimple)
39 name
40 pname
41 version
42 src
43 patches
44 stdenv
45 ;
46 }
47 # __impureHostDeps get duplicated in helloDrvSimpleSrc (on darwin)
48 # This is harmless, but fails the test for what is arguably an
49 # unrelated non-problem, so we just work around it here.
50 # The inclusion of __impureHostDeps really shouldn't be required,
51 # and should be removed from this test.
52 // lib.optionalAttrs (helloDrvSimple ? __impureHostDeps) {
53 inherit (helloDrvSimple) __impureHostDeps;
54 }
55 );
56
57in
58
59runCommand "srcOnly-tests"
60 {
61 moreTests = [
62 (testers.testEqualDerivation "zlibSrcDrvAttrs == zlibSrc" zlibSrcDrvAttrs zlibSrc)
63 # (testers.testEqualDerivation
64 # "zlibSrcFreeform == zlibSrc"
65 # zlibSrcFreeform
66 # zlibSrc)
67 (testers.testEqualDerivation "helloSrcDrvAttrs == helloSrc" helloSrcDrvAttrs helloSrc)
68 (testers.testEqualDerivation "helloDrvSimpleSrcFreeform == helloDrvSimpleSrc"
69 helloDrvSimpleSrcFreeform
70 helloDrvSimpleSrc
71 )
72 ];
73 }
74 ''
75 # Test that emptySrc is empty
76 if [ -n "$(ls -A ${emptySrc})" ]; then
77 echo "emptySrc is not empty"
78 exit 1
79 fi
80
81 # Test that zlibSrc is not empty
82 if [ -z "$(ls -A ${zlibSrc})" ]; then
83 echo "zlibSrc is empty"
84 exit 1
85 fi
86
87 # Make $out exist to avoid build failure
88 mkdir -p $out
89 ''