2024-06-24 15:38:28 +00:00
|
|
|
# Core Nix configuration
|
|
|
|
{
|
|
|
|
config,
|
|
|
|
inputs,
|
2024-09-28 04:47:38 +00:00
|
|
|
lib,
|
|
|
|
pkgs,
|
2024-12-06 16:46:10 +00:00
|
|
|
namespace,
|
2024-12-06 17:50:45 +00:00
|
|
|
system,
|
2024-06-24 15:38:28 +00:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-12-06 16:46:10 +00:00
|
|
|
cfg = config.${namespace};
|
2024-09-28 04:47:38 +00:00
|
|
|
|
2024-10-06 16:13:36 +00:00
|
|
|
nixos-operations-script = pkgs.writeShellScriptBin "nixos-operations-script" (
|
2024-12-06 16:16:58 +00:00
|
|
|
builtins.readFile ../../../../bin/nixos-operations-script.sh
|
2024-09-28 04:47:38 +00:00
|
|
|
);
|
2024-06-24 15:38:28 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-12-06 16:46:10 +00:00
|
|
|
${namespace} = {
|
2024-09-08 15:58:56 +00:00
|
|
|
retentionPeriod = lib.mkOption {
|
|
|
|
description = "How long to retain NixOS generations. Defaults to one month.";
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "monthly";
|
|
|
|
};
|
2024-10-06 16:13:36 +00:00
|
|
|
nixos-operations-script.enable = lib.mkEnableOption "Installs the nos (nixos-operations-script) helper script.";
|
2024-06-24 15:38:28 +00:00
|
|
|
};
|
|
|
|
};
|
2024-09-29 20:06:16 +00:00
|
|
|
config = lib.mkMerge [
|
|
|
|
{
|
|
|
|
nix = {
|
2024-12-06 16:46:10 +00:00
|
|
|
# Use Lix in place of Nix
|
2024-12-06 17:50:45 +00:00
|
|
|
package = inputs.lix.packages.${system}.default;
|
2024-12-06 16:46:10 +00:00
|
|
|
|
|
|
|
# Ensure we can still build when secondary caches are unavailable
|
2024-12-02 16:26:29 +00:00
|
|
|
extraOptions = ''
|
|
|
|
fallback = true
|
|
|
|
'';
|
|
|
|
|
2024-09-29 20:06:16 +00:00
|
|
|
settings = {
|
|
|
|
# Enable Flakes
|
|
|
|
experimental-features = [
|
|
|
|
"nix-command"
|
|
|
|
"flakes"
|
|
|
|
];
|
2024-06-24 15:38:28 +00:00
|
|
|
|
2024-12-02 02:01:53 +00:00
|
|
|
# Set up secondary binary caches for Lix and Hevana
|
|
|
|
substituters = [
|
|
|
|
"https://cache.lix.systems"
|
2024-12-02 02:47:41 +00:00
|
|
|
"https://${config.secrets.services.binary-cache.url}"
|
2024-12-02 02:01:53 +00:00
|
|
|
];
|
|
|
|
trusted-public-keys = [
|
|
|
|
"cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o="
|
|
|
|
config.secrets.services.binary-cache.pubcert
|
|
|
|
];
|
2024-06-24 15:38:28 +00:00
|
|
|
|
2024-12-02 16:26:29 +00:00
|
|
|
# Authentication for Hevana's binary cache
|
|
|
|
netrc-file =
|
|
|
|
with config.secrets.services.binary-cache;
|
|
|
|
pkgs.writeText "netrc" ''
|
|
|
|
machine ${url} login ${auth.username} password ${auth.password}
|
|
|
|
'';
|
|
|
|
|
2024-09-29 20:06:16 +00:00
|
|
|
# Only allow these users to use Nix
|
|
|
|
allowed-users = with config.users.users; [
|
|
|
|
root.name
|
2024-12-06 16:46:10 +00:00
|
|
|
(lib.mkIf config.${namespace}.users.aires.enable aires.name)
|
|
|
|
(lib.mkIf config.${namespace}.users.gremlin.enable gremlin.name)
|
2024-09-29 20:06:16 +00:00
|
|
|
];
|
2024-06-24 15:38:28 +00:00
|
|
|
|
2024-09-29 20:06:16 +00:00
|
|
|
# Avoid signature verification messages when doing remote builds
|
|
|
|
trusted-users = with config.users.users; [
|
|
|
|
root.name
|
2024-12-06 16:46:10 +00:00
|
|
|
(lib.mkIf config.${namespace}.users.aires.enable aires.name)
|
2024-09-29 20:06:16 +00:00
|
|
|
];
|
|
|
|
};
|
2024-06-24 15:38:28 +00:00
|
|
|
|
2024-09-29 20:06:16 +00: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-06-24 15:38:28 +00:00
|
|
|
|
2024-09-29 20:06:16 +00:00
|
|
|
# Configure NixOS to use the same software channel as Flakes
|
|
|
|
registry.nixpkgs.flake = inputs.nixpkgs;
|
|
|
|
nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
|
|
|
|
};
|
2024-09-28 04:47:38 +00:00
|
|
|
|
2024-09-29 20:06:16 +00:00
|
|
|
# Support for standard, dynamically-linked executables
|
|
|
|
programs.nix-ld.enable = true;
|
|
|
|
}
|
2024-10-06 16:13:36 +00:00
|
|
|
(lib.mkIf cfg.nixos-operations-script.enable {
|
2024-09-29 20:06:16 +00:00
|
|
|
# Enable and configure NOS
|
2024-12-06 16:46:10 +00:00
|
|
|
${namespace}.packages = [ nixos-operations-script ];
|
2024-09-29 20:06:16 +00:00
|
|
|
environment.variables."FLAKE_DIR" = config.secrets.nixConfigFolder;
|
|
|
|
})
|
|
|
|
];
|
2024-06-24 15:38:28 +00:00
|
|
|
}
|