Allow insecure packages in flake.nix

I have been working on some updates to nix-node, which allows installation of multiple versions of nodejs, including older versions that are no longer supported:

This has been working, except that the versions of node that are no longer officially supported are marked as insecure and cannot be installed or built. For example, attempting to build version 16.18.0 returns this error:

error: Package ‘nodejs-16.18.0’ in /nix/store/vkf7qqw2pmpxfhs5axsjmv1sbwdkqzhs-source/flake.nix:305 is marked as insecure, refusing to evaluate.

In trying to update the package to allow these versions to be installed, I have been following these sources:

Unfortunately I’m a bit of a nix noob and cannot work out how to apply these changes to the existing flake.nix:

My naive attempts to slot similar code in have either resulted in syntax errors, or simply don’t work. Would anyone be able to let me know where I should set the permittedInsecurePackages list in the above code?

Just replace

nixpkgs.legacyPackages.${system}

with

(import nixpkgs {
  inherit system;
  config = {
    permittedInsecurePackages = [
      "foo"
    ];
  };
})

That is basically how legacyPackages are defined in Nixpkgs:

Though see the discussion in Using nixpkgs.legacyPackages.${system} vs import for caveats.

2 Likes

Thank you so much, that was the key that I was missing.