Unverified Commit 1fa7acce authored by Wolfgang Walther's avatar Wolfgang Walther
Browse files

gnucap: fix overriding with overrideAttrs

Any attribute concatenation onto the result of mkDerivation will break
overrideability.

Before this PR, the following would fail to evaluate:

```
(gnucap.overrideAttrs { pname = "my-gnucap"; }).withPlugins (p: [
p.verilog ])'
```

The error is:

```
error: attribute 'withPlugins' missing
```

With this PR, it works as expected.
parent 903af7b0
Loading
Loading
Loading
Loading
+54 −56
Original line number Diff line number Diff line
{
  callPackage,
  fetchFromSavannah,
  gnucap,
  gnucap-full,
  installShellFiles,
  lib,
  readline,
@@ -12,30 +10,13 @@
  writeScript,
}:

let
  version = "20240220";
  meta = with lib; {
    description = "Gnu Circuit Analysis Package";
    longDescription = ''
      Gnucap is a modern general purpose circuit simulator with several advantages over Spice derivatives.
      It performs nonlinear dc and transient analyses, fourier analysis, and ac analysis.
    '';
    homepage = "http://www.gnucap.org/";
    changelog = "https://git.savannah.gnu.org/gitweb/?p=gnucap.git;a=blob;f=NEWS";
    license = licenses.gpl3Only;
    platforms = platforms.all;
    broken = stdenv.hostPlatform.isDarwin; # Relies on LD_LIBRARY_PATH
    maintainers = [ maintainers.raboof ];
    mainProgram = "gnucap";
  };
in
stdenv.mkDerivation {
stdenv.mkDerivation (finalAttrs: {
  pname = "gnucap";
  inherit version;
  version = "20240220";

  src = fetchFromSavannah {
    repo = "gnucap";
    rev = version;
    rev = finalAttrs.version;
    hash = "sha256-aZMiNKwI6eQZAxlF/+GoJhKczohgGwZ0/Wgpv3+AhYY=";
  };

@@ -53,20 +34,21 @@ stdenv.mkDerivation {
    installManPage man/*
  '';

  passthru.tests = {
  passthru = {
    tests = {
      verilog = runCommand "gnucap-verilog-test" { } ''
      echo "attach mgsim" | ${gnucap-full}/bin/gnucap -a msgsim > $out
        echo "attach mgsim" | ${
          finalAttrs.finalPackage.withPlugins (p: [ p.verilog ])
        }/bin/gnucap -a msgsim > $out
        cat $out | grep "verilog: already installed"
      '';
    };

  inherit meta;
}
// {
    plugins = callPackage ./plugins.nix { };
    withPlugins =
      p:
      let
        gnucap = finalAttrs.finalPackage;
        selectedPlugins = p gnucap.plugins;
        wrapper = writeScript "gnucap" ''
          export GNUCAP_PLUGPATH=${gnucap}/lib/gnucap
@@ -77,8 +59,8 @@ stdenv.mkDerivation {
        '';
      in
      stdenv.mkDerivation {
      pname = "gnucap-with-plugins";
      inherit version;
        pname = "${finalAttrs.pname}-with-plugins";
        inherit (finalAttrs) version;

        propagatedBuildInputs = selectedPlugins;

@@ -89,6 +71,22 @@ stdenv.mkDerivation {
          cp ${wrapper} $out/bin/gnucap
        '';

      inherit meta;
        inherit (finalAttrs) meta;
      };
  };

  meta = with lib; {
    description = "Gnu Circuit Analysis Package";
    longDescription = ''
      Gnucap is a modern general purpose circuit simulator with several advantages over Spice derivatives.
      It performs nonlinear dc and transient analyses, fourier analysis, and ac analysis.
    '';
    homepage = "http://www.gnucap.org/";
    changelog = "https://git.savannah.gnu.org/gitweb/?p=gnucap.git;a=blob;f=NEWS";
    license = licenses.gpl3Only;
    platforms = platforms.all;
    broken = stdenv.hostPlatform.isDarwin; # Relies on LD_LIBRARY_PATH
    maintainers = [ maintainers.raboof ];
    mainProgram = "gnucap";
  };
}
})