2 # This derivation confirms that the version of hpack used by stack in Nixpkgs
3 # is the exact same version as the upstream stack release.
5 # It is important to make sure the version of hpack used by stack in Nixpkgs
6 # matches with the version of hpack used by the upstream stack release. This
7 # is because hpack works slightly differently based on the version, and it can
8 # be frustrating to use hpack in a team setting when members are using different
9 # versions. See for more info: https://github.com/NixOS/nixpkgs/issues/223390
11 # This test is written as a fixed-output derivation, because we need to access
12 # accesses the internet to download the upstream stack release.
14 { cacert, curl, lib, stack, stdenv }:
17 # Find the hpack derivation that is a dependency of stack. Throw exception
18 # if hpack cannot be found.
21 (v: v.pname or "" == "hpack")
22 (throw "could not find stack's hpack dependency")
23 stack.passthru.getCabalDeps.executableHaskellDepends;
25 # This is a statically linked version of stack, so it should be usable within
26 # the Nixpkgs builder (at least on x86_64-linux).
28 "https://github.com/commercialhaskell/stack/releases/download/v${stack.version}/stack-${stack.version}-linux-x86_64.tar.gz";
30 # This test code has been explicitly pulled out of the derivation below so
31 # that it can be hashed and added to the `name` of the derivation. This is
32 # so that this test derivation won't be cached if the body of the test is
35 # WARNING: When modifying this script, make sure you don't introduce any
36 # paths to the Nix store within it. We only want this derivation to be re-run
37 # when the stack version (or the version of its hpack dependency) changes in
51 # Fetch the statically-linked upstream Stack binary.
52 echo "Trying to download a statically linked stack binary from ${stackDownloadUrl} to ./stack.tar.gz ..."
53 "''${curl[@]}" "${stackDownloadUrl}" > ./stack.tar.gz
56 upstream_stack_version_output="$(./stack-${stack.version}-linux-x86_64/stack --version)"
57 echo "upstream \`stack --version\` output: $upstream_stack_version_output"
59 nixpkgs_stack_version_output="$(stack --version)"
60 echo "nixpkgs \`stack --version\` output: $nixpkgs_stack_version_output"
62 # Confirm that the upstream stack version is the same as the stack version
63 # in Nixpkgs. This check isn't strictly necessary, but it is a good sanity
66 if [[ "$upstream_stack_version_output" =~ "Version "([0-9]+((\.[0-9]+)+)) ]]; then
67 upstream_stack_version="''${BASH_REMATCH[1]}"
69 echo "parsed upstream stack version: $upstream_stack_version"
70 echo "stack version from nixpkgs: ${stack.version}"
72 if [[ "${stack.version}" != "$upstream_stack_version" ]]; then
73 echo "ERROR: stack version in Nixpkgs (${stack.version}) does not match the upstream version for some reason: $upstream_stack_version"
77 echo "ERROR: Upstream stack version cannot be found in --version output: $upstream_stack_version"
81 # Confirm that the hpack version used in the upstream stack release is the
82 # same as the hpack version used by the Nixpkgs stack binary.
84 if [[ "$upstream_stack_version_output" =~ hpack-([0-9]+((\.[0-9]+)+)) ]]; then
85 upstream_hpack_version="''${BASH_REMATCH[1]}"
87 echo "parsed upstream stack's hpack version: $upstream_hpack_version"
88 echo "Nixpkgs stack's hpack version: ${hpack.version}"
90 if [[ "${hpack.version}" != "$upstream_hpack_version" ]]; then
91 echo "ERROR: stack's hpack version in Nixpkgs (${hpack.version}) does not match the upstream stack's hpack version: $upstream_hpack_version"
92 echo "The stack derivation in Nixpkgs needs to be fixed up so that it depends on hpack-$upstream_hpack_version, instead of ${hpack.name}"
96 echo "ERROR: Upstream stack's hpack version cannot be found in --version output: $upstream_hpack_version"
100 # Output a string with a known hash.
101 echo "success" > $out
104 testScriptHash = builtins.hashString "sha256" testScript;
107 stdenv.mkDerivation {
109 # This name is very important.
111 # The idea here is that want this derivation to be re-run everytime the
112 # version of stack (or the version of its hpack dependency) changes in
113 # Nixpkgs. We also want to re-run this derivation whenever the test script
116 # Nix/Hydra will re-run derivations if their name changes (even if they are a
117 # FOD and they have the same hash).
119 # The name of this derivation contains the stack version string, the hpack
120 # version string, and a hash of the test script. So Nix will know to
121 # re-run this version when (and only when) one of those values change.
122 name = "upstream-stack-hpack-version-test-${stack.name}-${hpack.name}-${testScriptHash}";
124 # This is the sha256 hash for the string "success", which is output upon this
126 outputHash = "sha256-gbK9TqmMjbZlVPvI12N6GmmhMPMx/rcyt1yqtMSGj9U=";
127 outputHashMode = "flat";
128 outputHashAlgo = "sha256";
130 nativeBuildInputs = [ curl stack ];
132 impureEnvVars = lib.fetchers.proxyImpureEnvVars;
135 # Make sure curl can access HTTPS sites, like GitHub.
137 # Note that we absolutely don't want the Nix store path of the cacert
138 # derivation in the testScript, because we don't want to rebuild this
139 # derivation when only the cacert derivation changes.
140 export SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt"
144 description = "Test that the stack in Nixpkgs uses the same version of Hpack as the upstream stack release";
145 maintainers = with maintainers; [ cdepillabout ];
147 # This derivation internally runs a statically-linked version of stack from
148 # upstream. This statically-linked version of stack is only available for
149 # x86_64-linux, so this test can only be run on x86_64-linux.
150 platforms = [ "x86_64-linux" ];