2024-08-08 19:21:52 +02:00
|
|
|
# credits to raf
|
2024-08-22 20:56:58 +02:00
|
|
|
{
|
2025-07-19 21:51:37 +02:00
|
|
|
sources,
|
2024-09-20 22:57:03 +02:00
|
|
|
lib,
|
2024-08-22 20:56:58 +02:00
|
|
|
pkgs,
|
|
|
|
...
|
2025-07-20 01:23:48 +02:00
|
|
|
}:
|
|
|
|
let
|
2025-04-09 15:31:18 +02:00
|
|
|
inherit (lib.modules) mkForce;
|
2025-07-21 00:06:54 +02:00
|
|
|
|
|
|
|
lix = pkgs.callPackage "${sources.lix}/package.nix" {
|
|
|
|
stdenv = pkgs.clangStdenv;
|
|
|
|
};
|
2025-07-20 01:23:48 +02:00
|
|
|
in
|
|
|
|
{
|
2024-07-23 00:00:26 +02:00
|
|
|
nix = {
|
2025-07-21 00:06:54 +02:00
|
|
|
package = lix;
|
2025-06-29 17:00:57 +02:00
|
|
|
# Check that Nix can parse the generated nix.conf.
|
|
|
|
checkConfig = true;
|
|
|
|
|
|
|
|
# Check the nix.conf, parsing for any kind of error. When disabled, checks only for unknown settings.
|
|
|
|
checkAllErrors = true;
|
2024-07-24 17:47:16 +02:00
|
|
|
|
2024-09-22 01:47:19 +02:00
|
|
|
# fuck channels, no thanks
|
|
|
|
channel.enable = mkForce false;
|
|
|
|
|
2024-09-22 02:03:18 +02:00
|
|
|
# this is taken from sioodmy.
|
|
|
|
# pin the registry to avoid downloading and evaling a new nixpkgs version every time
|
2025-07-19 21:51:37 +02:00
|
|
|
# registry =
|
|
|
|
# lib.mapAttrs (_: v: {flake = v.outPath;}) sources
|
|
|
|
# // {system.flake = sources.nichts;};
|
2025-07-21 00:06:54 +02:00
|
|
|
registry.nixpkgs.to = {
|
|
|
|
type = "path";
|
|
|
|
source = sources.nixpkgs;
|
|
|
|
};
|
2024-09-22 02:03:18 +02:00
|
|
|
|
2025-04-09 15:31:18 +02:00
|
|
|
# Add inputs to the system's legacy channels
|
|
|
|
# to make legacy nix commands consistent as well
|
2025-07-21 00:06:54 +02:00
|
|
|
nixPath = [ "nixpkgs=/etc/nixos/nixpkgs" ];
|
2024-09-20 22:57:03 +02:00
|
|
|
|
2025-04-09 15:31:18 +02:00
|
|
|
# Run the Nix daemon on lowest possible priority
|
2024-07-24 17:47:16 +02:00
|
|
|
daemonCPUSchedPolicy = "idle";
|
|
|
|
daemonIOSchedClass = "idle";
|
|
|
|
daemonIOSchedPriority = 7;
|
|
|
|
|
|
|
|
# Collect garbage
|
2025-04-09 15:31:18 +02:00
|
|
|
# NOTE: I use nh for this.
|
2024-07-24 17:47:16 +02:00
|
|
|
gc = {
|
2024-08-13 11:48:37 +02:00
|
|
|
automatic = false;
|
2024-07-24 17:47:16 +02:00
|
|
|
dates = "20:00";
|
|
|
|
options = "--delete-older-than 7d";
|
2025-04-09 15:31:18 +02:00
|
|
|
persistent = false;
|
2024-07-24 17:47:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
# Automatically optimize nix store by removing hard links
|
|
|
|
optimise = {
|
|
|
|
automatic = true;
|
2025-07-20 01:23:48 +02:00
|
|
|
dates = [ "21:00" ];
|
2024-07-24 17:47:16 +02:00
|
|
|
};
|
|
|
|
|
2025-06-02 17:18:22 +02:00
|
|
|
# NOTE:
|
|
|
|
# Writes the settings to /etc/nix/nix.conf.
|
|
|
|
# See `man nix.conf` for more detailed descriptions of these settings.
|
2024-07-23 00:00:26 +02:00
|
|
|
settings = {
|
|
|
|
# Tell nix to use the xdg spec for base directories
|
|
|
|
# while transitioning, any state must be carried over
|
|
|
|
# manually, as Nix won't do it for us.
|
2024-07-24 17:47:16 +02:00
|
|
|
use-xdg-base-directories = true;
|
|
|
|
|
|
|
|
# Automatically optimise symlinks
|
|
|
|
auto-optimise-store = true;
|
|
|
|
|
2025-06-29 17:00:57 +02:00
|
|
|
# Users that are allowed to connect to the Nix daemon.
|
2025-07-20 01:23:48 +02:00
|
|
|
allowed-users = [
|
|
|
|
"root"
|
|
|
|
"@wheel"
|
|
|
|
"nix-builder"
|
|
|
|
];
|
2024-07-24 17:47:16 +02:00
|
|
|
|
2025-06-29 17:00:57 +02:00
|
|
|
# Users that are allowed to connect to the Nix daemon.
|
2025-07-20 01:23:48 +02:00
|
|
|
trusted-users = [
|
|
|
|
"root"
|
|
|
|
"@wheel"
|
|
|
|
"nix-builder"
|
|
|
|
];
|
2024-07-24 17:47:16 +02:00
|
|
|
|
|
|
|
# Let the system decide the number of max jobs
|
|
|
|
# based on available system specs. Usually this is
|
|
|
|
# the same as the number of cores your CPU has.
|
2025-06-02 17:18:22 +02:00
|
|
|
max-jobs = "auto";
|
|
|
|
|
|
|
|
# This option defines the maximum number of concurrent tasks during one build.
|
|
|
|
# It affects, e.g., -j option for make. The special value 0 means that the builder
|
|
|
|
# should use all available CPU cores in the system. Some builds may become
|
|
|
|
# non-deterministic with this option; use with care!
|
|
|
|
# Packages will only be affected if enableParallelBuilding is set for them.
|
|
|
|
cores = 0;
|
2024-07-24 17:47:16 +02:00
|
|
|
|
2024-08-16 13:32:13 +02:00
|
|
|
# If set, Nix will perform builds in a sandboxed environment
|
|
|
|
# that it will set up automatically for each build.
|
|
|
|
# This prevents impurities in builds by disallowing access
|
|
|
|
# to dependencies outside of the Nix store by using network
|
|
|
|
# and mount namespaces in a chroot environment.
|
2024-07-24 17:47:16 +02:00
|
|
|
sandbox = true;
|
2024-09-20 22:57:03 +02:00
|
|
|
sandbox-fallback = false;
|
2024-07-24 17:47:16 +02:00
|
|
|
|
|
|
|
# Continue building derivations even if one fails
|
|
|
|
keep-going = true;
|
|
|
|
|
|
|
|
# If we haven't received data for >= 20s, retry the download
|
|
|
|
stalled-download-timeout = 20;
|
|
|
|
|
|
|
|
# Show more logs when a build fails and decides to display
|
|
|
|
# a bunch of lines. `nix log` would normally provide more
|
|
|
|
# information, but this may save us some time and keystrokes.
|
|
|
|
log-lines = 30;
|
|
|
|
|
|
|
|
# Extra features of Nix that are considered unstable
|
|
|
|
# and experimental. By default we should always include
|
|
|
|
# `flakes` and `nix-command`, while others are usually
|
2024-07-23 00:00:26 +02:00
|
|
|
# optional.
|
|
|
|
extra-experimental-features = [
|
|
|
|
"flakes" # flakes
|
|
|
|
"nix-command" # experimental nix commands
|
|
|
|
"cgroups" # allow nix to execute builds inside cgroups
|
2025-07-21 00:06:54 +02:00
|
|
|
"pipe-operator"
|
2024-07-23 00:00:26 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
# Ensures that the result of Nix expressions is fully determined by
|
2024-07-24 17:47:16 +02:00
|
|
|
# explicitly declared inputs, and not influenced by external state.
|
|
|
|
# In other words, fully stateless evaluation by Nix at all times.
|
2024-09-20 22:57:03 +02:00
|
|
|
pure-eval = false;
|
2024-07-24 17:47:16 +02:00
|
|
|
|
|
|
|
# Don't warn me that my git tree is dirty, I know.
|
|
|
|
warn-dirty = false;
|
|
|
|
|
|
|
|
# Maximum number of parallel TCP connections
|
|
|
|
# used to fetch imports and binary caches.
|
|
|
|
# 0 means no limit, default is 25.
|
|
|
|
http-connections = 50; # lower values fare better on slow connections
|
|
|
|
|
|
|
|
# Whether to accept nix configuration from a flake
|
|
|
|
# without displaying a Y/N prompt. For those obtuse
|
|
|
|
# enough to keep this true, I wish the best of luck.
|
|
|
|
# tl;dr: this is a security vulnerability.
|
|
|
|
accept-flake-config = false;
|
|
|
|
|
|
|
|
# Whether to execute builds inside cgroups. cgroups are
|
|
|
|
# "a Linux kernel feature that limits, accounts for, and
|
|
|
|
# isolates the resource usage (CPU, memory, disk I/O, etc.)
|
|
|
|
# of a collection of processes."
|
|
|
|
# See:
|
|
|
|
# <https://en.wikipedia.org/wiki/Cgroups>
|
|
|
|
use-cgroups = pkgs.stdenv.isLinux; # only supported on Linux
|
|
|
|
|
|
|
|
# for direnv GC roots
|
|
|
|
keep-derivations = true;
|
|
|
|
keep-outputs = true;
|
|
|
|
|
2025-04-09 15:31:18 +02:00
|
|
|
# Use binary cache
|
2024-07-24 17:47:16 +02:00
|
|
|
builders-use-substitutes = true;
|
2024-07-23 00:00:26 +02:00
|
|
|
|
2024-08-16 13:32:13 +02:00
|
|
|
# Substituters to pull from.
|
2024-07-23 00:00:26 +02:00
|
|
|
substituters = [
|
2025-04-09 15:31:18 +02:00
|
|
|
"https://cache.nixos.org"
|
2024-07-23 00:00:26 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
trusted-public-keys = [
|
|
|
|
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
|
|
|
|
];
|
2025-06-29 17:00:57 +02:00
|
|
|
# Determinate nix config
|
|
|
|
# ===========================================
|
2025-07-19 21:51:37 +02:00
|
|
|
# lazy-trees = true;
|
2025-06-29 17:00:57 +02:00
|
|
|
# ===========================================
|
2024-07-23 00:00:26 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2025-07-21 00:06:54 +02:00
|
|
|
environment.etc = {
|
|
|
|
"nixos/nixpkgs".source = builtins.storePath sources.nixpkgs;
|
|
|
|
};
|
2024-09-22 00:19:44 +02:00
|
|
|
systemd.services = {
|
2024-09-22 01:47:19 +02:00
|
|
|
# WE DONT WANT TO BUILD STUFF ON TMPFS
|
|
|
|
# ITS NOT A GOOD IDEA
|
|
|
|
nix-daemon = {
|
|
|
|
environment.TMPDIR = "/var/tmp";
|
|
|
|
};
|
2024-09-22 00:19:44 +02:00
|
|
|
|
2024-09-22 01:47:19 +02:00
|
|
|
# Do not run garbage collection on AC power.
|
2024-09-22 19:20:44 +02:00
|
|
|
# This makes for a quite nice difference in battery life.
|
2024-09-22 01:47:19 +02:00
|
|
|
nix-gc = {
|
|
|
|
unitConfig.ConditionACPower = true;
|
|
|
|
};
|
2024-09-22 00:19:44 +02:00
|
|
|
};
|
2024-07-23 00:00:26 +02:00
|
|
|
}
|