main
  1{
  2  config,
  3  desktop,
  4  globals,
  5  hostname,
  6  inputs,
  7  lib,
  8  libx,
  9  outputs,
 10  stateVersion,
 11  ...
 12}:
 13{
 14
 15  imports = [
 16    (./. + "/${hostname}/boot.nix")
 17    (./. + "/${hostname}/hardware.nix")
 18
 19    ./common/base
 20    ./common/users
 21  ]
 22  ++ lib.optional (builtins.pathExists (./. + "/${hostname}/extra.nix")) ./${hostname}/extra.nix
 23  ++ lib.optional (builtins.isString desktop) ./common/desktop
 24  ++ lib.optional (
 25    builtins.hasAttr "${hostname}" globals.machines
 26    && libx.hasSyncthingFolders globals.machines."${hostname}"
 27  ) ./common/services/syncthing.nix;
 28
 29  nixpkgs = {
 30    overlays = [
 31      # Our own flake exports (from overlays and pkgs dir)
 32      outputs.overlays.additions
 33      outputs.overlays.modifications
 34      outputs.overlays.unstable-packages
 35
 36      # And from other flakes
 37      inputs.emacs-overlay.overlay
 38      outputs.overlays.emacs-31
 39      inputs.chapeau-rouge.overlays.openshift
 40      inputs.chick-group.overlays.default
 41      inputs.go-org-readwise.overlays.default
 42      inputs.radian.overlays.default
 43      inputs.agenix.overlays.default
 44      inputs.nix-cachyos-kernel.overlays.default
 45      inputs.llm-agents.overlays.shared-nixpkgs
 46
 47      # Migrate to "modifications"
 48      (_: prev: {
 49        inherit (inputs.buildkit-tekton.packages.${prev.stdenv.hostPlatform.system}) tkn-local;
 50        inherit (inputs.pass-run.packages.${prev.stdenv.hostPlatform.system}) pass-run;
 51      })
 52    ];
 53    config = {
 54      allowUnfree = true;
 55      # Workaround for https://github.com/nix-community/home-manager/issues/2942
 56      allowUnfreePredicate = _: true;
 57    };
 58  };
 59
 60  nix = {
 61    # This will add each flake input as a registry
 62    # To make nix3 commands consistent with your flake
 63    registry = lib.mkForce (lib.mapAttrs (_: value: { flake = value; }) inputs);
 64
 65    # This will additionally add your inputs to the system's legacy channels
 66    # Making legacy nix commands consistent as well, awesome!
 67    nixPath = lib.mkForce (
 68      lib.mapAttrsToList (key: value: "${key}=${value.to.path}") config.nix.registry
 69    );
 70
 71    optimise = {
 72      automatic = true;
 73      dates = [
 74        "01:10"
 75        "12:10"
 76      ];
 77    };
 78
 79    settings = {
 80      auto-optimise-store = true;
 81      experimental-features = [
 82        "nix-command"
 83        "flakes"
 84      ];
 85      sandbox = true;
 86      allowed-users = [
 87        "@wheel"
 88      ];
 89      trusted-users = [
 90        "root"
 91        "@wheel"
 92      ];
 93      # See https://nixos.org/manual/nix/stable/command-ref/conf-file#conf-use-xdg-base-directories
 94      use-xdg-base-directories = true;
 95
 96      # Add some "caches" (substituters)
 97      substituters = [
 98        "https://cache.nixos.org/"
 99        "https://r-ryantm.cachix.org"
100        "https://shortbrain.cachix.org"
101        "https://vdemeester.cachix.org"
102        "https://chapeau-rouge.cachix.org"
103        "https://nixos-raspberrypi.cachix.org"
104        # Local Harmonia binary caches
105        "http://okinawa.sbr.pm:5000" # x86_64-linux
106        "http://aion.sbr.pm:5000" # aarch64-linux
107      ];
108      trusted-public-keys = [
109        "r-ryantm.cachix.org-1:gkUbLkouDAyvBdpBX0JOdIiD2/DP1ldF3Z3Y6Gqcc4c="
110        "shortbrain.cachix.org-1:dqXcXzM0yXs3eo9ChmMfmob93eemwNyhTx7wCR4IjeQ="
111        "chapeau-rouge.cachix.org-1:r34IG766Ez4Eeanr7Zx+egzXLE2Zgvc+XRspYZPDAn8="
112        "vdemeester.cachix.org-1:eZWNOrLR9A9szeMahn9ENaoT9DB3WgOos8va+d2CU44="
113        "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI="
114        # Local Harmonia cache public keys
115        "cache.okinawa.home:gp+IG0OaO4L/J0drL8OwmDtMPmdUq4kfLwg3mR8BkCs="
116        "cache.aion.home-1:VIbchtAJWf8+T46viAsLaQYDhG9KUGVo+vWxH1Tlz94="
117      ];
118    };
119
120    extraOptions = ''
121      connect-timeout = 20
122      build-cores = 0
123      keep-outputs = true
124      keep-derivations = true
125      builders-use-substitutes = true
126    '';
127
128    # On laptops at least, make the daemon and builders low priority
129    # to have a responding system while building
130    daemonIOSchedClass = "idle";
131    daemonCPUSchedPolicy = "idle";
132  };
133
134  # `nix-daemon` will hit the stack limit when using `nixFlakes`.
135  systemd.services.nix-daemon.serviceConfig."LimitSTACK" = "infinity";
136
137  system = {
138    inherit stateVersion;
139  };
140
141}