{ description = "NixOS Configuration"; inputs = rec { nixpkgs-git.url = "github:/NixOS/nixpkgs"; nixpkgs-stable.url = "github:/NixOS/nixpkgs/nixos-22.11"; nixpkgs-unstable.url = "github:/NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:/NixOS/nixpkgs/nixos-unstable"; alejandra = { url = github:kamadorueda/alejandra/3.0.0; inputs.nixpkgs.follows = "nixpkgs"; }; mailserver.url = "gitlab:/simple-nixos-mailserver/nixos-mailserver"; sops-nix = { url = github:Mic92/sops-nix; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, alejandra, mailserver, sops-nix, ... } @ attrs: let lib = nixpkgs.lib; fn = import ./fn.nix {inherit lib;}; mappedFormatter = builtins.mapAttrs (arch: packages: packages.default) alejandra.packages; mappedApps = builtins.mapAttrs (_arch: packages: { "lint" = { type = "app"; program = "${packages.statix}/bin/statix"; }; }) nixpkgs.legacyPackages; system = "x86_64-linux"; machineList = fn.lst { p = toString ./machines; t = "directory"; b = false; }; configFiles = fn.lst { p = toString ./config; b = true; }; pkgsFiles = fn.lst { p = toString ./pkgs; b = true; }; serviceFiles = fn.lst { p = toString ./services; b = true; }; nixosSystemFor = machine: { name = machine; value = let machinePath = lib.concatStringsSep "/" [(toString ./.) "machines" machine]; machineFiles = lib.filter (name: lib.strings.hasSuffix ".nix" name) (fn.lst { p = machinePath; b = true; }); in nixpkgs.lib.nixosSystem { inherit system; specialArgs = attrs // {fn = fn;}; modules = [ (toString ./options/machine.nix) sops-nix.nixosModules.sops ] ++ machineFiles ++ configFiles ++ pkgsFiles ++ serviceFiles; }; }; in { apps = mappedApps; formatter = mappedFormatter; nixosConfigurations = lib.listToAttrs (map nixosSystemFor machineList); }; }