let
  inputs = import ./inputs.nix;
  inherit (inputs) nixpkgs;
  inherit (nixpkgs) lib;
  recursivelyImport = import ./recursively-import.nix { inherit lib; };
in
{
  systems =
    definitions:
    lib.mapAttrs (
      name: info:
      lib.nixosSystem {
        specialArgs = {
          inherit inputs;
          inherit (info) system;
          localPkgs = lib.packagesFromDirectoryRecursive {
            inherit (inputs.nixpkgs.legacyPackages.${info.system}) callPackage;
            directory = ../pkgs;
          };
          scope = import ./scope.nix { inherit lib; };
          mainUser = info.username;
          machineName = name;
          getPkgs = builtins.attrValues;
          getFlakePkg = p: p.packages.${info.system}.default;
          getFlakePkg' = p: n: p.packages.${info.system}.${n};
        };
        modules = [
          inputs.arbys.nixosModules.arbys
          inputs.hjem.nixosModules.hjem
          (
            { scope, ... }:
            scope "hjem" {
              users.${info.username}.enable = true;
              extraModules = [
                inputs.hjem-rum.hjemModules.hjem-rum
              ]
              # alias base hjem options to `rum` so we can alias them all together after
              ++ (map (f: lib.mkAliasOptionModule [ "rum" f ] [ f ]) [
                "packages"
                "files"
                "xdg"
                "systemd"
              ]);
            }
          )
          # alias hjem-rum options to `user`
          (lib.mkAliasOptionModule [ "user" ] [ "hjem" "users" info.username "rum" ])
        ]
        ++ (recursivelyImport info.imports);
      }
    ) definitions;
}
