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 }: (
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;
});