How to access 'broken' attribute in configuration.nix

At the end of the environment.systemPackages I added the follolwing:

   ] ++ (builtins.filter (x: ! builtins.head (lib.options.getValues x.meta.broken)) 
           (builtins.filter stdenv.lib.isDerivation
              (builtins.attrValues pkgs.kdeApplications)));

as when I did not have the attempt at the ‘broken’ code the nixos-rebuild failed due to a broken kde package. So that was my attempt at filtering only those not broken as per Nix packages manual section 2.1. When I try to build I get the following error:

building Nix...
building the system configuration...
error: attribute 'broken' missing, at /etc/nixos/settings/packages.nix:91:69
(use '--show-trace' to show detailed location information)

What am I doing wrong ? I have seen the above code in other example configuration files and it would have been ok except for the broken package I am trying to filter out.

Not sure how lib.options.getValues would help. That function expects a list and returns a new list where every list element x is replaced by x.value:

The issue is that not every derivation has meta.broken attribute and when you try to access it, it fails. You can fix it by testing if the field is present first:

(builtins.filter (x: !(x.meta ? broken && x.meta.broken)) …)

or adding a fallback value in case it is not present:

(builtins.filter (x: !(x.meta.broken or false)) …)

Also note that some derivations might not even contain the meta attribute – those created by stdenv.mkDerivation should but if some of the derivations were created in a different way, you will need to check for the presence of meta too (edit: not actually necessary, the accessor with or will handle that):

(builtins.filter (x: !((x.meta or {}).broken or false)) …)
1 Like

Thanks for your help. Now it is filtering out the one KDE application that was stopping things from working. All good now.

How do I mark it as solved ?

The x.meta.broken or false approach works without this, the or operator will trigger if any component of the attrpath is missing.

1 Like