diff --git a/flake.nix b/flake.nix index 20c6d3e..2513686 100644 --- a/flake.nix +++ b/flake.nix @@ -8,86 +8,86 @@ }; outputs = { self, nixpkgs, flake-utils, sops-nix }: ( - 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 = + let + inherit (nixpkgs) lib; + tryFiles = files: default: + lib.lists.foldr + (a: b: + if builtins.pathExists a + then a + else b) + default + files; + in + flake-utils.lib.eachDefaultSystem ( + system: let - default = { pkgs, ... }: { - dualBoot = false; - timeZone = null; - keyMap = "us"; - keyboardLayout = "us"; - localeSettings = { }; - users = { }; - }; - systems = { - nixos.config = { ... }: { - }; - }; - in - builtins.mapAttrs ( - name: { system ? "x86_64-linux", config }: nixpkgs.lib.nixosSystem { - inherit system; + pkgs = import nixpkgs { + inherit system; + config = {}; - modules = [ - ( - { pkgs, ... }@args: { - config._module.args = { - hostname = name; - - machineConfig = (default args) // - (config args) // { - inherit name; - }; - }; - }) - sops-nix.nixosModules.sops - ./lib/configuration.nix - ( - let - configCandidate = ./lib/machines/${name}.nix; - - machineConfigPath = - if builtins.pathExists configCandidate - then - configCandidate - else - ./lib/hardware/base.nix; - in - machineConfigPath) + 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 = + let + default = { pkgs, ... }: { + dualBoot = false; + timeZone = null; + keyMap = "us"; + keyboardLayout = "us"; + localeSettings = { }; + users = { }; + }; + systems = { + nixos.config = { ... }: { + }; + }; + in + builtins.mapAttrs ( + name: { system ? "x86_64-linux", config }: nixpkgs.lib.nixosSystem { + inherit system; + + modules = [ + ( + { pkgs, ... }@args: { + config._module.args = { + hostname = name; + + machineConfig = (default args) // + (config args) // { + inherit name; + }; + }; + }) + sops-nix.nixosModules.sops + ./lib/configuration.nix + (tryFiles [ ./lib/machines/${name}.nix ] ./lib/hardware/base.nix) + ]; }) systems; });