nixos/modules/system/nixpkgs.nix

147 lines
6.2 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
{
2024-03-25 17:03:13 +08:00
arch = mkOption { type = types.enum [ "x86_64" "aarch64" ]; default = "x86_64"; };
2023-09-02 21:21:29 +08:00
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-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;
in
{
nixpkgs =
let
permittedInsecurePackages =
2024-06-26 15:20:12 +08:00
[ "openssl_1_1" "python2" "zotero" "electron_27" "electron_28" ];
hostPlatform = if nixpkgs.march != null
2024-03-25 17:03:13 +08:00
then { system = "${nixpkgs.arch}-linux"; gcc = { arch = nixpkgs.march; tune = nixpkgs.march; }; }
else "${nixpkgs.arch}-linux";
cudaConfig = inputs.lib.optionalAttrs nixpkgs.cuda.enable
(
{ cudaSupport = true; }
// (inputs.lib.optionalAttrs (nixpkgs.cuda.capabilities != null)
{ cudaCapabilities = nixpkgs.cuda.capabilities; })
// (inputs.lib.optionalAttrs (nixpkgs.cuda.forwardCompat != null)
{ cudaForwardCompat = nixpkgs.cuda.forwardCompat; })
);
in
{
inherit hostPlatform;
config = cudaConfig //
2023-09-02 21:21:29 +08:00
{
2024-06-23 11:47:38 +08:00
permittedInsecurePackages = map (package: inputs.pkgs.${package}.name) permittedInsecurePackages;
allowUnfree = true;
qchem-config = { optArch = nixpkgs.march; useCuda = nixpkgs.cuda.enable; };
2024-03-12 15:16:54 +08:00
}
// (if nixpkgs.march == null then {} else
{
2024-03-12 21:27:47 +08:00
oneapiArch = let match = { znver3 = "CORE-AVX2"; znver4 = "CORE-AVX512"; };
in match.${nixpkgs.march} or nixpkgs.march;
nvhpcArch = nixpkgs.march;
# contentAddressedByDefault = true;
2024-07-09 10:01:31 +08:00
enableCcache = true;
2024-03-12 15:16:54 +08:00
});
overlays =
[(final: prev:
let
2024-03-25 16:55:13 +08:00
inherit (final) system;
genericPackages = import inputs.topInputs.nixpkgs
{
2024-03-25 16:55:13 +08:00
inherit system;
config =
{
allowUnfree = true;
2024-03-25 16:55:13 +08:00
permittedInsecurePackages = let pkgs = inputs.topInputs.nixpkgs.legacyPackages.${system}; in map
(package: pkgs.${package}.name)
(filter (package: pkgs ? ${package}) permittedInsecurePackages);
};
};
in
2024-03-03 19:15:04 +08:00
{ inherit genericPackages; }
// (
let
source =
2023-12-04 18:26:27 +08:00
{
2024-06-12 21:47:42 +08:00
"pkgs-23.11" = "nixpkgs-23.11";
2024-03-03 19:15:04 +08:00
"pkgs-23.05" = "nixpkgs-23.05";
"pkgs-22.11" = "nixpkgs-22.11";
"pkgs-22.05" = "nixpkgs-22.05";
2023-12-04 18:26:27 +08:00
};
2024-06-23 11:47:38 +08:00
permittedInsecurePackages."pkgs-23.11" = [ "electron_19" ];
2024-03-03 19:15:04 +08:00
packages = name: import inputs.topInputs.${source.${name}}
{
localSystem = hostPlatform;
config = cudaConfig //
{
allowUnfree = true;
# contentAddressedByDefault = true;
2024-03-03 19:15:04 +08:00
permittedInsecurePackages =
2024-03-25 16:55:13 +08:00
let pkgs = inputs.topInputs.${source.${name}}.legacyPackages.${system};
2024-03-03 19:15:04 +08:00
in map
(package: pkgs.${package}.name)
2024-06-23 11:47:38 +08:00
permittedInsecurePackages.${name} or [];
2024-03-03 19:15:04 +08:00
};
};
in builtins.listToAttrs (map
(name: { inherit name; value = packages name; }) (builtins.attrNames source))
)
2024-05-22 10:44:41 +08:00
// (
inputs.lib.optionalAttrs (nixpkgs.march != null)
{
embree = prev.embree.override { stdenv = final.genericPackages.stdenv; };
libvorbis = prev.libvorbis.override { stdenv = final.genericPackages.stdenv; };
2024-05-24 16:01:19 +08:00
_7zz = prev._7zz.override { stdenv = final.genericPackages.stdenv; };
2024-05-25 16:37:54 +08:00
ispc = genericPackages.ispc;
2024-05-25 10:42:21 +08:00
opencolorio = prev.opencolorio.overrideAttrs { doCheck = false; };
redis = prev.redis.overrideAttrs { doCheck = false; };
2024-07-05 09:23:45 +08:00
krita = final.genericPackages.krita;
geos = prev.geos.overrideAttrs { doCheck = false; };
2024-07-23 21:53:46 +08:00
c-blosc = prev.c-blosc.overrideAttrs { doCheck = false; };
2024-07-31 10:55:51 +08:00
binaryen = prev.binaryen.overrideAttrs
{ cmakeFlags = (prev.cmakeFlags or []) ++ [ "-DCMAKE_CXX_FLAGS=-Wno-maybe-uninitialized" ]; };
2024-05-22 10:44:41 +08:00
}
)
2024-05-25 17:57:12 +08:00
// (
inputs.lib.optionalAttrs nixpkgs.cuda.enable
{
waifu2x-converter-cpp = prev.waifu2x-converter-cpp.override
{ stdenv = final.cudaPackages.backendStdenv; };
}
)
)];
};
programs.ccache = { enable = true; cacheDir = "/var/lib/ccache"; };
nix.settings.extra-sandbox-paths = [ inputs.config.programs.ccache.cacheDir ];
2024-07-31 12:55:06 +08:00
boot.kernelPatches = mkIf (nixpkgs.march != null && inputs.config.nixos.system.kernel.variant != "steamos")
[{
name = "native kernel";
patch = null;
extraStructuredConfig =
let
kernelConfig =
{
alderlake = "MALDERLAKE";
sandybridge = "MSANDYBRIDGE";
silvermont = "MSILVERMONT";
broadwell = "MBROADWELL";
skylake = "MSKYLAKE";
znver2 = "MZEN2";
znver3 = "MZEN3";
znver4 = "MZEN4";
};
in { GENERIC_CPU = inputs.lib.kernel.no; ${kernelConfig.${nixpkgs.march}} = inputs.lib.kernel.yes; };
}];
};
2023-09-02 21:21:29 +08:00
}