Search code examples
nixnim-langnixpkgs

Flake fails on update, nimPackages is missing, where has it gone?


A while back, I had a flake.nix which worked:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils, }:
    flake-utils.lib.eachDefaultSystem (system:
      let pkgs = import nixpkgs { inherit system; };
      in {
        packages = rec {
          hello = pkgs.nim2Packages.buildNimPackage {
            pname = "hello";
            version = "0.1.0";
            src = ./hello;
          };

          default = hello;
        };
      });

}

After running nix flake update it stopped working with this error message:

error: attribute 'nimPackages' missing

       at /nix/store/rkp543s3nhhichwg03kffd515411mikm-source/test/samples/greeter/flake.nix:12:19:

           11|         packages = rec {
           12|           hello = pkgs.nimPackages.buildNimPackage {
             |                   ^
           13|             pname = "hello";
       Did you mean elmPackages?

How can I fix it?


Solution

  • I did a git bisect and tracked it down to this nixpkgs PR

    Two changes, the first is just a rename/reorg: pkgs.nim2Packages.buildNimPackage -> pkgs.buildNimPackage

    The other required that I generate a lockfile:

    ❯ nix-shell -p nim_lk
    $ nim_lk ./hello > ./hello/lock.json
    $ exit
    ❯ git add ./hello/lock.json
    

    Then I needed to reference the lockfile in the call to buildNimPackage. Here's the flake.nix after making the changes:

    {
      inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
        flake-utils.url = "github:numtide/flake-utils";
      };
    
      outputs = { self, nixpkgs, flake-utils, }:
        flake-utils.lib.eachDefaultSystem (system:
          let pkgs = import nixpkgs { inherit system; };
          in {
            packages = rec {
              hello = pkgs.buildNimPackage {
                pname = "hello";
                version = "0.1.0";
                src = ./hello;
                lockFile = ./hello/lock.json;
              };
              default = hello;
            };
          });
    }