base.nix

 1# hosts/common/base.nix
 2# Base system configuration - boot, filesystems, networking
 3{ config, lib, pkgs, ... }:
 4
 5{
 6  # Boot and filesystems are defined in hardware-configuration.nix
 7  # which is imported per-host
 8
 9  # Basic networking
10  networking.useDHCP = lib.mkDefault true;
11  
12  # Enable IPv6 Router Advertisements (required for Hetzner IPv6)
13  # Hetzner uses RAs for IPv6 configuration rather than DHCPv6
14  networking.tempAddresses = "disabled";
15  boot.kernel.sysctl = {
16    "net.ipv6.conf.all.accept_ra" = 1;
17    "net.ipv6.conf.default.accept_ra" = 1;
18  };
19  
20  # Configure dhcpcd for IPv6
21  networking.dhcpcd.extraConfig = ''
22    # Enable IPv6
23    ipv6
24    
25    # Wait for IPv6 Router Advertisements
26    waitip 6
27  '';
28  
29  # Time and locale
30  time.timeZone = lib.mkDefault "UTC";
31  i18n.defaultLocale = lib.mkDefault "en_US.UTF-8";
32
33  # Essential packages
34  environment.systemPackages = with pkgs; [
35    git
36    htop
37    jq
38    lazyjournal
39  ];
40
41  # Enable neovim (system-wide) - plain, no plugins
42  programs.neovim = {
43    enable = true;
44    vimAlias = true;      # Makes 'vim' command run neovim
45    viAlias = true;       # Makes 'vi' command run neovim
46    defaultEditor = true; # Sets $EDITOR to neovim
47  };
48
49  # Enable flakes
50  nix.settings.experimental-features = [ "nix-command" "flakes" ];
51  
52  # Basic system state version
53  system.stateVersion = lib.mkDefault "24.11";
54
55  # Systemd service for Nix garbage collection
56  systemd.services.custom-nix-gc = {
57    description = "Nix garbage collection - remove generations older than 14 days";
58    serviceConfig = {
59      Type = "oneshot";
60      ExecStart = "${pkgs.nix}/bin/nix-collect-garbage --delete-older-than 14d";
61      User = "root";
62    };
63  };
64
65  # Systemd timer - run weekly on Sundays at 3:00 AM
66  systemd.timers.custom-nix-gc = {
67    description = "Nix garbage collection timer (weekly)";
68    wantedBy = [ "timers.target" ];
69    timerConfig = {
70      OnCalendar = "Sun *-*-* 03:00:00";
71      Persistent = true;
72    };
73  };
74}