nixos/modules/system/nixpkgs.nix

137 lines
5.3 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-09-03 17:17:10 +08:00
cudaSupport = mkOption { type = types.bool; default = false; };
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-04 17:27:47 +08:00
inherit (inputs.lib) mkIf;
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-04 17:27:47 +08:00
in
{
nixpkgs =
let
2023-12-04 18:26:27 +08:00
permittedInsecurePackages =
[ "openssl_1_1" "electron_19" "python2" "electron_12" "electron_24" "zotero" ];
2023-12-04 17:27:47 +08:00
hostPlatform = mkConditional (nixpkgs.march != null)
{ system = "x86_64-linux"; gcc = { arch = nixpkgs.march; tune = nixpkgs.march; }; }
"x86_64-linux";
2023-12-05 10:27:12 +08:00
noBuildPackages =
[
# chromium
"chromium" "electron" "webkitgtk"
# old python release
"python310"
# nodejs
"nodejs"
# haskell
"haskell"
# libreoffice
"libreoffice" "libreoffice-qt" "libreoffice-fresh"
# java
"openjdk" "jetbrains"
];
2023-12-04 17:27:47 +08:00
in
2023-09-02 21:21:29 +08:00
{
2023-12-04 17:27:47 +08:00
inherit hostPlatform;
config =
2023-09-02 21:21:29 +08:00
{
2023-12-04 18:26:27 +08:00
permittedInsecurePackages = map
(package: inputs.pkgs.${package}.name)
(filter (package: inputs.pkgs ? ${package}) permittedInsecurePackages);
2023-12-04 17:27:47 +08:00
allowUnfree = true;
cudaSupport = nixpkgs.cudaSupport;
qchem-config = mkIf (nixpkgs.march != null) { optArch = nixpkgs.march; };
oneapiArch = mkIf (nixpkgs.march != null) nixpkgs.march;
};
overlays =
[(final: prev:
let
genericPackages = import inputs.topInputs.nixpkgs
2023-09-10 16:40:19 +08:00
{
2023-12-04 17:27:47 +08:00
system = "x86_64-linux";
2023-12-04 18:26:27 +08:00
config =
{
allowUnfree = true;
permittedInsecurePackages = let pkgs = inputs.topInputs.nixpkgs.legacyPackages.x86_64-linux; in map
(package: pkgs.${package}.name)
(filter (package: pkgs ? ${package}) permittedInsecurePackages);
};
2023-09-10 16:40:19 +08:00
};
2023-12-05 10:27:12 +08:00
targetPythonVersion = inputs.lib.lists.take 2 (splitString "." genericPackages.python3.version);
targetPythonName = "python${concatStringsSep "" targetPythonVersion}";
2023-12-04 17:27:47 +08:00
in
{ inherit genericPackages; }
// {
unstablePackages = import inputs.topInputs.nixpkgs-unstable
2023-12-04 18:26:27 +08:00
{
localSystem = hostPlatform;
config =
{
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-04 17:27:47 +08:00
}
// (
2023-12-05 10:27:12 +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));
2023-12-05 11:43:08 +08:00
in listToAttrs (map
(package: { name = package; value = genericPackages.${package}; })
replacedPackages)
2023-12-05 10:27:12 +08:00
else {}
2023-12-04 17:27:47 +08:00
)
2023-12-04 20:57:52 +08:00
// (
if nixpkgs.replaceTensorflow then
2023-12-05 10:27:12 +08:00
{
${targetPythonName} = prev.${targetPythonName}.override { packageOverrides = final: prev:
2023-12-04 20:57:52 +08:00
{
2023-12-05 10:27:12 +08:00
tensorflow = prev.tensorflow.override
2023-12-04 20:57:52 +08:00
{
2023-12-05 10:27:12 +08:00
cudaSupport = false;
customBazelBuild = genericPackages.${targetPythonName}.pkgs.tensorflow.passthru.bazel-build;
};
};};
}
2023-12-04 20:57:52 +08:00
else {}
)
2023-12-04 17:27:47 +08:00
)];
};
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";
znver2 = "MZEN2";
znver3 = "MZEN3";
};
in { GENERIC_CPU = inputs.lib.kernel.no; ${kernelConfig.${nixpkgs.march}} = inputs.lib.kernel.yes; };
}];
};
2023-09-02 21:21:29 +08:00
}