Attempting to get requireFIle working to package proprietary software

I’m trying to make a derivation for the (proprietary) TotalPhase Data Center software, available here after log in from a browser. By my understanding that means I’ll need to use nix-store --add-fixed, nix-prefetch-url, or nix store add to add the .zip to the Nix store and then in the derivation use requireFile to get the .zip from the Nix store.

Unfortunately that does not work:

Shell session adding the file & trying nix build:

~/tmp/totalphase-data-center took 2s
❯ nix-store --add-fixed sha256 data-center-linux-x86_64-v7.10.000.zip
/nix/store/g6cd26y2fa1pp17chflrp2bnw6pqi282-data-center-linux-x86_64-v7.10.000.zip

~/tmp/totalphase-data-center
❯ nix hash path /nix/store/g6cd26y2fa1pp17chflrp2bnw6pqi282-data-center-linux-x86_64-v7.10.000.zip
sha256-gGCHbr3nDzN6Qow8AgMa5WGnzBRkbVs4rcO8K6m7sNk=

~/tmp/totalphase-data-center
❯ nix build
error: builder for '/nix/store/0c44n2l064xbyigzyln1rziry2m6n2dw-data-center-linux-x86_64-v7.10.000.zip.drv' failed with exit code 1;
       last 10 log lines:
       > ***
       > Unfortunately, we cannot download file data-center-linux-x86_64-v7.10.000.zip automatically.
       > Please go to https://www.totalphase.com/products/data-center/ to download it yourself, and add it to the Nix store
       > using either
       >   nix-store --add-fixed sha256 data-center-linux-x86_64-v7.10.000.zip
       > or
       >   nix-prefetch-url --type sha256 file:///path/to/data-center-linux-x86_64-v7.10.000.zip
       >
       > ***
       >
       For full logs, run 'nix log /nix/store/0c44n2l064xbyigzyln1rziry2m6n2dw-data-center-linux-x86_64-v7.10.000.zip.drv'.
error: 1 dependencies of derivation '/nix/store/v83h4882nb34rsag4np6m6h3vcy0rsv2-totalphase-data-center-7.10.000.drv' failed to build

My current flake.nix with the derivation:

{
  description = "TotalPhase Data Center software for protocol analyzer hardware";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs { inherit system; };
      version = "7.10.000";
    in
    {
      packages.${system}.default = with pkgs; stdenv.mkDerivation {
        name = "totalphase-data-center-${version}";

        # Get a local file. This will error if the hash is wrong.
        #  Run `nix store add-file <path/to/data-center-linux-x86_64-v${version}.zip`, get the output path. Use that output in
        # `nix hash path <output path of nix store add-file>`
        # Paste that into the hash line below.
        src = requireFile {
          name = "data-center-linux-x86_64-v${version}.zip";
          url = "https://www.totalphase.com/products/data-center/";
          hash = "sha256-gGCHbr3nDzN6Qow8AgMa5WGnzBRkbVs4rcO8K6m7sNk=";
        };

        nativeBuildInputs = [
          autoPatchelfHook
          unzip
        ];

        buildInputs = [
          bash
          gdk-pixbuf
          glibc
        ];

        sourceRoot = ".";

        dontBuild = true;
        dontConfigure = true;

        installPhase = ''
          runHook preInstall
          mkdir -p $out/{bin,doc,example,i18n,lib}
          install -m755 totalphase-data-center-v${version} -d $out
          runHook postInstall
        '';
      };
    };
}

How do I get requireFile to find the file in the Nix store?

Great question! I offer my advice based on limited experiences packaging software in Nix, flakes or otherwise. I hope someone else will chime in with better answers :).

Are you able to add the file to the same directory where your flake is?

I tend to make the file I need to consume a part of the flake’s directory.
Then, I’ve used buildPhase hook to copy it from ./my-file.txt to $out/my-file.txt.
In your snippet, you might be able to do the same with the installPhase hook.

I’ve just run up against this problem too so I’ve opened an issue on the nixpkgs GitHub here with a simple example.

Did you come up with a satisfactory workaround?

Can you try using nix hash file foo.txt instead of nix hash path foo.txt? I’ve been using it in the past like this and can’t remember having issues. And I just checked and the resulting hashes are definitely different.

Also, not sure if that is related in any capacity, but I am also using nix store add-file foo.txt instead of the legacy binary.

1 Like

That works! I might have a go at improving the relevant docs.

Thank you very much!