Overriding squirrel-sql source not working for me

Hello,

I am trying to install squirrel-sql in NixOS. The package uses the squirrel-sql-standard.zip file, but I need feature that are in the squirrel-sql-optional.zip file (which includes everything in the -standard zip, plus more).

From all of the searching I do online, it looks like I should be able to override the “src” attribute in the existing package with the alternative download I want to use. But no matter what I’ve tried, I cannot make this work; it always seems to want to unzip the -standard archive, not the -optional archive.

To start with, I am referencing the pkg definition at: nixpkgs/pkgs/development/tools/database/squirrel-sql/default.nix at 44534bc021b85c8d78e465021e21f33b856e2540 · NixOS/nixpkgs · GitHub

In my /etc/nixos directory, I’ve created a “squirrel-sql-optional.nix” file with the following contents:

{ pkgs, ... }:

pkgs.squirrel-sql.overrideAttrs (oldAttrs: {
  name = "squirrel-sql-optional";

  src = pkgs.fetchurl {
    url = "mirror://sourceforge/project/squirrel-sql/1-stable/${pkgs.squirrel-sql.version}-plainzip/squirrelsql-${pkgs.squirrel-sql.version}-optional.zip";
    sha256 = "sha256-tweGfzuLIHxjF8jOKgXWLEbwEKXxHVc5jZn1oYhbveA=";
  };

  buildPhase = ''
    runHook preBuild
    cd squirrelsql-${pkgs.squirrel-sql.version}-optional
    chmod +x squirrel-sql.sh
    runHook postBuild
  '';
})

This changes the src URL to the -optional.zip version, and since that should unzip to a different folder name, I’ve also overridden the buildPhase appropriately.

In my configuration.nix, I’ve added:

let
  squirrel-sql-optional = import ./squirrel-sql-optional.nix { pkgs = pkgs; };
in
{
  ...
  environment.systemPackages = with pkgs; [
    squirrel-sql-optional
    ...
  ]
}

However, when I run nixos-rebuild switch --use-remote-sudo, I get an error: /nix/store/lzrs17sc8bhi87nb1y1q1bas73j6q10y-stdenv-linux/setup: line 1715: cd: squirrelsql-4.8.0-optional: No such file or directory

And from the full log, I see that it unzipped the -standard.zip version, not my overridden src -optional.zip version. (However, if I put in the wrong sha256 hash, I do get a hash mismatch error, so it does appear to be downloading my alternate zip archive even thought it’s not unzipping it.)

Looking at the original package again, I see the reference to “unzip ${src}” in the unpackPhase, so I am thinking that perhaps overriding the src in my overrideAttrs isn’t flowing back “up” the chain to the original package definition. So I’ve updated my squirrel-sql-optional.nix to override the unpackPhase as well, hoping to refer to the new “local” src variable:

...
unpackPhase = ''
  runHook preUnpack
  unzip ${src}
  runHook postUnpack
'';
...

But now when I run nixos-rebuild, I get the error:

       error: undefined variable 'src'
       at /nix/store/43q5scb1pyb0jnca8dk9vsbvkvwv7q2f-source/squirrel-sql-optional.nix:14:13:
           13|     runHook preUnpack
           14|     unzip ${src}
             |             ^
           15|     runHook postUnpack

Okay, so I can’t reference ${src} like the original package does, even though it’s defined right there in the same block? I’ll try with the name of the file I know it’s downloading:

  unpackPhase = ''
    runHook preUnpack
    unzip squirrelsql-${pkgs.squirrel-sql.version}-optional.zip
    runHook postUnpack
  '';

But now when I run the nixos-rebuild, I get the error: unzip: cannot find or open squirrelsql-4.8.0-optional.zip ...

So it’s downloading the -optional.zip file, but I don’t know where it’s putting it. It does seem happy to unzip the -standard.zip file, though, even though I’ve overridden the src so that it shouldn’t even be downloading the -standard.zip anymore.

Any hints as to how I should install squirrel-sql from the -optional.zip download instead of the -standard.zip download? I’d appreciate it!

Thanks,
Matthew

Yes, because the original expression uses rec, and yours does not.
See https://nix.dev/manual/nix/2.24/language/syntax#recursive-sets

You will have to override unpackPhase as well, because they use rec instead of the finalAttrs pattern. See https://nixos.org/manual/nixpkgs/unstable/#mkderivation-recursive-attributes for more context.

Aha, thank you!

Yes, I had tried overriding the unpackPhase, but without ${src} working, I didn’t know which path the downloaded file was at.

I added rec, so now I am using oldAttrs: rec { ... to be able to reference my own ${src} and changed my unpackPhase back to ${src}, and now it’s unzipping the right file.

Thank you again!