{ inputs, self, withSystem, ... }: let inherit (inputs.nixpkgs.lib // builtins) filterAttrs foldl' makeOverridable mapAttrs' mapAttrsToList mkForce mkIf nixosSystem readDir substring ; inherit (inputs.darwin.lib) darwinSystem; nixSettings = { nix.registry.nixpkgs = { flake = inputs.nixpkgs; }; }; mapSystems = dir: mapAttrsToList (name: _: name) (filterAttrs (_: type: type == "directory") (readDir dir)); mapHosts = foldl' ( hosts: system: hosts // (mapAttrs' (name: _: { inherit name; value = { inherit system; hostconf = "${self}/machines/nixos/${system}/${name}"; }; }) (builtins.readDir "${self}/machines/nixos/${system}")) ) { }; mapMacs = foldl' ( hosts: system: hosts // (mapAttrs' (name: _: { inherit name; value = { inherit system; hostconf = "${self}/machines/darwin/${system}/${name}"; }; }) (builtins.readDir "${self}/machines/darwin/${system}")) ) { }; defaultModules = [ nixSettings inputs.agenix.nixosModules.age inputs.disko.nixosModules.disko inputs.home-manager.nixosModules.home-manager "${self}/modules/common" "${self}/modules/nixos" "${self}/modules/nas-client.nix" "${self}/modules/backups.nix" ]; darwinDefaultModules = [ nixSettings inputs.agenix.darwinModules.age inputs.home-manager.darwinModules.home-manager "${self}/modules/common" ]; darwinConfigurations = mapAttrs' ( name: conf: let inherit (conf) system hostconf; adminUser = { name = "fcuny"; userinfo = { email = "franck@fcuny.net"; fullName = "Franck Cuny"; }; }; in { inherit name; value = withSystem system ( { pkgs, ... }: makeOverridable darwinSystem { inherit system; specialArgs = { hostName = name; inherit adminUser; inherit self; inherit inputs; }; modules = [ { inherit adminUser; } { nixpkgs.pkgs = pkgs; nixpkgs.hostPlatform = system; system.stateVersion = 5; environment.systemPackages = [ pkgs.git ]; } ] ++ darwinDefaultModules ++ [ hostconf ]; } ); } ) (mapMacs (mapSystems "${self}/machines/darwin")); nixosConfigurations = mapAttrs' ( name: conf: let inherit (conf) system hostconf; adminUser = { name = "fcuny"; uid = 1000; userinfo = { email = "franck@fcuny.net"; fullName = "Franck Cuny"; }; }; in { inherit name; value = withSystem system ( { pkgs, ... }: makeOverridable nixosSystem { inherit system; specialArgs = { hostName = name; inherit adminUser; inherit self; hostConfigurations = mapAttrs' (name: conf: { inherit name; value = conf.config; }) nixosConfigurations; inherit inputs; }; modules = [ { inherit adminUser; } { system.configurationRevision = mkIf (self ? rev) self.rev; system.nixos.versionSuffix = mkForce "git.${substring 0 11 inputs.nixpkgs.rev}"; nixpkgs.pkgs = pkgs; environment.systemPackages = [ pkgs.git ]; } { home-manager.users.${adminUser.name}.imports = [ "${self}/home/programs/bat.nix" ]; } ] ++ defaultModules ++ [ hostconf inputs.my-go-tools.nixosModules.default ]; } ); } ) (mapHosts (mapSystems "${self}/machines/nixos")); adminUser = { name = "fcuny"; uid = 1000; userinfo = { email = "franck@fcuny.net"; fullName = "Franck Cuny"; }; }; in { flake = { inherit nixosConfigurations darwinConfigurations; colmenaHive = inputs.colmena.lib.makeHive self.outputs.colmena; colmena = { meta = { nixpkgs = import inputs.nixpkgs { system = "x86_64-linux"; overlays = [ inputs.agenix.overlays.default inputs.my-go-tools.overlays.default ]; }; specialArgs = { inherit inputs self; adminUser = adminUser; }; }; defaults = { ... }: { imports = defaultModules ++ [ inputs.my-go-tools.nixosModules.default inputs.home-manager.nixosModules.home-manager { home-manager.users.${adminUser.name}.imports = [ "${self}/home/programs/bat.nix" { home.stateVersion = "25.05"; } ]; } ]; }; do-rproxy = { name, ... }: { imports = [ ../machines/nixos/x86_64-linux/${name} ]; deployment = { tags = [ "droplet" ]; targetHost = "fcuny.net"; targetUser = "fcuny"; buildOnTarget = true; allowLocalDeployment = false; }; }; synology-vm = { name, ... }: { imports = [ ../machines/nixos/x86_64-linux/${name} ]; deployment = { tags = [ "vm" ]; targetHost = "vm-synology"; targetUser = "fcuny"; buildOnTarget = true; allowLocalDeployment = false; }; }; rivendell = { name, ... }: { imports = [ ../machines/nixos/x86_64-linux/${name} ]; deployment = { tags = [ "bm" ]; targetHost = "rivendell"; targetUser = "fcuny"; buildOnTarget = true; allowLocalDeployment = false; }; }; }; }; }