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;
|
2024-02-24 15:58:48 +08:00
|
|
|
in
|
|
|
|
{
|
|
|
|
nixpkgs =
|
|
|
|
let
|
|
|
|
permittedInsecurePackages =
|
|
|
|
[ "openssl_1_1" "electron_19" "python2" "electron_12" "electron_24" "zotero" "electron_25" ];
|
|
|
|
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";
|
2024-02-24 15:58:48 +08:00
|
|
|
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-02-24 15:58:48 +08:00
|
|
|
permittedInsecurePackages = map
|
|
|
|
(package: inputs.pkgs.${package}.name)
|
|
|
|
(filter (package: inputs.pkgs ? ${package}) 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;
|
2024-03-12 15:27:58 +08:00
|
|
|
nvhpcArch = nixpkgs.march;
|
2024-03-12 15:16:54 +08:00
|
|
|
});
|
2024-02-24 15:58:48 +08:00
|
|
|
overlays =
|
|
|
|
[(final: prev:
|
|
|
|
let
|
2024-03-25 16:55:13 +08:00
|
|
|
inherit (final) system;
|
2024-02-24 15:58:48 +08:00
|
|
|
genericPackages = import inputs.topInputs.nixpkgs
|
|
|
|
{
|
2024-03-25 16:55:13 +08:00
|
|
|
inherit system;
|
2024-02-24 15:58:48 +08:00
|
|
|
config =
|
|
|
|
{
|
|
|
|
allowUnfree = true;
|
2024-03-25 16:55:13 +08:00
|
|
|
permittedInsecurePackages = let pkgs = inputs.topInputs.nixpkgs.legacyPackages.${system}; in map
|
2024-02-24 15:58:48 +08:00
|
|
|
(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-03-03 19:15:04 +08:00
|
|
|
unstablePackages = "nixpkgs-unstable";
|
|
|
|
"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-03-03 19:15:04 +08:00
|
|
|
packages = name: import inputs.topInputs.${source.${name}}
|
|
|
|
{
|
|
|
|
localSystem = hostPlatform;
|
|
|
|
config = cudaConfig //
|
|
|
|
{
|
|
|
|
allowUnfree = true;
|
|
|
|
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)
|
|
|
|
(filter (package: pkgs ? ${package}) permittedInsecurePackages);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in builtins.listToAttrs (map
|
|
|
|
(name: { inherit name; value = packages name; }) (builtins.attrNames source))
|
|
|
|
)
|
2024-02-24 15:58:48 +08:00
|
|
|
// (inputs.lib.optionalAttrs (nixpkgs.march != null)
|
|
|
|
{ embree = prev.embree.override { stdenv = final.genericPackages.stdenv; }; })
|
|
|
|
)];
|
|
|
|
};
|
|
|
|
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";
|
|
|
|
skylake = "MSKYLAKE";
|
|
|
|
znver2 = "MZEN2";
|
|
|
|
znver3 = "MZEN3";
|
|
|
|
znver4 = "MZEN4";
|
|
|
|
};
|
|
|
|
in { GENERIC_CPU = inputs.lib.kernel.no; ${kernelConfig.${nixpkgs.march}} = inputs.lib.kernel.yes; };
|
|
|
|
}];
|
|
|
|
environment.systemPackages = mkIf nixpkgs.cuda.enable [ inputs.pkgs.cudatoolkit ];
|
|
|
|
};
|
2023-09-02 21:21:29 +08:00
|
|
|
}
|