nixos-config/modules/nix.nix
Simon Bruder 360f7de65d
nix: Update global nixpkgs definition
Nixpkgs 24.05 now sets a registry entry and NIX_PATH by default.
2024-06-02 14:35:22 +02:00

75 lines
2 KiB
Nix

# SPDX-FileCopyrightText: 2020-2024 Simon Bruder <simon@sbruder.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
{ config, inputs, lib, pkgs, ... }:
let
# Adapted from https://nixos.wiki/wiki/Overlays
overlaysCompat = pkgs.writeTextFile {
name = "overlays-compat";
destination = "/overlays.nix";
text = /* nix */ ''
self: super:
with super.lib;
let
# Load the system config and get the `nixpkgs.overlays` option
# This fails gracefully if getFlake is not available
overlays = if (builtins.hasAttr "getFlake" builtins && builtins.pathExists "/var/src/config")
then (builtins.getFlake "/var/src/config").nixosConfigurations.${config.networking.hostName}.config.nixpkgs.overlays
else [ ];
in
# Apply all overlays to the input of the current "main" overlay
foldl' (flip extends) (_: super) overlays self
'';
};
in
{
nix = {
channel.enable = false;
registry = with inputs; {
nixpkgs-unstable.flake = nixpkgs-unstable;
};
nixPath = [
"nixpkgs-overlays=${overlaysCompat}"
"nixpkgs-unstable=flake:nixpkgs-unstable"
];
settings = {
# Make sudoers trusted nix users
trusted-users = [ "@wheel" ];
# On-the-fly optimisation of nix store
auto-optimise-store = true;
experimental-features = "nix-command flakes";
} // (lib.optionalAttrs config.sbruder.full {
# Keep output of derivations with gc root
keep-outputs = true;
keep-derivations = true;
});
# Make nix build in background less noticeable
daemonCPUSchedPolicy = "batch";
daemonIOSchedPriority = 5; # 0-7
};
nixpkgs.overlays = with inputs; [
self.overlays.default
nixpkgs-overlay.overlays.default
(final: prev: {
unstable = import nixpkgs-unstable {
inherit (config.nixpkgs)
config
overlays
system;
};
})
];
environment.systemPackages = with pkgs; [
cached-nix-shell
];
}