Things you can do but you shouldn't do on NixOS.
Caution
Don't tell anyone.
NixOS Can be Configured with TOML:
# configuration.nix
imports = [
(builtins.fromTOML (builtins.readFile ./config.toml))
]
# config.toml
[boot]
loader.systemd-boot.enable = true
[programs.git]
enable = true
lfs.enable = true
Possible to configure with others e.g. JSON: builtins.fromJSON (builtins.readFile ./config.json);
. See configs directory.
You can add advanced compiler flags to your stdenv
with a configuration like this:
self: super: {
stdenv = super.withCFlags ["-flto" "-funroll-loops" "-O3"] super.stdenv;
}
These flags will be applied to everything built with stdenv
. However, PGO cannot be added to the entire system easily because it requires a different compilation procedure. A version of GCC built with PGO is available in pkgs.fastStdenv
.
To handle packages that fail to build due to these compiler flags, use overrides to replace the inputs of derivations. For example:
self: super: {
stdenv = super.withCFlags ["-flto" "-funroll-loops" "-O3"] super.stdenv;
coreutils = super.coreutils.override {stdenv = super.stdenv;};
}
For PGO, refer to this example. You can also look at the Firefox derivation to see how to implement LTO.
For LTO in the kernel, see this example.
- LTO (Link Time Optimization) does not affect reproducibility but requires recompilation and consumes more resources, especially if you use FatLTO instead of ThinLTO.
- PGO (Profile-Guided Optimization) can affect reproducibility if the profile differs across builds. PGO should not cause reproducibility issues if you store and reuse the profiles used for optimization.
Not all packages in NixOS are built from source; many are unpacked from pre-compiled .deb files. To apply GCC flags globally, refer to system/nix/build-flags.nix
.
For instructions on compiling all packages from source, see system/nix/build-flags.nix
.
Using Ccache system-wide is not possible. However, it might be feasible to specify individual packages that should use the cache, depending on how a derivation is packed. For more information, refer to the unofficial NixOS wiki here.
To enable sccache to use its cache, you need to disable the Nix sandbox. The sandbox restricts filesystem and network access, which interferes with sccache functionality.
Follow this example (source):
{
services.xserver.windowManager.i3.package = pkgs.i3.overrideAttrs (previousAttrs: {
name = "i3-next";
src = pkgs.fetchFromGitHub {
owner = "i3";
repo = "i3";
rev = "90432jkfdkjf92343290842343290dsfiu";
hash = pkgs.lib.fakeHash;
};
});
}
Follow this example (source):
{
environment.systemPackages = [pkgs.myfortune];
nixpkgs.overlays = [
(final: prev: {
myfortune = prev.fortune.overrideAttrs (previousAttrs: {
src = ./fortune-src;
});
})
];
}
Follow this example (source):
{
nixpkgs.overlays = [
(final: prev: {
maven-jdk8 = prev.maven.override {
jdk = final.jdk8;
};
})
];
}
Follow this example (source):
{
nixpkgs.overlays = [
(final: prev: {
openssl = prev.openssl.overrideAttrs (previousAttrs: {
patches = previousAttrs.patches ++ [
(fetchpatch {
name = "CVE-2021-4044.patch";
url = "https://git.openssl.org/gitweb/?p=openssl.git;a=patch;h=758754966791c537ea95241438454aa86f91f256";
hash = pkgs.lib.fakeHash;
})
];
});
})
];
}