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

nixos/nix-ld: Support 32-bit portability #326948

Open
wants to merge 3 commits into
base: master
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
16 changes: 16 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@
);
});

systems.x86_64-linux.test =
(self.lib.nixosSystem {
system = "x86_64-linux";
modules = [
({
boot.loader.grub.enable = false;
fileSystems."/".device = "nodev";
# See https://search.nixos.org/options?show=system.stateVersion&query=stateversion
system.stateVersion = lib.versions.majorMinor lib.version; # DON'T do this in real configs!

programs.nix-ld.systems.x86_64-linux = { };
})
];
});
packages.x86_64-linux.test = self.systems.x86_64-linux.test.config.system.build.toplevel;

checks = forAllSystems (system: {
tarball = jobs.${system}.tarball;
# Exclude power64 due to "libressl is not available on the requested hostPlatform" with hostPlatform being power64
Expand Down
2 changes: 1 addition & 1 deletion nixos/doc/manual/release-notes/rl-2205.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ In addition to numerous new and upgraded packages, this release has the followin

- [nifi](https://nifi.apache.org), an easy to use, powerful, and reliable system to process and distribute data. Available as [services.nifi](#opt-services.nifi.enable).

- [nix-ld](https://github.com/Mic92/nix-ld), Run unpatched dynamic binaries on NixOS. Available as [programs.nix-ld](#opt-programs.nix-ld.enable).
- [nix-ld](https://github.com/Mic92/nix-ld), Run unpatched dynamic binaries on NixOS. Available as `programs.nix-ld`.

- [NNCP](http://www.nncpgo.org), NNCP (Node to Node copy) utilities and configuration, Available as [programs.nncp](#opt-programs.nncp.enable).

Expand Down
136 changes: 92 additions & 44 deletions nixos/modules/programs/nix-ld.nix
Original file line number Diff line number Diff line change
@@ -1,61 +1,109 @@
{ pkgs, lib, config, ... }:
let
cfg = config.programs.nix-ld;
inherit (lib)
literalExpression
mapAttrsToList
mergeAttrsList
mkEnableOption
mkMerge
mkOption
mkPackageOption
types;

nix-ld-libraries = pkgs.buildEnv {
cfg = config.programs.nix-ld.systems;

share-path = system: "share/nix-ld-${system}";

nix-ld-libraries = system: cfg: cfg.pkgs.buildEnv {
name = "ld-library-path";
pathsToLink = [ "/lib" ];
paths = map lib.getLib cfg.libraries;
# TODO make glibc here configurable?
postBuild = ''
ln -s ${pkgs.stdenv.cc.bintools.dynamicLinker} $out/share/nix-ld/lib/ld.so
ln -s ${cfg.pkgs.stdenv.cc.bintools.dynamicLinker} $out/${share-path system}/lib/ld.so
'';
extraPrefix = "/share/nix-ld";
extraPrefix = "/${share-path system}";
ignoreCollisions = true;
};
in
{
meta.maintainers = [ lib.maintainers.mic92 ];
options.programs.nix-ld = {
enable = lib.mkEnableOption ''nix-ld, Documentation: <https://github.com/Mic92/nix-ld>'';
package = lib.mkPackageOption pkgs "nix-ld" { };
libraries = lib.mkOption {
type = lib.types.listOf lib.types.package;
description = "Libraries that automatically become available to all programs. The default set includes common libraries.";
default = [ ];
defaultText = lib.literalExpression "baseLibraries derived from systemd and nix dependencies.";
};
};

config = lib.mkIf config.programs.nix-ld.enable {
environment.ldso = "${cfg.package}/libexec/nix-ld";

environment.systemPackages = [ nix-ld-libraries ];

environment.pathsToLink = [ "/share/nix-ld" ];

environment.variables = {
NIX_LD = "/run/current-system/sw/share/nix-ld/lib/ld.so";
NIX_LD_LIBRARY_PATH = "/run/current-system/sw/share/nix-ld/lib";
};

# We currently take all libraries from systemd and nix as the default.
# Is there a better list?
programs.nix-ld.libraries = with pkgs; [
zlib
zstd
stdenv.cc.cc
curl
openssl
attr
libssh
bzip2
libxml2
acl
libsodium
util-linux
xz
systemd
];
options.programs.nix-ld.systems = mkOption {
default = { };
description = ''
Configure nix-ld for the given system.
'';
type = types.attrsOf (types.submodule {
options = {
enable = mkEnableOption "nix-ld for the given system";
package = mkPackageOption pkgs "nix-ld" { };

pkgs = mkOption {
type = types.pkgs;
default = pkgs;
defaultText = "pkgs";
description = "Package set to use";
};

ldso = mkOption {
type = types.str;
description = ''
Which runtime loader to override, either `ldso` or `ldso32`, see
`environment.ldso` and `environment.ldso32`.
'';
default = "ldso";
};

libraries = mkOption {
type = types.listOf types.package;
description = "Libraries that automatically become available to all programs. The default set includes common libraries.";
default = [ ];
defaultText = literalExpression "baseLibraries derived from systemd and nix dependencies.";
};
};
});
};

config =
let
recursive =
# mkMerge
mergeAttrsList
(mapAttrsToList
(system: cfg: {
environment.${cfg.ldso} = "${cfg.package}/libexec/nix-ld";

environment.systemPackages = [ (nix-ld-libraries system cfg) ];

environment.pathsToLink = [ "/${share-path system}" ];

environment.variables = {
"NIX_LD_${builtins.replaceStrings ["-"] ["_"] system}" = "/run/current-system/sw/${share-path system}/lib/ld.so";
"NIX_LD_LIBRARY_PATH_${builtins.replaceStrings ["-"] ["_"] system}" = "/run/current-system/sw/${share-path system}/lib";
};

# We currently take all libraries from systemd and nix as the default.
# Is there a better list?
programs.nix-ld.systems.${system}.libraries = with cfg.pkgs; [
zlib
zstd
stdenv.cc.cc
curl
openssl
attr
libssh
bzip2
libxml2
acl
libsodium
util-linux
xz
systemd
];
})
cfg);
in
# recursive;
{ environment.etc.foo.text = builtins.toJSON recursive; };
}