Fix invalid import issue.

This commit is contained in:
Zuckerberg 2023-04-21 18:57:06 -06:00
parent 71baa09bd2
commit 03603119e5
3 changed files with 103 additions and 85 deletions

View File

@ -12,7 +12,16 @@ in
./roles.nix ./roles.nix
]; ];
options.machines.hosts = lib.mkOption { options.machines = {
# For some reason (presumably a bug), using the best value of "../../machines"
# as the path causes nix to search for invalid paths for flake imports but *not*
# secrets.nix for agenix.
machinesPath = lib.mkOption {
type = lib.types.path;
default = ../..;
};
hosts = lib.mkOption {
type = lib.types.attrsOf type = lib.types.attrsOf
(lib.types.submodule { (lib.types.submodule {
options = { options = {
@ -107,6 +116,7 @@ in
}; };
}); });
}; };
};
config = { config = {
assertions = (lib.concatLists (lib.mapAttrsToList assertions = (lib.concatLists (lib.mapAttrsToList
@ -193,6 +203,6 @@ in
in in
lib.concatMap (d: propertiesFiles' "${dir}/${d}" d) dirPaths ++ builtins.map (p: { "${dirName}" = p; }) propFiles; lib.concatMap (d: propertiesFiles' "${dir}/${d}" d) dirPaths ++ builtins.map (p: { "${dirName}" = p; }) propFiles;
in in
properties ../../machines; properties config.machines.machinesPath;
}; };
} }

View File

@ -2,6 +2,7 @@
{ nixpkgs ? import <nixpkgs> { } { nixpkgs ? import <nixpkgs> { }
, assertionsModule ? <nixpkgs/nixos/modules/misc/assertions.nix> , assertionsModule ? <nixpkgs/nixos/modules/misc/assertions.nix>
, machinesPath ? null
}: }:
{ {
@ -10,6 +11,11 @@
modules = [ modules = [
./default.nix ./default.nix
assertionsModule assertionsModule
{
config = nixpkgs.lib.mkIf (machinesPath != null) {
machines.machinesPath = machinesPath;
};
}
]; ];
}).config.machines; }).config.machines;
} }

View File

@ -1,6 +1,8 @@
let let
lib = (import <nixpkgs> { }).lib; lib = (import <nixpkgs> { }).lib;
sshKeys = (import ../common/machine-info/moduleless.nix { }).machines.ssh; sshKeys = (import ../common/machine-info/moduleless.nix {
machinesPath = ../machines;
}).machines.ssh;
# add userkeys to all roles so that I can r/w the secrets from my personal computers # add userkeys to all roles so that I can r/w the secrets from my personal computers
roles = lib.mapAttrs (role: hosts: hosts ++ sshKeys.userKeys) sshKeys.hostKeysByRole; roles = lib.mapAttrs (role: hosts: hosts ++ sshKeys.userKeys) sshKeys.hostKeysByRole;