nix-helpers: e10a6f42d9fd0af372726a27c8356fbc37bcfe31

     1: # Checks for whether Racket is broken/unsupported on this arch/nixpkgs combo.
     2: # We provide two important things:
     3: #
     4: #  - A boolean indicating whether (as we understand it) Racket is broken
     5: #  - A test to check whether or not Racket is indeed broken or not
     6: #
     7: # Anyone making use of this boolean in their definition should also include the
     8: # test in their suite, to see whether it's still accurate.
     9: { fail, nixpkgsRelease, path, runCommand, withNix }:
    10: 
    11: with builtins;
    12: with {
    13:   # If we're on a system we think has a broken racket, we should check to
    14:   # make sure it actually is. If broken packages weren't so strict we could
    15:   # take a look at racket.meta.broken, but we can't since it may cause Nix
    16:   # to abort. Instead we define a test, which invokes Nix to do the check
    17:   # and see if it succeeds. This is complicated by two things:
    18:   #
    19:   #  - We need to run Nix inside a builder. withNix lets us do this.
    20:   #  - We need to ensure we're checking the version of nixpkgs that's called
    21:   #    us, which might not be <nixpkgs>. We use the 'path' attribute of
    22:   #    nixpkgs for this.
    23:   racket-override-still-needed =
    24:     runCommand "racket-override-still-needed-for-nixpkgs${nixpkgsRelease}"
    25:     (withNix { buildInputs = [ fail ]; }) ''
    26:       echo "Checking whether Racket in nixpkgs${nixpkgsRelease}," 1>&2
    27:       echo "from ${path}, is still broken on ${currentSystem}."   1>&2
    28:       KNOWN=0
    29:       BROKEN=0
    30: 
    31:       function go {
    32:         if [[ "$KNOWN" -eq 1 ]]
    33:         then
    34:           echo "Skipping '$1' since we know the result" 1>&2
    35:           return
    36:         fi
    37:         echo "Checking '$1'" 1>&2
    38:         nix-instantiate --eval -E \
    39:           "with builtins // { pkgs = import \"${path}\" {}; }; $1"
    40:       }
    41: 
    42:       # Check that we can actually look up packages, etc. None of these
    43:       # should trigger a 'package marked as broken' message.
    44: 
    45:       X=$(go 'abort "Checking abort triggers error"' 2>&1) &&
    46:         fail "'abort' didn't abort:\n$X"
    47: 
    48:       X=$(go 'true'                       2>&1) ||
    49:         fail "'true' failed:\n$X"
    50:       X=$(go 'pkgs ? bash   || abort "x"' 2>&1) ||
    51:         fail "Couldn't find bash:\n$X"
    52:       X=$(go 'pkgs ? racket || abort "x"' 2>&1) ||
    53:         fail "Couldn't find racket:\n$X"
    54:       X=$(go 'pkgs.racket ? meta || abort "No racket.meta"' 2>&1) ||
    55:         fail "Couldn't find racket.meta:\n$X"
    56: 
    57:       # Now we try to check whether racket is broken. We need to
    58:       # distinguish between true/false booleans and aborted evaluation.
    59: 
    60:       X=$(go 'let x = typeOf pkgs.racket.meta; in x == x' 2>&1) || {
    61:         echo "Evaling racket.meta aborted:\n$X\Looks broken to me" 1>&2
    62:         KNOWN=1
    63:         BROKEN=1
    64:       }
    65: 
    66:       X=$(go 'pkgs.racket.meta ? broken' 2>&1) || {
    67:         echo "Evaling meta.broken aborted:\n$X\nLooks broken to me" 1>&2
    68:         KNOWN=1
    69:         BROKEN=1
    70:       }
    71: 
    72:       if [[ "$KNOWN" -eq 0 ]] &&
    73:          X=$(go 'pkgs.racket.meta ? broken && abort "No broken"' 2>&1)
    74:       then
    75:         echo "Can eval 'racket.meta' and it has no 'broken'" 1>&2
    76:         KNOWN=1
    77:         BROKEN=0
    78:       fi
    79: 
    80:       X=$(go 'pkgs.racket.meta.broken' 2>&1) || {
    81:         echo "Evaling meta.broken aborted:\n$X\nLooks broken to me" 1>&2
    82:         KNOWN=1
    83:         BROKEN=1
    84:       }
    85: 
    86:       if [[ "$KNOWN" -eq 0 ]]
    87:       then
    88:         if X=$(go 'pkgs.racket.meta.broken && abort "Broken"' 2>&1)
    89:         then
    90:           echo "pkgs.racket.meta.broken is true" 1>&2
    91:           KNOWN=1
    92:           BROKEN=1
    93:         else
    94:           echo "pkgs.racket.meta.broken is false" 1>&2
    95:           KNOWN=1
    96:           BROKEN=1
    97:         fi
    98:       fi
    99: 
   100:       [[ "$KNOWN" -eq 1 ]] || fail "Couldn't tell if broken"
   101: 
   102:       # Subsequent nixpkgs versions avoid 'broken' in favour of checking
   103:       # the 'platforms', so we try checking that
   104:       if [[ "$BROKEN" -eq 0 ]]
   105:       then
   106:         echo "Racket is apparently not broken; checking platforms" 1>&2
   107:         KNOWN=0
   108:         X=$(go 'pkgs.racket.meta ? platforms' 2>&1) ||
   109:           fail "Evaling meta.platforms aborted:\n$X"
   110:         if X=$(go 'pkgs.racket.meta ? platforms || abort "None"' 2>&1)
   111:         then
   112:           X=$(go 'elem currentSystem pkgs.racket.meta.platforms ||
   113:                   abort "currentSystem not in platforms"' 2>&1) || {
   114:             echo "Current system not in Racket's supported platforms" 1>&2
   115:             KNOWN=1
   116:             BROKEN=1
   117:           }
   118:         fi
   119:       fi
   120: 
   121:       [[ "$KNOWN" -eq 1 ]] || fail "Still couldn't tell if broken"
   122: 
   123:       if [[ "$BROKEN" -eq 0 ]]
   124:       then
   125:         echo "Racket is apparently not broken; checking if it evals" 1>&2
   126:         X=$(nix-instantiate -E '(import "${path}" {}).racket' 2>&1) ||
   127:           fail "Racket is broken:\n$X\nOur checks failed to spot it"
   128: 
   129:         # If it's fixed, we'll need to redefine racketWorks
   130:         fail "Racket doesn't seem to be broken. Maybe it's fixed?" 1>&2
   131:       fi
   132: 
   133:       echo "Checking that racket truly is broken" 1>&2
   134:       X=$(nix-instantiate -E '(import "${path}" {}).racket' 2>&1) &&
   135:         fail "Our checks said Racket is broken, but it worked"
   136:       echo "Yes, we thought racket was broken and it is." 1>&2
   137:       echo "Our override is still needed. Test passed."
   138: 
   139:       mkdir "$out"
   140:     '';
   141: 
   142:   racket-override-not-needed =
   143:     runCommand "racket-override-not-needed-for-nixpkgs${nixpkgsRelease}"
   144:     (withNix { buildInputs = [ fail ]; }) ''
   145:       X=$(nix-instantiate -E '(import "${path}" {}).racket' 2>&1) ||
   146:         fail "Couldn't instantiate Racket:\n$X\nSeems broken to me!"
   147:       mkdir "$out"
   148:     '';
   149: }; rec {
   150:   racketWorks = !(elem currentSystem [ "i686-linux" "x86_64-darwin" ])
   151:     || compareVersions nixpkgsRelease "1703" == -1;
   152: 
   153:   checkWhetherBroken = if racketWorks then {
   154:     inherit racket-override-not-needed;
   155:   } else {
   156:     inherit racket-override-still-needed;
   157:   };
   158: }

Generated by git2html.