refactor: cleanup instances where we map to attrs to be more resilient against duplicate names
This commit is contained in:
parent
f17ae1ca7b
commit
dbb78088f4
|
@ -12,16 +12,13 @@
|
||||||
in
|
in
|
||||||
"${name}@${host}";
|
"${name}@${host}";
|
||||||
|
|
||||||
# given a DNS-style recursive AttrSet, return a flat AttrSet that maps ssh id => pubkey.
|
# [{ path :: [String], value :: String }] for the keys we want to install
|
||||||
keysFor = attrs:
|
globalKeys = sane-lib.flattenAttrs sane-data.keys;
|
||||||
let
|
localKeys = sane-lib.flattenAttrs sane-data.keys.org.uninsane.local;
|
||||||
by-path = sane-lib.flattenAttrs attrs;
|
in lib.mkMerge (builtins.map
|
||||||
in
|
({ path, value }: {
|
||||||
sane-lib.mapToAttrs ({ path, value }: {
|
"${keyNameForPath path}" = value;
|
||||||
name = keyNameForPath path;
|
})
|
||||||
inherit value;
|
(globalKeys ++ localKeys)
|
||||||
}) by-path;
|
);
|
||||||
globalKeys = keysFor sane-data.keys;
|
|
||||||
localKeys = keysFor sane-data.keys.org.uninsane.local;
|
|
||||||
in lib.mkMerge [ globalKeys localKeys ];
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,16 @@ rec {
|
||||||
path = import ./path.nix moduleArgs;
|
path = import ./path.nix moduleArgs;
|
||||||
types = import ./types.nix moduleArgs;
|
types = import ./types.nix moduleArgs;
|
||||||
|
|
||||||
|
# like `builtins.listToAttrs` but any duplicated `name` throws error on access.
|
||||||
|
# Type: listToDisjointAttrs :: [{ name :: String, value :: Any }] -> AttrSet
|
||||||
|
listToDisjointAttrs = l: lib.foldl' lib.attrsets.unionOfDisjoint {} (builtins.map nameValueToAttrs l);
|
||||||
|
|
||||||
|
# evaluate a `{ name, value }` pair in the same way that `listToAttrs` does.
|
||||||
|
# Type: nameValueToAttrs :: { name :: String, value :: Any } -> Any
|
||||||
|
nameValueToAttrs = { name, value }: {
|
||||||
|
"${name}" = value;
|
||||||
|
};
|
||||||
|
|
||||||
# if `maybe-null` is non-null, yield that. else, return the `default`.
|
# if `maybe-null` is non-null, yield that. else, return the `default`.
|
||||||
withDefault = default: maybe-null: if maybe-null != null then
|
withDefault = default: maybe-null: if maybe-null != null then
|
||||||
maybe-null
|
maybe-null
|
||||||
|
@ -22,9 +32,10 @@ rec {
|
||||||
(name: value: builtins.elem name names)
|
(name: value: builtins.elem name names)
|
||||||
attrs;
|
attrs;
|
||||||
|
|
||||||
# transform a list into an AttrSet via a function which maps an element to a name + value
|
# transform a list into an AttrSet via a function which maps an element to a { name, value } pair.
|
||||||
|
# it's an error for the same name to be specified more than once
|
||||||
# Type: mapToAttrs :: (a -> { name :: String, value :: Any }) -> [a] -> AttrSet
|
# Type: mapToAttrs :: (a -> { name :: String, value :: Any }) -> [a] -> AttrSet
|
||||||
mapToAttrs = f: list: builtins.listToAttrs (builtins.map f list);
|
mapToAttrs = f: list: listToDisjointAttrs (builtins.map f list);
|
||||||
|
|
||||||
# flatten a nested AttrSet into a list of { path = [String]; value } items.
|
# flatten a nested AttrSet into a list of { path = [String]; value } items.
|
||||||
# Type: flattenAttrs :: AttrSet[AttrSet|Any] -> [{ path :: String, value :: Any }]
|
# Type: flattenAttrs :: AttrSet[AttrSet|Any] -> [{ path :: String, value :: Any }]
|
||||||
|
|
|
@ -235,10 +235,14 @@ in
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
# default each item along the backing path to have the same acl as the location it would be mounted.
|
# default each item along the backing path to have the same acl as the location it would be mounted.
|
||||||
sane.fs = sane-lib.mapToAttrs (fsSubpath: {
|
sane.fs = lib.mkMerge (builtins.map
|
||||||
name = fsPathToBackingPath fsSubpath;
|
(fsSubpath: {
|
||||||
value.generated.acl = config.sane.fs."${fsSubpath}".generated.acl;
|
"${fsPathToBackingPath fsSubpath}" = {
|
||||||
}) (path.walk store.prefix fspath);
|
generated.acl = config.sane.fs."${fsSubpath}".generated.acl;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
(path.walk store.prefix fspath)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
configsPerPath = lib.mapAttrsToList cfgFor cfg.byPath;
|
configsPerPath = lib.mapAttrsToList cfgFor cfg.byPath;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user