Skip to content

nix packaging #3

Description

@teto

To use wordbase as a dependency of my program and as a nix fan, I am trying to pakcage this for nix (possibily upstreamed as hinted at #1, otherwise just in a fork).

On the suggestion of my lux friends, I went with https://github.com/ipetkov/crane which is more granular than other rust nix packagers.

I create this ticket mostly to track down issues I meet:

First one is absence of a workspace.version in Cargo.toml which triggers this:

commonCargoSourcesevaluation warning: crane will use a placeholder value since `name` cannot be found in /nix/store/vvmg0szsqa0nyp2x51x7qb97vfjr47in-Cargo.toml
                    to silence this warning consider one of the following:
                    - setting `pname = "...";` in the derivation arguments explicitly
                    - setting `package.name = "..."` or `package.metadata.crane.name` = "..." or `workspace.metadata.crane.name` = "..." in the root Cargo.toml
                    - explicitly looking up the values from a different Cargo.toml via
                      `craneLib.crateNameFromCargoToml { cargoToml = ./path/to/Cargo.toml; }`

                    To find the source of this warning, rerun nix with:
                    `NIX_ABORT_ON_WARN=1 nix --option pure-eval false --show-trace ...`

Lindera needs some external data. To start with I apply this patch:

diff --git i/crates/wordbase/Cargo.toml w/crates/wordbase/Cargo.toml
index b964a20..d555475 100644
--- i/crates/wordbase/Cargo.toml
+++ w/crates/wordbase/Cargo.toml
@@ -39,7 +39,7 @@ foldhash             = { workspace = true }
 futures              = { workspace = true }
 indexmap             = { workspace = true, features = ["serde"] }
 itertools            = { workspace = true }
-lindera              = { workspace = true, features = ["unidic", "compress"] }
+lindera              = { workspace = true, features = ["compress"] }
 maud                 = { workspace = true }
 paste                = { workspace = true }
 pin-project          = { workspace = true }

to avoid

       >   cargo:rerun-if-changed=build.rs
       >   cargo:rerun-if-changed=Cargo.toml
       >   cargo::rustc-env=LINDERA_WORKDIR=/build/source/target/release/build/lindera-unidic-fbad8ed6b976bd63/out
       >
       >   --- stderr
       >   Error: "Failed to download a valid file from all sources"

https://github.com/NixOS/nixpkgs/blob/e32cfd2e9abfe73cb3ed49c22bd1e29677ce4f9a/pkgs/applications/misc/pagefind/default.nix#L102 may show how to patch lindera build.

My current error is this:

     >     = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query` (in Nightly builds, run with -Z macro-backtrace for more info)
       >
       > error: set `DATABASE_URL` to use query macros online, or run `cargo sqlx prepare` to update the query cache
       >    --> crates/wordbase/src/profile.rs:147:9
       >     |
       > 147 | /         sqlx::query!(
       > 148 | |             "UPDATE profile SET font_family = $1 WHERE id = $2",
       > 149 | |             font_family,
       > 150 | |             profile_id.0
       > 151 | |         )
       >     | |_________^
       >     |
       >     = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query` (in Nightly builds, run with -Z macro-backtrace for more info)
       >
       > error: set `DATABASE_URL` to use query macros online, or run `cargo sqlx prepare` to update the query cache
       >    --> crates/wordbase/src/profile.rs:166:23
       >     |
       > 166 |       let mut records = sqlx::query!(
       >     |  _______________________^
       > 167 | |         "SELECT
       > 168 | |             profile.id,
       > 169 | |             profile.name,
       > ...   |
       > 177 | |         ORDER BY profile.id"
       > 178 | |     )
       >     | |_____^
       >     |
       >     = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query` (in Nightly builds, run with -Z macro-backtrace for more info)
       >
       > error: set `DATABASE_URL` to use query macros online, or run `cargo sqlx prepare` to update the query cache
       >   --> crates/wordbase/src/texthook.rs:38:19
       >    |
       > 38 |         let url = query!("SELECT texthooker_url FROM config")
       >    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >    |
       >    = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `query` (in Nightly builds, run with -Z macro-backtrace for more info)
       >
       > error: set `DATABASE_URL` to use query macros online, or run `cargo sqlx prepare` to update the query cache
       >   --> crates/wordbase/src/texthook.rs:75:9
       >    |
       > 75 |         query!("UPDATE config SET texthooker_url = $1", url)
       >    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >    |
       >    = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `query` (in Nightly builds, run with -Z macro-backtrace for more info)
       >
       > warning: unused import: `RecordKind`
       >   --> crates/wordbase/src/import/insert.rs:32:65
       >    |
       > 32 |     DictionaryId, FrequencyValue, NormString, Record, RecordId, RecordKind, RecordType, Term,
       >    |                                                                 ^^^^^^^^^^
       >    |
       >    = note: `#[warn(unused_imports)]` on by default
       >
       > warning: `wordbase` (lib) generated 1 warning
       > error: could not compile `wordbase` (lib) due to 31 previous errors; 1 warning emitted
       > warning: build failed, waiting for other jobs to finish...
       For full logs, run:
         nix log /nix/store/8dvzx0yg6kq1s554sbpxsymv3jkhwh9m-wordbase-cli-0.0.1.drv

Not sure what the build is trying to do here, are these macros/SQL commands executed at buildtime ? any idea how to make it work in a sandbox (pass on an already generated data etc) ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions