nixos/modules/system/nix.nix

88 lines
3.0 KiB
Nix
Raw Normal View History

2023-09-02 14:04:03 +08:00
inputs:
{
options.nixos.system.nix = let inherit (inputs.lib) mkOption types; in
{
2023-09-02 14:21:27 +08:00
# marches allowed to be compiled on this machine
2023-09-02 14:04:03 +08:00
marches = mkOption { type = types.nullOr (types.listOf types.nonEmptyStr); default = null; };
2024-02-04 11:13:34 +08:00
includeBuildDependencies = mkOption { type = types.bool; default = inputs.topInputs.self.config.archive; };
2023-09-02 14:04:03 +08:00
substituters = mkOption { type = types.nullOr (types.listOf types.nonEmptyStr); default = null; };
autoOptimiseStore = mkOption { type = types.bool; default = false; };
2023-09-02 14:04:03 +08:00
};
2024-02-01 10:55:47 +08:00
config = let inherit (inputs.config.nixos.system) nix; in inputs.lib.mkMerge
[
# general nix config
{
nix.settings =
2023-09-02 14:04:03 +08:00
{
2024-02-01 10:55:47 +08:00
system-features = [ "big-parallel" "nixos-test" "benchmark" ];
experimental-features = [ "nix-command" "flakes" ];
keep-failed = true;
max-substitution-jobs = 4;
2024-02-01 10:55:47 +08:00
trusted-public-keys = [ "chn:Cc+nowW1LIpe1kyXOZmNaznFDiH1glXmpb4A+WD/DTE=" ];
show-trace = true;
max-jobs = 4;
2024-02-01 10:55:47 +08:00
cores = 0;
keep-going = true;
2024-02-27 11:19:29 +08:00
keep-outputs = true;
2024-02-01 10:55:47 +08:00
};
systemd.services.nix-daemon = { serviceConfig.CacheDirectory = "nix"; environment.TMPDIR = "/var/cache/nix"; };
}
# nix daemon use lower io/cpu priority
{
nix = { daemonIOSchedClass = "idle"; daemonCPUSchedPolicy = "idle"; };
systemd.services.nix-daemon.serviceConfig = { Slice = "-.slice"; Nice = "19"; };
}
# nix channel & nix flake registry
{
nix =
{
registry =
2023-09-02 14:04:03 +08:00
{
2024-02-01 10:55:47 +08:00
nixpkgs.flake = inputs.topInputs.nixpkgs;
nixpkgs-unstable.flake = inputs.topInputs.nixpkgs-unstable;
nixos.flake = inputs.topInputs.self;
2023-09-02 14:04:03 +08:00
};
2024-02-01 10:55:47 +08:00
nixPath = [ "nixpkgs=${inputs.topInputs.nixpkgs}" ];
};
environment =
{
etc =
2023-09-02 14:04:03 +08:00
{
2024-02-01 10:55:47 +08:00
"channels/nixpkgs".source = inputs.topInputs.nixpkgs.outPath;
"channels/nixpkgs-unstable".source = inputs.topInputs.nixpkgs-unstable.outPath;
"nixos".source = inputs.topInputs.self.outPath;
2023-09-02 14:04:03 +08:00
};
2024-02-01 10:55:47 +08:00
variables.COMMA_NIXPKGS_FLAKE = "nixpkgs-unstable";
2023-09-02 14:04:03 +08:00
};
2024-02-01 10:55:47 +08:00
}
# marches
{
nix.settings.system-features =
(map
2024-02-01 10:55:47 +08:00
(march: "gccarch-${march}")
(
if nix.marches == null then
(with inputs.config.nixos.system.nixpkgs; if march == null then [] else [ march ])
else nix.marches
))
2024-02-27 12:56:43 +08:00
++ (with inputs.config.nixos.system.nixpkgs; if march == null then [] else [ "nvhpcarch-${march}" ]);
2024-02-01 10:55:47 +08:00
}
# includeBuildDependencies
{
system.includeBuildDependencies = nix.includeBuildDependencies;
}
# substituters
{
nix.settings.substituters = if nix.substituters == null then [ "https://cache.nixos.org/" ] else nix.substituters;
}
# autoOptimiseStore
{
nix.settings.auto-optimise-store = nix.autoOptimiseStore;
}
# c++ include path
# environment.pathsToLink = [ "/include" ];
# environment.variables.CPATH = "/run/current-system/sw/include";
# environment.variables.LIBRARY_PATH = "/run/current-system/sw/lib";
];
2023-09-02 14:04:03 +08:00
}