revert(dotfiles): share Nix file discovery
This commit is contained in:
@@ -17,7 +17,7 @@ let
|
|||||||
util = import ./util.nix { inherit lib; };
|
util = import ./util.nix { inherit lib; };
|
||||||
|
|
||||||
registry = import ./registry.nix {
|
registry = import ./registry.nix {
|
||||||
inherit lib util;
|
inherit lib;
|
||||||
hosts = self.nixosConfigurations;
|
hosts = self.nixosConfigurations;
|
||||||
root = root + "/registry";
|
root = root + "/registry";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
util,
|
util,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
files = util.collectNixFiles root;
|
|
||||||
mkGuest =
|
mkGuest =
|
||||||
name:
|
name:
|
||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
@@ -168,22 +167,22 @@ let
|
|||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
assertions =
|
assertions =
|
||||||
let
|
let
|
||||||
|
hasDirectorySettings = mount: mount.owner != null || mount.group != null || mount.mode != null;
|
||||||
|
hasCompleteDirectorySettings =
|
||||||
|
mount: mount.owner != null && mount.group != null && mount.mode != null;
|
||||||
|
hasOneSource = mount: (mount.directory != null) != (mount.file != null);
|
||||||
mountsWithInvalidSource = lib.attrNames (
|
mountsWithInvalidSource = lib.attrNames (
|
||||||
lib.filterAttrs (_: mount: !hasOneSource mount) cfg.mounts
|
lib.filterAttrs (_: mount: !hasOneSource mount) cfg.mounts
|
||||||
);
|
);
|
||||||
hasOneSource = mount: (mount.directory != null) != (mount.file != null);
|
|
||||||
fileMountsWithHostSettings = lib.attrNames (
|
fileMountsWithHostSettings = lib.attrNames (
|
||||||
lib.filterAttrs (_: mount: mount.file != null && hasDirectorySettings mount) cfg.mounts
|
lib.filterAttrs (_: mount: mount.file != null && hasDirectorySettings mount) cfg.mounts
|
||||||
);
|
);
|
||||||
hasDirectorySettings = mount: mount.owner != null || mount.group != null || mount.mode != null;
|
|
||||||
directoryMountsWithPartialHostSettings = lib.attrNames (
|
directoryMountsWithPartialHostSettings = lib.attrNames (
|
||||||
lib.filterAttrs (
|
lib.filterAttrs (
|
||||||
_: mount:
|
_: mount:
|
||||||
mount.directory != null && hasDirectorySettings mount && !hasCompleteDirectorySettings mount
|
mount.directory != null && hasDirectorySettings mount && !hasCompleteDirectorySettings mount
|
||||||
) cfg.mounts
|
) cfg.mounts
|
||||||
);
|
);
|
||||||
hasCompleteDirectorySettings =
|
|
||||||
mount: mount.owner != null && mount.group != null && mount.mode != null;
|
|
||||||
in
|
in
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -276,7 +275,11 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
names = map (path: lib.removeSuffix ".nix" (builtins.baseNameOf path)) files;
|
files = util.collectNixFiles root;
|
||||||
|
guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) (
|
||||||
|
builtins.readDir root
|
||||||
|
);
|
||||||
|
names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = files ++ map mkGuest names;
|
imports = files ++ map mkGuest names;
|
||||||
|
|||||||
@@ -2,14 +2,20 @@
|
|||||||
hosts,
|
hosts,
|
||||||
lib,
|
lib,
|
||||||
root,
|
root,
|
||||||
util,
|
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
definitions = lib.listToAttrs (
|
definitions =
|
||||||
map (path: lib.nameValuePair (registryName (builtins.baseNameOf path)) (mkRegistry path)) (
|
lib.mapAttrs'
|
||||||
util.collectNixFiles root
|
(
|
||||||
)
|
name: _type:
|
||||||
);
|
let
|
||||||
|
path = root + "/${name}";
|
||||||
|
in
|
||||||
|
lib.nameValuePair (registryName name) (mkRegistry path)
|
||||||
|
)
|
||||||
|
(
|
||||||
|
lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root)
|
||||||
|
);
|
||||||
|
|
||||||
registryName = fileName: lib.removeSuffix ".nix" fileName;
|
registryName = fileName: lib.removeSuffix ".nix" fileName;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user