Cant load new version of package found in github

I am sure this information is somewhere but I guess I just don’t know the terminology well enough to find it, so my apologies for asking again. My current configuration is NixOS v24.1 w/ Home-Manager. I want to use version 7+ of PMD which is currently only at version 6.5 in the nixos repository. I have tried many ways to make this happen but I either get an error building from the source code, or version 6.5 still ends up getting installed. This is the latest attempt. I don’t get an error but it isn’t installed either. After running nixos-rebuild switch with this configuration, there is no problem with the rebuild. Trying to run pmd from the command line states it is not in the current path so run nix-shell -p pmd.So, if I run that command, I get PMD but version 6.5. This is giving me nixos hair…

I have created pmd.nix in /etc/nixos:


{ pkgs, … }:
pkgs.stdenv.mkDerivation {
pname = “pmd”;
version = “latest”;
src = pkgs.fetchzip {
url = “https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.10.0/pmd-dist-7.10.0-bin.zip”; # Replace with actual version and URL
sha256 = “”;
};
installPhase = ‘’
mkdir -p $out/bin
cp -r * $out/
‘’;
meta = {
description = “PMD static code analyzer”;
homepage = “https://pmd.github.io/”;
license = pkgs.lib.licenses.bsd2;
platforms = pkgs.lib.platforms.all;
};
}


I am including it in configuration.nix as a system-wide package, though I prefer it user based under home-manager:

******************** /etc/nixos/configuration.nix *****************

environment.systemPackages = with pkgs; [
(import ./pmd.nix { inherit pkgs; })
maven
vim
pkgs.docker
pkgs.docker-compose
nodePackages.node2nix
];


I have also tried doing it this way:

environment.systemPackages = with pkgs; [
(pkgs.pmd.overrideAttrs (oldAttrs: {
buildInputs = oldAttrs.buildInputs ++ [ pkgs.maven ];
buildPhase = ‘’
mvn package
‘’;
installPhase = ‘’
mkdir -p $out/bin
cp target/*.jar $out/bin/
‘’;
src = pkgs.fetchFromGitHub {
owner = “pmd”;
repo = “pmd”;
rev = “700a9b668840c11eb4be09843372e704f6b3f7dc”;
sha256 = “”;
};
}))
maven
vim
pkgs.docker
pkgs.docker-compose
nodePackages.node2nix
];

And this way:

environment.systemPackages = with pkgs; [
(pkgs.pmd.overrideAttrs (oldAttrs: {
src = pkgs.fetchFromGitHub {
owner = “pmd”;
repo = “pmd”;
rev = “700a9b668840c11eb4be09843372e704f6b3f7dc”;
sha256 = “”;
};
}))
];

This version does not exist, there 24.05 and 24.11 are the closest matches.

24.11 and unstable both seem to have version 6.55.

Also, I can not reproduce:

$ ./result/bin/pmd --version
  ████                            ████
  ██                                ██
  ██  █████ █ ███    ███  ███████   ██
 ███  ██  ███ ████  ████  ██    ██  ███
 ███  ███████ ██ ████ ██  ██    ██  ███
  ██  ██      ██  ██  ██  ███████   ██
  ██                                ██
  ████                            ████
PMD 7.10.0 (db70a20d4294fda0786145c126ca977b1a882a3c, 2025-01-31T09:22:09Z)
Java version: 21.0.6, vendor: Ubuntu, runtime: /usr/lib/jvm/java-21-openjdk-amd64

After building your snippet.

Are you sure you have not mentioned the original pkgs.pmd anywhere else in your configuration? Maybe hidden behind other options?


PS: Please used markdown indended or fenced codeblocks for easier to copy and easier to read code. Fenced code can even provide code highlighting (in theory, it seems the relevant plugins and highlighters are not aactive in this forum):

```nix
{ foo, ...}: {
  bar = foo;
}
```

will produce:

{ foo, ... }: {
  bar = foo;
}

Sorry, yes, it is NixOS 24.11 not 24.1.
So, I have removed the previous code and just added the package to configuration.nix. Pmd is only present in the file in this location. I have run the following commands to clean things out.

nix-store --gc

I removed all references to pmd from configuration.nix and ran nixos-rebuild switch.
I confirmed that pmd is no longer accessible by running it from the command line.
I added pmd back to configuration.nix. It now looks like this:

environment.systemPackages = with pkgs; [
    maven
    vim
    pkgs.docker
    pkgs.docker-compose
    nodePackages.node2nix
    pkgs.pmd
  ];

ran nixos-rebuild switch and then ran pmd --version from the command line which returned

PMD 6.5.5.0

Looking at search.nixos.org for PMD only shows 6.5.5. So how are you getting 7+ for a version?

Can you run which pmd and give the result?

and type -a pmd for good measure as well.

Both return the same path:

/run/current-system/sw/bin/pmd

It should return 6.55.0 not 6.5.5.0, but anyway, that’s tangential to your actual question.

You’ll have to override the src:

This is a good start, unfortunately pmd in nixpkgs isn’t built from source, so this won’t work as-is.
Instead of fetchFromGitHub, try using fetchurl as the pmd expression in nixpkgs does:

Actually it seems like the nixpkgs-update bot would normally update this package automatically, but the URL format changed:

https://nixpkgs-update-logs.nix-community.org/pmd/2025-01-31.log

There’s now -dist in the URL:

https://github.com/pmd/pmd/releases/tag/pmd_releases%2F7.10.0

Once that’s updated then automatic updates should work again in the future.
You’re welcome to send a PR for that.

Also did this as a solution. Same result. pmd version 6.5.5

Where did you try that? Share the code.
None of the examples above show an override with fetchurl on the prebuilt zip.

(And again, you should not be getting 6.5.5 on the current version, the version is 6.55.)

It just refuses to pull in version 7.10.

This:

Results in this:

install: cannot stat 'bin/run.sh': No such file or directory
error: builder for '/nix/store/nayjw1w4wn41fn263pz6g6118wwgg8ii-pmd-6.55.0.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/0r9knn8djs66ij2y5sjxjxpc3b84vx79-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/3wb9mgz0jiqgdx3aqld1sdrrk92wi07c-nixos-system-nixos-24.11.710315.b681065d0919.drv' failed to build

I don’t know where to get run.sh to help it.

In that case I’ve no idea, I’m not familiar with the package. If you can’t figure it out, feel free to post an update request on the nixpkgs repo and tag the maintainers.

If you pull that package down and poke a bit you’ll see it looks like they renamed run.sh to just pmd:

❯ unzip -t pmd-dist-7.10.0-bin.zip pmd-bin-7.10.0/bin/*
Archive:  pmd-dist-7.10.0-bin.zip
    testing: pmd-bin-7.10.0/bin/      OK
    testing: pmd-bin-7.10.0/bin/pmd.bat   OK
    testing: pmd-bin-7.10.0/bin/pmd   OK
No errors detected in pmd-dist-7.10.0-bin.zip for the 3 files tested.
❯ file pmd
pmd:     Bourne-Again shell script, ASCII text executable

So the installPhase of the nixpkg needs to copy this file instead of run.sh:

-    install -Dm755 bin/run.sh $out/libexec/pmd
+    install -Dm755 bin/pmd $out/libexec/pmd

But - you may run into another problem too. They changed the name of the package to pmd-dist- but the internal of the zip file is still pmd-bin-.

Added a bug report for this:

1 Like

Thanks. I just actually figured this out this morning. Too bad that NixOS doesn’t really have good information on situations like this which details how packages are installed. Basically, the PMD package is already in a standard format suitable for use in the NixOS store. Understanding what NixOS did with the files from a zip or a tar file was fundamental to understanding how to solve this problem. This is how I understand NixOS handles packages:

  • NixOS creates a store.
  • The store contains a typical Linux file structure for any application or project with a bin, a lib and a conf.
  • NixOS when it installs a package, it opens up the archive and moves the files into a directory that it manages but expects the structure to match what is expected.
  • NixOS automatically adds the path to the users environment to correspond to the bin directory for this store depending on the choosen configuration.
  • NixOS configuration.nix file provides a method to override the installation, build and unpackaging phases with script commands that can be used when the package does not conform to the expected norm.

My solution:

    (pkgs.pmd.overrideAttrs (oldAttrs: {
		installPhase = ''
			install -d $out/bin $out/conf $out/lib $out/sbom
			install -m 755 bin/* $out/bin/
			install -m 644 conf/* $out/conf/
			install -m 644 lib/* $out/lib/
			install -m 644 sbom/* $out/sbom/
	  '';
      src = fetchurl {
        url = "https://github.com/pmd/pmd/releases/download/pmd_releases/7.10.0/pmd-dist-7.10.0-bin.zip";
        hash = "sha256-zWdrGdvofob37tWUCkhL4tOrai0dVS5gWGCrEvvwXLs=";
      };
    }))

We have a disgustingly huge manual on how they are built, actually: https://nixos.org/manual/nixpkgs/unstable/

(And it’s nixpkgs, not nixos, which provides the framework for nix to then build packages.)