Hello to all the nix-learning and nix-knowning people
I started to write my first own derivation from scratch. I want to package a project I develop and hopefully include it into the official nixpkgs later on.
This is my default.nix so far:
{ pkgs ? import <nixpkgs> {}, doCheck ? true }:
let
stdenv = pkgs.stdenv;
fetchFromGitHub = pkgs.fetchFromGitHub;
in
stdenv.mkDerivation rec {
pname = "nvimpager";
version = "0.9";
src = fetchFromGitHub {
owner = "lucc";
repo = pname;
rev = "v${version}";
sha256 = "1xy5387szfw0bp8dr7d4z33wd4xva7q219rvz8gc0vvv1vsy73va";
};
buildInputs = with pkgs; [
ncurses # for tput
neovim
procps # for nvim_get_proc() which uses ps(1)
pandoc
];
makeFlags = [ "PREFIX=$(out)" ];
buildFlags = [ "nvimpager.configured" ];
preBuild = ''
substituteInPlace nvimpager \
--replace '/usr/bin/env bash' '${pkgs.bash}/bin/bash' \
--replace ':-nvim' ':-${pkgs.neovim}/bin/nvim'
'';
checkInputs = with pkgs; [ lua51Packages.busted ];
checkTarget = "test";
inherit doCheck;
meta = with stdenv.lib; {
description = "Use neovim as pager";
longDescription = ''
Use neovim as a pager to view manpages, diffs, etc with nvim's syntax
highlighting. Includes a cat mode to print highlighted files to stdout
and a ansi esc mode to highlight ansi escape sequences in neovim.
'';
homepage = "https://github.com/lucc/nvimpager";
license = licenses.bsd2;
platforms = platforms.all;
};
}
Building it with nix-build default.nix --arg doCheck false seems to work and I can use the program inside the derivation’s output. My problem lies with the check phase. When I run with doCheck true I get many test failures,especially this message: ./nvimpager: line 127: /dev/tty: No such device or address (my program is a script that redirects from /dev/tty).
The thing is if I use my derivation with nix-shell default.nix and run make test it works perfectly. So what is nix-build doing or how can I fix that?
On top of that I also interested in all the criticism and comments that you can give to help me learn to write a better derivation.
sandbox-paths
A list of paths bind-mounted into Nix sandbox environments. You can use the syntax target=source to mount a path in a different location in the sandbox; for instance, /bin=/nix-bin will mount the path /nix-bin as /bin inside the sandbox. If source is followed by ?, then it is not an error if source does not exist; for example, /dev/nvidiactl? specifies that /dev/nvidiactl will only be mounted in the sandbox if it exists in the host filesystem.
Depending on how Nix was built, the default value for this option may be empty or provide /bin/sh as a bind-mount of bash.
``
Indeed that is the case, I have sandbox = true in /etc/nix/nix.conf (I am on NixOS and the default for nix.useSandbox is true).
Now I tried sudo nix-build --option extra-sandbox-paths /dev/tty default.nix but the error is the same. That looks strange to me. How should I activate extra-sandbox-paths for one build? Or do I need to set it permanently?
If I use --option sandbox-paths /dev/tty instead the test fail even more dramatic because lua’s io.popen returns nil (the test suite is in lua and calls external commands).
@olmokramer that does not work at once because xterm can not connect to the display:
/nix/store/mky314anzlqa3jqqacbp1kry3nzzcw0l-xterm-362/bin/xterm: Xt error: Can't open display:
/nix/store/mky314anzlqa3jqqacbp1kry3nzzcw0l-xterm-362/bin/xterm: DISPLAY is not set
I also tried this idea with tmux but the error stays the same.
Xterm also sounds like a strange workaround and I then have to deal with the display in the sandbox. Not sure if that is the way to go.