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

lib.getExe: Do not make assumptions about the main program #246386

Merged
Merged
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
6 changes: 5 additions & 1 deletion lib/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,9 @@ rec {
=> "/nix/store/am9ml4f4ywvivxnkiaqwr0hyxka1xjsf-mustache-go-1.3.0/bin/mustache"
*/
getExe = x:
"${lib.getBin x}/bin/${x.meta.mainProgram or (lib.getName x)}";
"${lib.getBin x}/bin/${x.meta.mainProgram or (
# This could be turned into an error when 23.05 is at end of life
lib.warn "getExe: Package ${lib.strings.escapeNixIdentifier x.meta.name or x.pname or x.name} does not have the meta.mainProgram attribute. We'll assume that the main program has the same name for now, but this behavior is deprecated, because it leads to surprising errors when the assumption does not hold. If the package has a main program, please set `meta.mainProgram` in its definition to make this warning go away. Otherwise, if the package does not have a main program, or if you don't control its definition, specify the full path to the program, such as \"\${lib.getBin foo}/bin/bar\"."
lib.getName x
)}";
}
7 changes: 6 additions & 1 deletion nixos/modules/programs/oddjobd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ in
};

config = lib.mkIf cfg.enable {
assertions = [
Copy link
Member

Choose a reason for hiding this comment

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

I really like this pattern!

{ assertion = false;
message = "The oddjob service was found to be broken without NixOS test or maintainer. Please take ownership of this service.";
}
];
systemd.packages = [ cfg.package ];

systemd.services.oddjobd = {
Expand All @@ -21,7 +26,7 @@ in
serviceConfig = {
Type = "dbus";
BusName = "org.freedesktop.oddjob";
ExecStart = "${lib.getExe cfg.package}/bin/oddjobd";
ExecStart = "${lib.getBin cfg.package}/bin/oddjobd";
};
};
};
Expand Down
1 change: 1 addition & 0 deletions pkgs/applications/audio/espeak-ng/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ stdenv.mkDerivation rec {
license = licenses.gpl3Plus;
maintainers = with maintainers; [ aske ];
platforms = platforms.all;
mainProgram = "espeak-ng";
};
}
1 change: 1 addition & 0 deletions pkgs/applications/display-managers/greetd/regreet.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ rustPlatform.buildRustPackage rec {
license = licenses.gpl3Plus;
maintainers = with maintainers; [ fufexan ];
platforms = platforms.linux;
mainProgram = "regreet";
};
}
1 change: 1 addition & 0 deletions pkgs/applications/emulators/darling/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,6 @@ in stdenv.mkDerivation {
license = licenses.gpl3Plus;
maintainers = with maintainers; [ zhaofengli ];
platforms = [ "x86_64-linux" ];
mainProgram = "darling";
};
}
1 change: 1 addition & 0 deletions pkgs/applications/graphics/openscad/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ mkDerivation rec {
license = lib.licenses.gpl2;
platforms = lib.platforms.unix;
maintainers = with lib.maintainers; [ bjornfor raskin gebner ];
mainProgram = "openscad";
};
}
1 change: 1 addition & 0 deletions pkgs/applications/graphics/tesseract/tesseract5.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ stdenv.mkDerivation rec {
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ anselmschueler ];
platforms = lib.platforms.unix;
mainProgram = "tesseract";
};
}
5 changes: 5 additions & 0 deletions pkgs/applications/networking/browsers/firefox/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# not in `badPlatforms` because cross-compilation on 64-bit machine might work.
maxSilent = 14400; # 4h, double the default of 7200s (c.f. #129212, #129115)
license = lib.licenses.mpl20;
mainProgram = "firefox";
};
tests = [ nixosTests.firefox ];
updateScript = callPackage ./update.nix {
Expand All @@ -46,6 +47,7 @@
# not in `badPlatforms` because cross-compilation on 64-bit machine might work.
maxSilent = 14400; # 4h, double the default of 7200s (c.f. #129212, #129115)
license = lib.licenses.mpl20;
mainProgram = "firefox";
};
tests = [ nixosTests.firefox-beta ];
updateScript = callPackage ./update.nix {
Expand Down Expand Up @@ -74,6 +76,7 @@
# not in `badPlatforms` because cross-compilation on 64-bit machine might work.
maxSilent = 14400; # 4h, double the default of 7200s (c.f. #129212, #129115)
license = lib.licenses.mpl20;
mainProgram = "firefox";
};
tests = [ nixosTests.firefox-devedition ];
updateScript = callPackage ./update.nix {
Expand Down Expand Up @@ -104,6 +107,7 @@
broken = stdenv.buildPlatform.is32bit; # since Firefox 60, build on 32-bit platforms fails with "out of memory".
# not in `badPlatforms` because cross-compilation on 64-bit machine might work.
license = lib.licenses.mpl20;
mainProgram = "firefox";
};
tests = [ nixosTests.firefox-esr-102 ];
updateScript = callPackage ./update.nix {
Expand Down Expand Up @@ -132,6 +136,7 @@
broken = stdenv.buildPlatform.is32bit; # since Firefox 60, build on 32-bit platforms fails with "out of memory".
# not in `badPlatforms` because cross-compilation on 64-bit machine might work.
license = lib.licenses.mpl20;
mainProgram = "firefox";
};
tests = [ nixosTests.firefox-esr-115 ];
updateScript = callPackage ./update.nix {
Expand Down
1 change: 1 addition & 0 deletions pkgs/applications/networking/clash-verge/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ stdenv.mkDerivation rec {
license = licenses.gpl3Plus;
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
maintainers = with maintainers; [ zendo ];
mainProgram = "clash-verge";
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let
{
pythonInterpreter = "${python3.interpreter}";
configDirName = lib.toLower binaryName;
meta.mainProgram = "disable-breaking-updates.py";
} ''
mkdir -p $out/bin
cp ${./disable-breaking-updates.py} $out/bin/disable-breaking-updates.py
Expand Down
1 change: 1 addition & 0 deletions pkgs/applications/networking/irc/thelounge/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ stdenv.mkDerivation (finalAttrs: {
maintainers = with maintainers; [ winter raitobezarius ];
license = licenses.mit;
inherit (nodejs.meta) platforms;
mainProgram = "thelounge";
};
})
1 change: 1 addition & 0 deletions pkgs/applications/version-management/gitea/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ buildGoModule rec {
license = licenses.mit;
maintainers = with maintainers; [ disassembler kolaente ma27 techknowlogick ];
broken = stdenv.isDarwin;
mainProgram = "gitea";
};
}
1 change: 1 addition & 0 deletions pkgs/applications/virtualization/kvmtool/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ stdenv.mkDerivation {
license = licenses.gpl2Only;
maintainers = with maintainers; [ astro ];
platforms = [ "x86_64-linux" "aarch64-linux" ];
mainProgram = "nvramtool";
};
}
1 change: 1 addition & 0 deletions pkgs/applications/window-managers/cage/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ stdenv.mkDerivation rec {
license = licenses.mit;
platforms = platforms.linux;
maintainers = with maintainers; [ primeos ];
mainProgram = "cage";
};
}
24 changes: 17 additions & 7 deletions pkgs/build-support/writers/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ rec {
name = last (builtins.split "/" nameOrPath);
in

pkgs.runCommandLocal name (if (types.str.check content) then {
inherit content interpreter;
passAsFile = [ "content" ];
} else {
inherit interpreter;
contentPath = content;
}) ''
pkgs.runCommandLocal name (
lib.optionalAttrs (nameOrPath == "/bin/${name}") {
meta.mainProgram = name;
}
// (
if (types.str.check content) then {
inherit content interpreter;
passAsFile = [ "content" ];
} else {
inherit interpreter;
contentPath = content;
}
)
)
''
# On darwin a script cannot be used as an interpreter in a shebang but
# there doesn't seem to be a limit to the size of shebang and multiple
# arguments to the interpreter are allowed.
Expand Down Expand Up @@ -89,6 +97,8 @@ rec {
# https://github.com/NixOS/nixpkgs/issues/154203
# https://github.com/NixOS/nixpkgs/issues/148189
nativeBuildInputs = [ stdenv.cc.bintools ];
} // lib.optionalAttrs (nameOrPath == "/bin/${name}") {
meta.mainProgram = name;
}) ''
${compileScript}
${lib.optionalString strip
Expand Down
1 change: 1 addition & 0 deletions pkgs/desktops/gnome/apps/file-roller/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ stdenv.mkDerivation rec {
license = licenses.gpl2Plus;
platforms = platforms.linux;
maintainers = teams.gnome.members ++ teams.pantheon.members;
mainProgram = "file-roller";
};
}
1 change: 1 addition & 0 deletions pkgs/development/interpreters/perl/intepreter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ stdenv.mkDerivation (rec {
maintainers = [ maintainers.eelco ];
platforms = platforms.all;
priority = 6; # in `buildEnv' (including the one inside `perl.withPackages') the library files will have priority over files in `perl`
mainProgram = "perl";
};
} // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) rec {
crossVersion = "c876045741f5159318085d2737b0090f35a842ca"; # June 5, 2022
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/interpreters/python/cpython/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -572,5 +572,6 @@ in with passthru; stdenv.mkDerivation {
license = licenses.psfl;
platforms = platforms.linux ++ platforms.darwin;
maintainers = with maintainers; [ fridh ];
mainProgram = "python3";
Copy link
Member

Choose a reason for hiding this comment

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

This is not quite correct, fix in #247955

Copy link
Member Author

Choose a reason for hiding this comment

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

It preserved the prior behavior of lib.getExe on python, by virtue of being equal to the pname value (except for python3Minimal, where "python3" is a fix).

I have no opinion on what the mainProgram for the python interpreters should be.

};
}
1 change: 1 addition & 0 deletions pkgs/development/libraries/xdg-dbus-proxy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ stdenv.mkDerivation rec {
license = licenses.lgpl21Plus;
maintainers = with maintainers; [ jtojnar ];
platforms = platforms.linux;
mainProgram = "xdg-dbus-proxy";
};
}
1 change: 1 addition & 0 deletions pkgs/development/python-modules/flake8/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ buildPythonPackage rec {
homepage = "https://github.com/pycqa/flake8";
license = licenses.mit;
maintainers = with maintainers; [ dotlambda ];
mainProgram = "flake8";
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ buildGoModule {

meta = common.meta // {
description = "Woodpecker Continuous Integration agent";
mainProgram = "woodpecker-agent";
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ buildGoModule {

meta = common.meta // {
description = "Woodpecker Continuous Integration server";
mainProgram = "woodpecker-server";
};
}
1 change: 1 addition & 0 deletions pkgs/development/tools/esbuild/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ buildGoModule rec {
changelog = "https://github.com/evanw/esbuild/blob/v${version}/CHANGELOG.md";
license = licenses.mit;
maintainers = with maintainers; [ lucus16 marsam undefined-moe ];
mainProgram = "esbuild";
};
}
1 change: 1 addition & 0 deletions pkgs/development/tools/esbuild/netlify.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ buildGoModule rec {
homepage = "https://github.com/netlify/esbuild";
license = licenses.mit;
maintainers = with maintainers; [ roberth ];
mainProgram = "esbuild";
};
}
1 change: 1 addition & 0 deletions pkgs/development/tools/geckodriver/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ rustPlatform.buildRustPackage rec {
homepage = "https://github.com/mozilla/geckodriver";
license = licenses.mpl20;
maintainers = with maintainers; [ jraygauthier ];
mainProgram = "geckodriver";
};
}
2 changes: 2 additions & 0 deletions pkgs/development/tools/misc/libtool/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ stdenv.mkDerivation rec {

license = lib.licenses.gpl2Plus;
platforms = lib.platforms.unix;

mainProgram = "libtool";
};
}
1 change: 1 addition & 0 deletions pkgs/development/tools/misc/libtool/libtool2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ stdenv.mkDerivation rec {
license = licenses.gpl2Plus;
maintainers = [ ];
platforms = platforms.unix;
mainProgram = "libtool";
};
}
1 change: 1 addition & 0 deletions pkgs/development/tools/misc/tokei/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ rustPlatform.buildRustPackage rec {
homepage = "https://github.com/XAMPPRocky/tokei";
license = with licenses; [ asl20 /* or */ mit ];
maintainers = with maintainers; [ gebner lilyball ];
mainProgram = "tokei";
};
}
1 change: 1 addition & 0 deletions pkgs/development/tools/selenium/chromedriver/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ in stdenv.mkDerivation rec {
# Note from primeos: By updating Chromium I also update Google Chrome and
# ChromeDriver.
platforms = attrNames allSpecs;
mainProgram = "chromedriver";
};
}
1 change: 1 addition & 0 deletions pkgs/os-specific/linux/below/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ rustPlatform.buildRustPackage rec {
description = "A time traveling resource monitor for modern Linux systems";
license = licenses.asl20;
homepage = "https://github.com/facebookincubator/below";
mainProgram = "below";
};
}
1 change: 1 addition & 0 deletions pkgs/servers/code-server/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,6 @@ stdenv.mkDerivation (finalAttrs: {
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ offline henkery code-asher ];
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
mainProgram = "code-server";
};
})
1 change: 1 addition & 0 deletions pkgs/servers/consul/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ buildGoModule rec {
platforms = platforms.linux ++ platforms.darwin;
license = licenses.mpl20;
maintainers = with maintainers; [ pradeepchhetri vdemeester nh2 techknowlogick];
mainProgram = "consul";
};
}
1 change: 1 addition & 0 deletions pkgs/servers/dns/acme-dns/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ buildGoModule rec {
changelog = "https://github.com/joohoi/acme-dns/releases/tag/${src.rev}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ emilylange ];
mainProgram = "acme-dns";
};
}
1 change: 1 addition & 0 deletions pkgs/servers/ldap/lldap/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ in rustPlatform.buildRustPackage (commonDerivationAttrs // {
license = licenses.gpl3Only;
platforms = platforms.linux;
maintainers = with maintainers; [ emilylange bendlas ];
mainProgram = "lldap";
};
})
1 change: 1 addition & 0 deletions pkgs/servers/monitoring/grafana-agent/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ buildGoModule rec {
homepage = "https://grafana.com/products/cloud";
changelog = "https://github.com/grafana/agent/blob/${src.rev}/CHANGELOG.md";
maintainers = with lib.maintainers; [ flokli emilylange ];
mainProgram = "grafana-agent";
};
}
1 change: 1 addition & 0 deletions pkgs/servers/openvscode-server/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,6 @@ stdenv.mkDerivation (finalAttrs: {
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ dguenther ghuntley emilytrau ];
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
mainProgram = "openvscode-server";
};
})
1 change: 1 addition & 0 deletions pkgs/servers/pufferpanel/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ buildGoModule rec {
homepage = "https://www.pufferpanel.com/";
license = with licenses; [ asl20 ];
maintainers = with maintainers; [ ckie tie ];
mainProgram = "pufferpanel";
};
}
1 change: 1 addition & 0 deletions pkgs/servers/web-apps/kavita/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ stdenvNoCC.mkDerivation (finalAttrs: {
license = lib.licenses.gpl3Only;
platforms = lib.platforms.linux;
maintainers = with lib.maintainers; [ misterio77 ];
mainProgram = "kavita";
};
})
10 changes: 10 additions & 0 deletions pkgs/servers/x11/xorg/overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ self: super:
+ lib.optionalString stdenv.hostPlatform.isStatic ''
export NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK -lXau -lXdmcp"
'';
meta = attrs.meta // {
mainProgram = "xdpyinfo";
};
});

xdm = super.xdm.overrideAttrs (attrs: {
Expand Down Expand Up @@ -814,6 +817,7 @@ self: super:
--replace '_X_NORETURN' '__attribute__((noreturn))' \
--replace 'n_dirs--;' ""
'';
meta.mainProgram = "lndir";
});

twm = super.twm.overrideAttrs (attrs: {
Expand Down Expand Up @@ -940,6 +944,12 @@ self: super:
'';
});

xset = super.xset.overrideAttrs (attrs: {
meta = attrs.meta // {
mainProgram = "xset";
};
});

# convert Type1 vector fonts to OpenType fonts
fontbitstreamtype1 = super.fontbitstreamtype1.overrideAttrs (attrs: {
nativeBuildInputs = attrs.nativeBuildInputs ++ [ fontforge ];
Expand Down
1 change: 1 addition & 0 deletions pkgs/tools/backup/tarsnap/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ stdenv.mkDerivation rec {
license = lib.licenses.unfree;
platforms = lib.platforms.unix;
maintainers = with lib.maintainers; [ thoughtpolice roconnor ];
mainProgram = "tarsnap";
};
}
1 change: 1 addition & 0 deletions pkgs/tools/misc/coreboot-utils/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ let
nvramtool = generic {
pname = "nvramtool";
meta.description = "Read and write coreboot parameters and display information from the coreboot table in CMOS/NVRAM";
meta.mainProgram = "nvramtool";
};
superiotool = generic {
pname = "superiotool";
Expand Down
Loading