Simplify trying to import files

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

154
flake.nix
View file

@ -8,86 +8,86 @@
}; };
outputs = { self, nixpkgs, flake-utils, sops-nix }: ( outputs = { self, nixpkgs, flake-utils, sops-nix }: (
flake-utils.lib.eachDefaultSystem ( let
system: inherit (nixpkgs) lib;
let tryFiles = files: default:
pkgs = import nixpkgs { lib.lists.foldr
inherit system; (a: b:
config = {}; if builtins.pathExists a
then a
overlays = [ else b)
sops-nix.overlays.default default
]; files;
}; in
in { flake-utils.lib.eachDefaultSystem (
devShells.default = pkgs.mkShellNoCC ( system:
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 let
default = { pkgs, ... }: { pkgs = import nixpkgs {
dualBoot = false; inherit system;
timeZone = null; config = {};
keyMap = "us";
keyboardLayout = "us"; overlays = [
localeSettings = { }; sops-nix.overlays.default
users = { }; ];
}; };
systems = { in {
nixos.config = { ... }: { devShells.default = pkgs.mkShellNoCC (
}; with pkgs;
}; {
in sopsPGPKeyDirs = [
builtins.mapAttrs ( "${toString ./.}/keys/hosts"
name: { system ? "x86_64-linux", config }: nixpkgs.lib.nixosSystem { "${toString ./.}/keys/users"
inherit system;
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)
]; ];
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; systems;
}); });