From 44ae89efeed232ddfaf92e0ddae0b71d90bad730 Mon Sep 17 00:00:00 2001 From: chn Date: Mon, 4 Dec 2023 20:57:52 +0800 Subject: [PATCH] nixpkgs: allow to replace tensorflow --- flake.lock | 12 ++++++------ flake.nix | 12 ++++++------ modules/system/nixpkgs.nix | 26 +++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/flake.lock b/flake.lock index 42d440e2..cc55e02b 100644 --- a/flake.lock +++ b/flake.lock @@ -1169,11 +1169,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1701660218, - "narHash": "sha256-hW/PSHXaF8L/06RN6fa/ZNyEjJCy0T2lN91dtBZ/FvE=", + "lastModified": 1701694102, + "narHash": "sha256-V51St+KHQoPiIma31qnl9tEV5+dC8f9a1AvV/hpq8mg=", "owner": "CHN-beta", "repo": "nixpkgs", - "rev": "3acbf3e037d3b8fafaac4a7e60defe9e8f741865", + "rev": "7b5fc5cb52b268ef5218bdd7a3aa31f9ac9a8efe", "type": "github" }, "original": { @@ -1185,11 +1185,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1701660161, - "narHash": "sha256-Q6N91xL87pMyKcV983ffJsjq13TItxdMNqMSPiBnUXY=", + "lastModified": 1701688908, + "narHash": "sha256-4m5mIRCsFSFsygGDiIz+7GKVbTsnUhcj7B9lRIAbTrY=", "owner": "CHN-beta", "repo": "nixpkgs", - "rev": "f90d85fe584c552c76252ccfa534ac30f2a6b4c6", + "rev": "26b8c3a268910f0adca218446c14aed9187e01ab", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index a95989ee..27181f0b 100644 --- a/flake.nix +++ b/flake.nix @@ -88,7 +88,7 @@ }) (localLib.attrsToList { - "pc" = + pc = [ (inputs: { config.nixos = { @@ -136,7 +136,7 @@ ]; keepOutputs = true; }; - nixpkgs = { march = "alderlake"; cudaSupport = true; }; + nixpkgs = { march = "alderlake"; cudaSupport = true; replaceTensorflow = true; }; gui = { enable = true; preferred = true; }; kernel.patches = [ "cjktty" ]; impermanence.enable = true; @@ -223,7 +223,7 @@ ]; };}) ]; - "vps6" = + vps6 = [ (inputs: { config.nixos = { @@ -296,7 +296,7 @@ }; };}) ]; - "vps7" = + vps7 = [ (inputs: { config.nixos = { @@ -362,7 +362,7 @@ }; };}) ]; - "nas" = + nas = [ (inputs: { config.nixos = { @@ -460,7 +460,7 @@ users.users = [ "root" "chn" "xll" "zem" "yjq" "yxy" ]; };}) ]; - "yoga" = + yoga = [ (inputs: { config.nixos = { diff --git a/modules/system/nixpkgs.nix b/modules/system/nixpkgs.nix index 278cb1c3..b63c79a3 100644 --- a/modules/system/nixpkgs.nix +++ b/modules/system/nixpkgs.nix @@ -4,12 +4,13 @@ inputs: { march = mkOption { type = types.nullOr types.nonEmptyStr; default = null; }; cudaSupport = mkOption { type = types.bool; default = false; }; + replaceTensorflow = mkOption { type = types.bool; default = false; }; }; config = let - inherit (builtins) map listToAttrs filter tryEval attrNames concatStringsSep; + inherit (builtins) map listToAttrs filter tryEval attrNames concatStringsSep toString; inherit (inputs.lib) mkIf; - inherit (inputs.lib.strings) hasPrefix; + inherit (inputs.lib.strings) hasPrefix splitString; inherit (inputs.localLib) mkConditional attrsToList; inherit (inputs.config.nixos.system) nixpkgs; in @@ -21,7 +22,7 @@ inputs: hostPlatform = mkConditional (nixpkgs.march != null) { system = "x86_64-linux"; gcc = { arch = nixpkgs.march; tune = nixpkgs.march; }; } "x86_64-linux"; - noBuildPackages = [ "chromium" "electron" "webkitgtk" "python310Packages" "nodejs" "pandoc" ]; + noBuildPackages = [ "chromium" "electron" "webkitgtk" "python310Packages" "nodejs" "pandoc" "fastfetch" ]; in { inherit hostPlatform; @@ -79,6 +80,25 @@ inputs: (package: { name = package; value = genericPackages.${package}; }) replacedPackages)) ) + // ( + if nixpkgs.replaceTensorflow then + let + versionString = + concatStringsSep "" (inputs.lib.lists.take 2 (splitString "." genericPackages.python3.version)); + pythonName = "python${versionString}"; + in + { + ${pythonName} = prev.${pythonName}.override { packageOverrides = final: prev: + { + tensorflow = prev.tensorflow.override + { + cudaSupport = false; + customBazelBuild = genericPackages.${pythonName}.pkgs.tensorflow.passthru.bazel-build; + }; + };}; + } + else {} + ) )]; }; programs.ccache = { enable = true; cacheDir = "/var/lib/ccache"; };