{ description = "NixOS Machine Configurations by manuth"; inputs = { nixpkgs.url = "nixpkgs/38c01297e7ec11f7b9e3f2cae7d6fcec6cc767ec"; flake-utils.url = "github:numtide/flake-utils?ref=b1d9ab70662946ef0850d488da1c9019f3a9752a"; sops-nix.url = "github:Mic92/sops-nix?ref=f1b0adc27265274e3b0c9b872a8f476a098679bd"; }; outputs = { self, nixpkgs, flake-utils, sops-nix }: ( let inherit (nixpkgs) lib; defaultMachine = { system = "x86_64-linux"; config = { pkgs, ... }: { dualBoot = false; timeZone = null; keyMap = "us"; keyboardLayout = "us"; localeSettings = { }; users = { }; }; }; machines = { nixos.config = { ... }: { }; }; systems = builtins.mapAttrs (name: value: defaultMachine // value) machines; tryFiles = import ./lib/utils/try-files.nix { inherit lib; }; in flake-utils.lib.eachDefaultSystem ( system: let pkgs = import nixpkgs { inherit system; config = {}; overlays = [ sops-nix.overlays.default ]; }; in { devShells.default = pkgs.mkShellNoCC ( with pkgs; { sopsPGPKeyDirs = [ "${toString ./.}/keys/hosts" "${toString ./.}/keys/users" ]; packages = [ nixos-rebuild sops sops-import-keys-hook ssh-to-age ssh-to-pgp ]; nativeBuildInputs = [ sops-import-keys-hook ]; }); } ) // { nixosConfigurations = builtins.mapAttrs ( name: { system, config }: nixpkgs.lib.nixosSystem { inherit system; modules = [ ( { pkgs, ... }@args: { config._module.args = { hostname = name; machineConfig = (defaultMachine.config args) // (config args) // { inherit name; }; }; }) sops-nix.nixosModules.sops ./lib/configuration.nix (tryFiles [ ./lib/machines/${name}.nix ] ./lib/hardware/base.nix) ]; }) systems; homeConfigurations = let lib = nixpkgs.lib; in lib.attrsets.concatMapAttrs ( hostname: machineDeclaration: let machine = machineDeclaration // defaultMachine // { config = { ... }@args: ( (defaultMachine.config args) // (machineDeclaration.config args)); }; pkgs = import nixpkgs { inherit (machine) system; }; in lib.attrsets.concatMapAttrs ( username: user: { "${username}@${hostname}" = { modules = let getUserConfig = import ./lib/utils/user-config.nix { inherit lib; }; userConfigPath = getUserConfig { inherit hostname username; }; in [ ( { pkgs, ... }: { config._module.args = { userConfig = { inherit hostname username ; } // user; }; }) sops-nix.homeManagerModules.sops ./lib/home.nix ] ++ (lib.optional (userConfigPath != null) userConfigPath); }; }) (machine.config { inherit pkgs; }).users) machines; }); }