tweag / opam-nix

Turn opam-based OCaml projects into Nix derivations
MIT License
111 stars 33 forks source link

error: attribute 'mypackage' missing #67

Closed MarcCoquand closed 11 months ago

MarcCoquand commented 11 months ago

Describe the bug A clear and concise description of what the bug is.

I am unable to run nix build, it fails with the following:

error: attribute 'mypackage' missing

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:494:23:

          493|       pinDeps =
          494|         getPinDepends repo.passthru.pkgdefs.${name}.${latestVersions.${name}};
             |                       ^
          495|     in queryToScope {

       … while evaluating the attribute 'passthru.pkgdefs.mypackage."${(latestVersions)."${name}"}"'

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:259:38:

          258|       repo = linkFarm "opam-repo" ([ repo-description ] ++ opamFileLinks);
          259|     in repo // { passthru = { inherit sourceMap pkgdefs; }; };
             |                                      ^
          260|

       … while evaluating 'getPinDepends'

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:475:19:

          474|
          475|   getPinDepends = pkgdef:
             |                   ^
          476|     if pkgdef ? pin-depends then

       … from call site

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:494:9:

          493|       pinDeps =
          494|         getPinDepends repo.passthru.pkgdefs.${name}.${latestVersions.${name}};
             |         ^
          495|     in queryToScope {

       … while evaluating 'optionals'

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/lists.nix:271:5:

          270|     # List to return if condition is true
          271|     elems: if cond then elems else [];
             |     ^
          272|

       … from call site

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:496:27:

          495|     in queryToScope {
          496|       repos = [ repo ] ++ optionals pinDepends pinDeps ++ repos;
             |                           ^
          497|       overlays = overlays;

       … while evaluating 'joinRepos'

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:372:15:

          371|
          372|   joinRepos = repos:
             |               ^
          373|     if length repos == 0 then

       … from call site

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:455:18:

          454|     pipe query [
          455|       (opamList (joinRepos repos) resolveArgs)
             |                  ^
          456|       (opamListToQuery)

       … while evaluating the attribute 'buildCommand' of the derivation 'resolve'

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/pkgs/stdenv/generic/make-derivation.nix:302:7:

          301|     // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
          302|       name =
             |       ^
          303|         let

       … while realising the context of a path

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/strings.nix:1076:43:

         1075|   */
         1076|   fileContents = file: removeSuffix "\n" (readFile file);
             |                                           ^
         1077|

       … while evaluating anonymous lambda

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/trivial.nix:357:50:

          356|   */
          357|   warnIf = cond: msg: if cond then warn msg else x: x;
             |                                                  ^
          358|

       … from call site

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/strings.nix:654:5:

          653|     # to strings and comparing. This was surprising and confusing.
          654|     warnIf
             |     ^
          655|       (isPath suffix)

       … while evaluating 'removeSuffix'

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/strings.nix:651:5:

          650|     # Input string
          651|     str:
             |     ^
          652|     # Before 23.05, paths would be copied to the store before converting them

       … from call site

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/strings.nix:1076:24:

         1075|   */
         1076|   fileContents = file: removeSuffix "\n" (readFile file);
             |                        ^
         1077|

       … while evaluating 'fileContents'

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/strings.nix:1076:18:

         1075|   */
         1076|   fileContents = file: removeSuffix "\n" (readFile file);
             |                  ^
         1077|

       … from call site

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:201:18:

          200|         '';
          201|       solution = fileContents resolve-drv;
             |                  ^
          202|

       … while evaluating 'splitString'

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/strings.nix:598:22:

          597|   */
          598|   splitString = sep: s:
             |                      ^
          599|     let

       … from call site

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:203:18:

          202|
          203|       lines = s: splitString "\n" s;
             |                  ^
          204|

       … while evaluating 'lines'

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:203:15:

          202|
          203|       lines = s: splitString "\n" s;
             |               ^
          204|

       … from call site

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:205:8:

          204|
          205|     in lines solution;
             |        ^
          206|

       … while evaluating 'opamList'

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:159:33:

          158|
          159|   opamList = repo: resolveArgs: packages:
             |                                 ^
          160|     let

       … from call site

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/trivial.nix:62:30:

           61|   pipe = val: functions:
           62|     let reverseApply = x: f: f x;
             |                              ^
           63|     in builtins.foldl' reverseApply val functions;

       … while evaluating 'reverseApply'

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/trivial.nix:62:27:

           61|   pipe = val: functions:
           62|     let reverseApply = x: f: f x;
             |                           ^
           63|     in builtins.foldl' reverseApply val functions;

       … from call site

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/trivial.nix:63:8:

           62|     let reverseApply = x: f: f x;
           63|     in builtins.foldl' reverseApply val functions;
             |        ^
           64|

       … while evaluating 'pipe'

       at /nix/store/q3l9x3ncgi0hppw0i65ki9jrxj8kmgac-source/lib/trivial.nix:61:15:

           60|   */
           61|   pipe = val: functions:
             |               ^
           62|     let reverseApply = x: f: f x;

       … from call site

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:454:5:

          453|     query:
          454|     pipe query [
             |     ^
          455|       (opamList (joinRepos repos) resolveArgs)

       … while evaluating 'queryToScope'

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:453:5:

          452|     , overlays ? __overlays, resolveArgs ? { } }:
          453|     query:
             |     ^
          454|     pipe query [

       … from call site

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:495:8:

          494|         getPinDepends repo.passthru.pkgdefs.${name}.${latestVersions.${name}};
          495|     in queryToScope {
             |        ^
          496|       repos = [ repo ] ++ optionals pinDepends pinDeps ++ repos;

       … while evaluating 'buildOpamProject'

       at /nix/store/xf0glwam0jk3yym888y1c7ny4f92j8lk-source/src/opam.nix:488:20:

          487|     , recursive ? false }@args:
          488|     name: project: query:
             |                    ^
          489|     let

       … from call site

       at /nix/store/8agzjbynw7bb9n030radf916a6xkyhxv-source/flake.nix:15:11:

           14|         scope =
           15|           on.buildOpamProject { } package ./. { ocaml-base-compiler = "*"; };
             |           ^
           16|         overlay = final: prev:

       … while evaluating the attribute 'legacyPackages'

       at /nix/store/8agzjbynw7bb9n030radf916a6xkyhxv-source/flake.nix:21:9:

           20|       in {
           21|         legacyPackages = scope.overrideScope' overlay;
             |         ^
           22|

       … while evaluating the attribute 'legacyPackages.x86_64-linux.mypackage'

       at /nix/store/pgid9c9xfcrbqx2giry0an0bi0df7s5c-source/lib.nix:40:24:

           39|                 ${key} = (attrs.${key} or { })
           40|                   // { ${system} = ret.${key}; };
             |                        ^
           41|               }

To Reproduce Steps to reproduce the behavior.

nix flake init -t github:tweag/opam-nix

Change package name and then you get this error

Environment

Additional context

Full config

{
  inputs = {
    opam-nix.url = "github:tweag/opam-nix";
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.follows = "opam-nix/nixpkgs";
  };
  outputs = { self, flake-utils, opam-nix, nixpkgs }@inputs:
    # Don't forget to put the package name instead of `throw':
    let package = "mypackage";
    in flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        on = opam-nix.lib.${system};
        scope =
          on.buildOpamProject { } package ./. { ocaml-base-compiler = "*"; };
        overlay = final: prev:
          {
            # Your overrides go here
          };
      in {
        legacyPackages = scope.overrideScope' overlay;

        packages.default = self.legacyPackages.${system}.${package};
      });
}

My opam file

# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Marc Coquand"]
authors: ["Marc Coquand"]
license: "AGPL-3.0-only"
tags: ["topics" "to describe" "your" "project"]
homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
  "ocaml"
  "dune" {>= "3.11"}
  "dream"
  "ppx_yojson_conv"
  "crunch"
  "cohttp"
  "lwt_ppx"
  "cohttp-lwt-unix"
  "containers"
  "calendar"
  "ptime"
  "mirage-crypto-rng"
  "mirage-crypto-rng-lwt"
  "ppx_inline_test"
  "ppx_deriving"
  "decoders-yojson"
  "odoc" {with-doc}
]
build: [
  ["dune" "subst"] {dev}
  [
    "dune"
    "build"
    "-p"
    name
    "-j"
    jobs
    "@install"
    "@runtest" {with-test}
    "@doc" {with-doc}
  ]
]
dev-repo: "git+https://github.com/username/reponame.git"
MarcCoquand commented 11 months ago

So I figured out what it was.... I had the .opam file in gitignore as I'm using dune to generate it :man_facepalming:. It seems nix ignores it too then.

balsoft commented 11 months ago

FYI you can keep that setup and just use buildDuneProject instead of buildOpamProject