1
0
Fork 0
nix-configuration/modules/system/nix.nix

84 lines
2.5 KiB
Nix
Raw Normal View History

# Core Nix configuration
{
config,
inputs,
lib,
pkgs,
...
}:
let
cfg = config.aux.system;
nixos-operations-script = pkgs.writeShellScriptBin "nixos-operations-script" (
builtins.readFile ../../bin/nixos-operations-script.sh
);
in
{
options = {
2024-09-08 11:58:56 -04:00
aux.system = {
allowUnfree = lib.mkEnableOption "Allow unfree packages to install.";
retentionPeriod = lib.mkOption {
description = "How long to retain NixOS generations. Defaults to one month.";
type = lib.types.str;
default = "monthly";
};
nixos-operations-script.enable = lib.mkEnableOption "Installs the nos (nixos-operations-script) helper script.";
};
};
2024-09-29 16:06:16 -04:00
config = lib.mkMerge [
{
nixpkgs.config.allowUnfree = cfg.allowUnfree;
nix = {
settings = {
# Enable Flakes
experimental-features = [
"nix-command"
"flakes"
];
2024-09-29 16:06:16 -04:00
# Use Lix instead of Nix
substituters = [ "https://cache.lix.systems" ];
trusted-public-keys = [ "cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o=" ];
2024-09-29 16:06:16 -04:00
# Only allow these users to use Nix
allowed-users = with config.users.users; [
root.name
(lib.mkIf config.aux.system.users.aires.enable aires.name)
2024-09-30 11:44:07 -04:00
(lib.mkIf config.aux.system.users.gremlin.enable gremlin.name)
2024-09-29 16:06:16 -04:00
];
2024-09-29 16:06:16 -04:00
# Avoid signature verification messages when doing remote builds
trusted-users = with config.users.users; [
root.name
(lib.mkIf config.aux.system.users.aires.enable aires.name)
];
};
2024-09-29 16:06:16 -04:00
# Optimize the Nix store on each build
settings.auto-optimise-store = true;
# Enable garbage collection
gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than ${cfg.retentionPeriod}";
persistent = true;
randomizedDelaySec = "1hour";
};
2024-09-29 16:06:16 -04:00
# Configure NixOS to use the same software channel as Flakes
registry.nixpkgs.flake = inputs.nixpkgs;
nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
};
2024-09-29 16:06:16 -04:00
# Support for standard, dynamically-linked executables
programs.nix-ld.enable = true;
}
(lib.mkIf cfg.nixos-operations-script.enable {
2024-09-29 16:06:16 -04:00
# Enable and configure NOS
aux.system.packages = [ nixos-operations-script ];
2024-09-29 16:06:16 -04:00
environment.variables."FLAKE_DIR" = config.secrets.nixConfigFolder;
})
];
}