From 80b9ae7d8a6999dd8ecc499c1b384436f141efe8 Mon Sep 17 00:00:00 2001 From: chn Date: Mon, 21 Jul 2025 18:09:13 +0800 Subject: [PATCH] lib.buildNixpkgsConfig: fix for non-nixos usage --- devices/jykang.xmuhpc/default.nix | 2 +- devices/xmuhk/default.nix | 2 +- flake/lib/buildNixpkgsConfig/default.nix | 10 +++++++--- flake/packages.nix | 2 +- modules/system/nixpkgs.nix | 3 ++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/devices/jykang.xmuhpc/default.nix b/devices/jykang.xmuhpc/default.nix index b084a1e1..d50a1d22 100644 --- a/devices/jykang.xmuhpc/default.nix +++ b/devices/jykang.xmuhpc/default.nix @@ -5,7 +5,7 @@ let pkgs = import inputs.nixpkgs (localLib.buildNixpkgsConfig { inputs = { inherit (inputs.nixpkgs) lib; topInputs = inputs; }; - nixpkgs = { march = "haswell"; cuda = null; nixRoot = "/data/gpfs01/jykang/.nix"; }; + nixpkgs = { march = "haswell"; cuda = null; nixRoot = "/data/gpfs01/jykang/.nix"; nixos = false; }; }); in pkgs.symlinkJoin { diff --git a/devices/xmuhk/default.nix b/devices/xmuhk/default.nix index fa52635e..dbe1d475 100644 --- a/devices/xmuhk/default.nix +++ b/devices/xmuhk/default.nix @@ -3,7 +3,7 @@ let pkgs = import inputs.nixpkgs (localLib.buildNixpkgsConfig { inputs = { inherit (inputs.nixpkgs) lib; topInputs = inputs; }; - nixpkgs = { march = null; cuda = null; nixRoot = "/public/home/xmuhk/.nix"; }; + nixpkgs = { march = null; cuda = null; nixRoot = "/public/home/xmuhk/.nix"; nixos = false; }; }); lumericalLicenseManager = let diff --git a/flake/lib/buildNixpkgsConfig/default.nix b/flake/lib/buildNixpkgsConfig/default.nix index 71824a19..448bc82f 100644 --- a/flake/lib/buildNixpkgsConfig/default.nix +++ b/flake/lib/buildNixpkgsConfig/default.nix @@ -1,9 +1,13 @@ -# inputs = { lib, topInputs, ...}; nixpkgs = { march, cuda, nixRoot }; +# inputs = { lib, topInputs, ...}; nixpkgs = { march, cuda, nixRoot, nixos }; { inputs, nixpkgs }: let platformConfig = if nixpkgs.march == null then { system = "x86_64-linux"; } - else { hostPlatform = { system = "x86_64-linux"; gcc = { arch = nixpkgs.march; tune = nixpkgs.march; }; }; }; + else + { + ${if nixpkgs.nixos then "hostPlatform" else "localSystem"} = + { system = "x86_64-linux"; gcc = { arch = nixpkgs.march; tune = nixpkgs.march; }; }; + }; cudaConfig = inputs.lib.optionalAttrs (nixpkgs.cuda != null) ( { cudaSupport = true; } @@ -83,7 +87,7 @@ in platformConfig // }; packages = name: import inputs.topInputs.${source.${name}.source or source.${name}} { - localSystem = platformConfig.hostPlatform or { inherit (platformConfig) system; }; + localSystem = platformConfig.hostPlatform or platformConfig.localSystem or platformConfig; inherit config; overlays = [(source.${name}.overlay or (_: _: {}))]; }; diff --git a/flake/packages.nix b/flake/packages.nix index e14dbdd1..56de7eec 100644 --- a/flake/packages.nix +++ b/flake/packages.nix @@ -3,7 +3,7 @@ pkgs = import inputs.nixpkgs (localLib.buildNixpkgsConfig { inputs = { inherit (inputs.nixpkgs) lib; topInputs = inputs; }; - nixpkgs = { march = null; cuda = null; nixRoot = null; }; + nixpkgs = { march = null; cuda = null; nixRoot = null; nixos = false; }; }); hpcstat = let diff --git a/modules/system/nixpkgs.nix b/modules/system/nixpkgs.nix index badc9779..a94603d2 100644 --- a/modules/system/nixpkgs.nix +++ b/modules/system/nixpkgs.nix @@ -15,7 +15,8 @@ inputs: }; config = let inherit (inputs.config.nixos.system) nixpkgs; in { - nixpkgs = inputs.localLib.buildNixpkgsConfig { inherit inputs; nixpkgs = nixpkgs // { nixRoot = null; }; }; + nixpkgs = inputs.localLib.buildNixpkgsConfig + { inherit inputs; nixpkgs = nixpkgs // { nixRoot = null; nixos = true; }; }; boot.kernelPatches = inputs.lib.mkIf (nixpkgs.march != null) [{ name = "native kernel";