Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixseparatedebuginfod: new module #1242

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/modules/services/nixseparatedebuginfod.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{ pkgs, lib, config, ... }:

let
cfg = config.services.nixseparatedebuginfod;
listen_address = "${cfg.host}:${toString cfg.port}";
in
{
options.services.nixseparatedebuginfod = {
enable = lib.mkEnableOption "nixseparatedebuginfod";

package = lib.mkOption {
type = lib.types.package;
default = pkgs.nixseparatedebuginfod;
description = "nixseparatedebuginfod package to use.";
};

host = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
description = "IP address for nixseparatedebuginfod to listen on.";
};

port = lib.mkOption {
type = lib.types.port;
default = 1949;
description = "Port for nixseparatedebuginfod to listen on.";
};
};

config = lib.mkIf cfg.enable {
processes.nixseparatedebuginfod.exec = ''
exec ${lib.getExe cfg.package} -l ${listen_address}
'';

enterShell = ''
export DEBUGINFOD_URLS="http://${listen_address}''${DEBUGINFOD_URLS:+ $DEBUGINFOD_URLS}"
'';
};
}
10 changes: 10 additions & 0 deletions tests/nixseparatedebuginfod/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: all
all: example

.PHONY: install
install: example
install -Dm755 $< $(DESTDIR)/bin/$<

.PHONY: clean
clean:
$(RM) example
28 changes: 28 additions & 0 deletions tests/nixseparatedebuginfod/devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ lib, pkgs, config, ... }:

let
cfg = config.services.nixseparatedebuginfod;
inherit (pkgs.stdenv) hostPlatform;

# Use a locally built derivation so that the test wouldn't rely on cache.nixos.org
cbin = pkgs.stdenv.mkDerivation {
pname = "cbin";
version = "1.0";
src = ./.;
installFlags = [ "DESTDIR=$(out)" ];
separateDebugInfo = true;
meta.mainProgram = "example";
};
in
lib.mkIf (lib.meta.availableOn hostPlatform cfg.package) {
services.nixseparatedebuginfod.enable = true;

# The Nix store needs to be indexed by nixseparatedebuginfod for debug outputs from local
# derivations to be served. This can take a few minutes.
process.before = "${lib.getExe cfg.package} --index-only";
Comment on lines +20 to +22
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test that fetches debuginfo from the server, but I'm not sure if this is a good idea. nixseparatedebuginfod needs to index the Nix store before it can serve debuginfos for locally built derivations. This can "take a few minutes" according to the official README. On my machine, it took a little more than a minute so I set the timeout to 2 minutes. The actual time will likely depend on the size of the Nix store and I don't know if 2 minutes is going to be enough, though.


enterTest = ''
wait_for_port ${toString cfg.port} 120
${pkgs.elfutils}/bin/debuginfod-find debuginfo ${lib.getExe cbin}
'';
}
3 changes: 3 additions & 0 deletions tests/nixseparatedebuginfod/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(void) {
return 0;
}