Simplify trying to import files

This commit is contained in:
Manuel Thalmann 2024-05-09 00:50:42 +02:00
parent 808926f012
commit 2cce1f0b2e

View file

@ -8,6 +8,17 @@
}; };
outputs = { self, nixpkgs, flake-utils, sops-nix }: ( outputs = { self, nixpkgs, flake-utils, sops-nix }: (
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 ( flake-utils.lib.eachDefaultSystem (
system: system:
let let
@ -75,18 +86,7 @@
}) })
sops-nix.nixosModules.sops sops-nix.nixosModules.sops
./lib/configuration.nix ./lib/configuration.nix
( (tryFiles [ ./lib/machines/${name}.nix ] ./lib/hardware/base.nix)
let
configCandidate = ./lib/machines/${name}.nix;
machineConfigPath =
if builtins.pathExists configCandidate
then
configCandidate
else
./lib/hardware/base.nix;
in
machineConfigPath)
]; ];
}) })
systems; systems;