Need help building a package

DISCLAIMER: I stopped reading the nix pills halfway through chapter 12 due to a hangup, so my knowledge about how nix works is likely incomplete.

I want to package lokke for personal use and don’t understand what I am doing wrong. These are my build files.

The first problem I run into is that git is unable to resolve The command I am executing is nix-build lokke.nix

these derivations will be built:
building '/nix/store/yw9r05x3vs3bqh9bgwgknaaym6is12wx-lokke.drv'...
Cloning into '/nix/store/4h6b2fwapbqarfljnlv70ddkyhjnxyn6-lokke'...
fatal: unable to access '': Could not resolve host:
builder for '/nix/store/yw9r05x3vs3bqh9bgwgknaaym6is12wx-lokke.drv' failed with exit code 128
error: build of '/nix/store/yw9r05x3vs3bqh9bgwgknaaym6is12wx-lokke.drv' failed
Exception: nix-build exited with 100
[tty 15], line 1: nix-build lokke.nix 

Wat do?

1 Like

It’s probably easier to use the stdenv.mkDerivation rather than builtins.derivation.

Then you can easily use the pkgs.fetchFromGitHub fetcher for src and in general you get a nicer and usually easier to grasp abstraction and you do not need to implement all of it on your own.


Thanks @NobbZ ! Your advice has resulted in strong progress. :slight_smile:

These are the build files now. Can’t believe how much shorter it is.

I have several questions.

  1. fetchGit removes the .git directory, which requires the build script to git init .. This is necessary b/c the setup script needs it in order to run. Can I instead somehow instruct fetchGit to leave the repo intact?
  2. nix-build lokke.nix can’t seem to find, so I am just using nix-shell lokke.nix for now. In a previous exercise I didn’t have to specify all of the build scripts in order for them to be copied into the store. Wat do?
  3. nix-shell exits upon any failure. How do I tell it not to do this?
  4. This is the important one. ./configure gives this error:
./configure: line 5590: syntax error near unexpected token `PCRE2,'
./configure: line 5590: `PKG_CHECK_MODULES(PCRE2, libpcre2-8 libpcre2-32)'
Exception: nix-shell exited with 2
[tty 10], line 1: nix-shell lokke.nix 
1 Like

Yes, keepGotGit or something like that. Though don’t do it. Thogh that makes the expression non-reproducible, as .git changes with each potential clone.

If the build just invokes git and parses its output, it is common to use a fake git script that outputs predetermined output.

Don’t use builder, but instead use mkDerivations default phases. configurePhase, buildPhase, ìnstallPhase`, etc.

The shell should stay intact. Therefore not sure what you are observing.

How do you invoke the shell? Though are you sure you build the configure script correctly?

As said, working with git mechanisms does not go well within nix. The fact that installation procedures want do all kind of weird side effects is just sad (albeit understandable in a world without more principled alternatives), and the quickest way to go is patching it out. Search for patchPhase in the nixpkgs manual (sorry, no keyboard right now, otherwise I’d just give you the link). In your case that should be fairly straightforward, since it’s just some path filtering and renaming. The correct, long-term-oriented, good-internet-citizen way to do it is of course talking to maintainers and develop a pure solution upstream. I feel your pain, recently I’ve been fighting a bunch of CMake builds that try to fetch their own dependencies with git

The reason is that specifying ./ will copy that file to /nix/store and your relative path to ./ will point nowhere from there. I think it would be easiest to specify your custom build steps in the preConfigurePhase field for stdenv.mkDerivation, again please check the manual. You’re trying to do the same, technically, it’s just much more tedious since we already have all the convenience layers from nixpkgs.

I keep repeating it to newcomers, but the Nix Pills are absolutely unsuitable for beginners, as they are too low-level to do anything useful with that knowledge. The manuals are much better suited, but still need a lot of work. @daf it’s absolutely not your fault to be confused. You’ve invested significant amount of effort, and asked a highly informed question. Bad luck you picked a rocky path because it was on the front page.

Funnily all the information is somehow out there, it just takes tons of time to scrape it together and synthesize something coherent in your head. For example look at this person literally reading the manuals back to back trying to make sense of everything.

It’s an entertaining an informative read, but in a sense perpetuates the problem by being a more useful resource than the manual. So if anyone reading this wants to contribute to improving the manual, please drop me a message or ping me in your pull request. I’ll be glad to help with answering questions or reviewing. I didn’t manage to start out on my own in over a year, as there are only few itches to scratch left for myself, time is limited, and, you know, priorities…

1 Like

Thanks, @NobbZ & @fricklerhandwerk. Based on your advice regarding the first question I have decided to go with the current approach. I could write a replacement script for git ls-files … probably, but tbh ls-files seems extremely harmless so… :man_shrugging:

The reason is that specifying ./ will copy that file to /nix/store and your relative path to ./ will point nowhere from there.

Thanks, @fricklerhandwerk. This explanation led me to assign ./setup to a key in the map passed to stdenv.mkDerivation.

How do you invoke the shell? Though are you sure you build the configure script correctly?

nix-shell lokke.nix. However, I have recently renamed the file to default.nix, so now I invoke the shell w/ simply nix-shell. I am following the build instructions on the README as closely as possible.

These are the build files now.

I discovered that pkg-config was needed for the PCRE2 config issue, but now I am seeing a similar issue with the configuration script.This is being invoked from within nix-shell by calling configurePhase, which is part of the stdenv.mkDerivation script.

./configure: line 14058: syntax error near unexpected token `3.0'
./configure: line 14058: `GUILE_PKG(3.0 2.2)'
1 Like