nixos/modules/system/nixpkgs.nix

161 lines
6.6 KiB
Nix
Raw Normal View History

2023-09-02 21:21:29 +08:00
inputs:
{
options.nixos.system.nixpkgs = let inherit (inputs.lib) mkOption types; in
{
march = mkOption { type = types.nullOr types.nonEmptyStr; default = null; };
2023-12-06 22:23:31 +08:00
cuda =
{
enable = mkOption { type = types.bool; default = false; };
2023-12-06 22:28:12 +08:00
capabilities = mkOption { type = types.nullOr (types.nonEmptyListOf types.nonEmptyStr); default = null; };
2023-12-06 22:23:31 +08:00
forwardCompat = mkOption { type = types.nullOr types.bool; default = null; };
};
2023-12-04 20:57:52 +08:00
replaceTensorflow = mkOption { type = types.bool; default = false; };
2023-09-02 21:21:29 +08:00
};
config =
let
2023-12-04 20:57:52 +08:00
inherit (builtins) map listToAttrs filter tryEval attrNames concatStringsSep toString;
2023-12-06 22:23:31 +08:00
inherit (inputs.lib) mkIf mkMerge;
2023-12-04 20:57:52 +08:00
inherit (inputs.lib.strings) hasPrefix splitString;
2023-12-04 17:27:47 +08:00
inherit (inputs.localLib) mkConditional attrsToList;
2023-09-02 21:21:29 +08:00
inherit (inputs.config.nixos.system) nixpkgs;
2023-12-06 22:23:31 +08:00
in mkMerge
[
{
nixpkgs =
let
permittedInsecurePackages =
2024-01-23 13:02:19 +08:00
[ "openssl_1_1" "electron_19" "python2" "electron_12" "electron_24" "zotero" "electron_25" ];
2023-12-06 22:23:31 +08:00
hostPlatform = mkConditional (nixpkgs.march != null)
{ system = "x86_64-linux"; gcc = { arch = nixpkgs.march; tune = nixpkgs.march; }; }
"x86_64-linux";
2023-12-07 21:12:01 +08:00
noBuildPackages = [];
# noBuildPackages =
# [
# # chromium
# "chromium" "electron" "webkitgtk"
# # old python release
# "python310"
# # nodejs
# "nodejs"
# # haskell
# "haskell"
# # libreoffice
# "libreoffice" "libreoffice-qt" "libreoffice-fresh"
# # java
# "openjdk" "jetbrains"
# ];
2023-12-06 22:23:31 +08:00
in
2023-09-02 21:21:29 +08:00
{
2023-12-06 22:23:31 +08:00
inherit hostPlatform;
config =
{
permittedInsecurePackages = map
(package: inputs.pkgs.${package}.name)
(filter (package: inputs.pkgs ? ${package}) permittedInsecurePackages);
allowUnfree = true;
2023-12-08 12:12:53 +08:00
qchem-config = { optArch = nixpkgs.march; useCuda = nixpkgs.cuda.enable; };
2023-12-06 22:23:31 +08:00
oneapiArch = mkIf (nixpkgs.march != null) nixpkgs.march;
};
overlays =
[(final: prev:
let
genericPackages = import inputs.topInputs.nixpkgs
2023-12-04 18:26:27 +08:00
{
2023-12-06 22:23:31 +08:00
system = "x86_64-linux";
2023-12-04 18:26:27 +08:00
config =
{
allowUnfree = true;
2023-12-06 22:23:31 +08:00
permittedInsecurePackages = let pkgs = inputs.topInputs.nixpkgs.legacyPackages.x86_64-linux; in map
(package: pkgs.${package}.name)
(filter (package: pkgs ? ${package}) permittedInsecurePackages);
2023-12-04 18:26:27 +08:00
};
};
2023-12-06 22:23:31 +08:00
targetPythonVersion = inputs.lib.lists.take 2 (splitString "." genericPackages.python3.version);
targetPythonName = "python${concatStringsSep "" targetPythonVersion}";
in
{ inherit genericPackages; }
// {
unstablePackages = import inputs.topInputs.nixpkgs-unstable
2023-12-04 20:57:52 +08:00
{
2023-12-06 22:23:31 +08:00
localSystem = hostPlatform;
config =
2023-12-04 20:57:52 +08:00
{
2023-12-06 22:23:31 +08:00
allowUnfree = true;
permittedInsecurePackages =
let pkgs = inputs.topInputs.nixpkgs-unstable.legacyPackages.x86_64-linux;
in map
(package: pkgs.${package}.name)
(filter (package: pkgs ? ${package}) permittedInsecurePackages);
2023-12-05 10:27:12 +08:00
};
2023-12-06 22:23:31 +08:00
};
2023-12-05 10:27:12 +08:00
}
2023-12-06 22:23:31 +08:00
// (
if nixpkgs.march != null then
let replacedPackages = filter
(package: let pname = tryEval genericPackages.${package}.pname or null;
in (pname.success && (builtins.elem pname.value noBuildPackages)
|| builtins.elem package noBuildPackages))
(filter
(package: builtins.any (prefix: hasPrefix prefix package) noBuildPackages)
(attrNames genericPackages));
in listToAttrs (map
(package: { name = package; value = genericPackages.${package}; })
replacedPackages)
else {}
)
2023-12-18 14:04:39 +08:00
// (
if nixpkgs.march != null then
{ embree = prev.embree.override { stdenv = final.genericPackages.stdenv; }; }
else {}
)
2023-12-06 22:23:31 +08:00
// (
if nixpkgs.replaceTensorflow then
{
${targetPythonName} = prev.${targetPythonName}.override { packageOverrides = final: prev:
{
tensorflow = prev.tensorflow.override
{
cudaSupport = false;
customBazelBuild = genericPackages.${targetPythonName}.pkgs.tensorflow.passthru.bazel-build;
};
};};
}
else {}
)
)];
};
programs.ccache = { enable = true; cacheDir = "/var/lib/ccache"; };
nix.settings.extra-sandbox-paths = [ inputs.config.programs.ccache.cacheDir ];
boot.kernelPatches = mkIf (nixpkgs.march != null)
[{
name = "native kernel";
patch = null;
extraStructuredConfig =
let
kernelConfig =
{
alderlake = "MALDERLAKE";
sandybridge = "MSANDYBRIDGE";
silvermont = "MSILVERMONT";
broadwell = "MBROADWELL";
2024-01-10 20:33:07 +08:00
skylake = "MSKYLAKE";
2023-12-06 22:23:31 +08:00
znver2 = "MZEN2";
znver3 = "MZEN3";
2024-01-13 22:28:22 +08:00
znver4 = "MZEN4";
2023-12-06 22:23:31 +08:00
};
in { GENERIC_CPU = inputs.lib.kernel.no; ${kernelConfig.${nixpkgs.march}} = inputs.lib.kernel.yes; };
}];
}
2024-02-20 19:08:46 +08:00
(
mkIf nixpkgs.cuda.enable
{
nixpkgs.config = { cudaSupport = true; }
2023-12-06 22:23:31 +08:00
// (if nixpkgs.cuda.capabilities != null then { cudaCapabilities = nixpkgs.cuda.capabilities; } else {})
2024-02-21 16:14:39 +08:00
// (if nixpkgs.cuda.forwardCompat != null then { cudaForwardCompat = nixpkgs.cuda.forwardCompat; } else {})
// (if nixpkgs.march != null then { nvhpcArch = nixpkgs.march; } else {});
2024-02-20 19:08:46 +08:00
environment.systemPackages = [ inputs.pkgs.cudatoolkit ];
}
)
2023-12-06 22:23:31 +08:00
];
2023-09-02 21:21:29 +08:00
}