Skip to content

Commit 3d60026

Browse files
committed
nix support: adjustments pointed out by ruki
1 parent a5223db commit 3d60026

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

xmake/modules/detect/tools/find_nix.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,15 @@ function main(opt)
4545
local nix_paths = {
4646
"/nix/var/nix/profiles/default/bin", -- multi-user installation
4747
"/home/" .. (os.getenv("USER") or "user") .. "/.nix-profile/bin", -- single user installation
48-
"/run/current-system/sw/bin", -- only on nixos, maybe separate nix logic from nixos logic?
4948
"/usr/local/bin", -- default path of nix when compiling nix from source
5049
}
50+
51+
-- NixOS-specific paths
52+
if linuxos.name() == "nixos" then
53+
table.insert(nix_paths, "/run/current-system/sw/bin")
54+
end
5155

56+
opt.paths = table.wrap(opt.paths)
5257
for _, nixpath in ipairs(nix_paths) do
5358
table.insert(opt.paths, nixpath)
5459
end

xmake/modules/package/manager/nix/find_package.lua

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ function _get_available_nix_paths()
6767
-- Also check for manifest (generation info)
6868
local manifest = path.join(location, "manifest.nix")
6969
if os.isfile(manifest) then
70-
local manifest_content = try {function()
71-
return io.readfile(manifest)
72-
end}
70+
local manifest_content = io.readfile(manifest)
7371

7472
if manifest_content then
7573
-- Extract store paths from manifest
@@ -142,17 +140,8 @@ function _find_in_store_path(store_path, name)
142140
if os.isdir(pcdir) then
143141
local pcfiles = os.files(path.join(pcdir, name .. ".pc"))
144142
if #pcfiles > 0 then
145-
-- Use pkg-config to get proper info
146-
local old_path = os.getenv("PKG_CONFIG_PATH")
147-
os.setenv("PKG_CONFIG_PATH", pcdir .. (old_path and (":" .. old_path) or ""))
148-
149-
local pcresult = find_package_from_pkgconfig(name)
150-
151-
if old_path then
152-
os.setenv("PKG_CONFIG_PATH", old_path)
153-
else
154-
os.setenv("PKG_CONFIG_PATH", nil)
155-
end
143+
-- Use pkg-config with configdirs
144+
local pcresult = find_package_from_pkgconfig(name, {configdirs = pcdir})
156145

157146
if pcresult then
158147
return pcresult

xmake/modules/package/manager/nix/install_package.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
-- imports
2222
import("core.base.option")
2323
import("lib.detect.find_tool")
24+
import("private.core.base.is_cross")
2425

2526
-- install package
2627
--
@@ -39,9 +40,9 @@ function main(name, opt)
3940
raise("nix not found!")
4041
end
4142

42-
-- check architecture (nix supports cross compilation but for simplicity...)
43-
if opt.arch ~= os.arch() then
44-
raise("cannot install package(%s) for arch(%s)!", name, opt.arch)
43+
-- check architecture
44+
if is_cross(opt.plat, opt.arch) then
45+
raise("cannot install package(%s) for cross compilation!", name)
4546
end
4647

4748
local success = false

0 commit comments

Comments
 (0)