chore!(util): clean up

Fix `hasDirectories`
Correctly detect `autoDarwinConfigurations` (did not check for `home`)
Decrease usage of `with`
Depend more on `lib` functions over custom implementations
Reindent correctly some code
This commit is contained in:
reo101 2023-04-23 02:39:34 +03:00
parent c58f383168
commit 46f6f90a0c
Signed by: reo101
GPG key ID: 675AA7EF13964ACB
2 changed files with 64 additions and 42 deletions

View file

@ -78,25 +78,24 @@
let let
inherit (self) outputs; inherit (self) outputs;
util = import ./util { inherit inputs outputs; }; util = import ./util { inherit inputs outputs; };
in in rec {
with util; rec {
# Packages (`nix build`) # Packages (`nix build`)
packages = forEachPkgs (pkgs: packages = util.forEachPkgs (pkgs:
import ./pkgs { inherit pkgs; } import ./pkgs { inherit pkgs; }
); );
# Apps (`nix run`) # Apps (`nix run`)
apps = forEachPkgs (pkgs: apps = util.forEachPkgs (pkgs:
import ./apps { inherit pkgs; } import ./apps { inherit pkgs; }
); );
# Dev Shells (`nix develop`) # Dev Shells (`nix develop`)
devShells = forEachPkgs (pkgs: devShells = util.forEachPkgs (pkgs:
import ./shells { inherit pkgs; } import ./shells { inherit pkgs; }
); );
# Formatter # Formatter
formatter = forEachPkgs (pkgs: formatter = util.forEachPkgs (pkgs:
pkgs.nixpkgs-fmt pkgs.nixpkgs-fmt
); );
@ -107,22 +106,24 @@
overlays = import ./overlays { inherit inputs outputs; }; overlays = import ./overlays { inherit inputs outputs; };
# Machines # Machines
inherit machines; inherit (util)
inherit homeManagerMachines; machines
inherit nixDarwinMachines; homeManagerMachines
inherit nixOnDroidMachines; nixDarwinMachines
inherit nixosMachines; nixOnDroidMachines
nixosMachines;
# Modules # Modules
inherit nixosModules; inherit (util)
inherit nixOnDroidModules; nixosModules
inherit nixDarwinModules; nixOnDroidModules
inherit homeManagerModules; nixDarwinModules
homeManagerModules;
# Configurations # Configurations
nixosConfigurations = autoNixosConfigurations; nixosConfigurations = util.autoNixosConfigurations;
nixOnDroidConfigurations = autoNixOnDroidConfigurations; nixOnDroidConfigurations = util.autoNixOnDroidConfigurations;
darwinConfigurations = autoDarwinConfigurations; darwinConfigurations = util.autoDarwinConfigurations;
homeConfigurations = autoHomeConfigurations; homeConfigurations = util.autoHomeConfigurations;
}; };
} }

View file

@ -20,7 +20,7 @@ rec {
# NOTE: Implying `attrs` is the output of `recurseDir` # NOTE: Implying `attrs` is the output of `recurseDir`
hasFiles = files: attrs: hasFiles = files: attrs:
builtins.all builtins.all
(b: b) lib.id
(builtins.map (builtins.map
(file: (file:
builtins.hasAttr file attrs && builtins.hasAttr file attrs &&
@ -30,13 +30,15 @@ rec {
# NOTE: Implying `attrs` is the output of `recurseDir` # NOTE: Implying `attrs` is the output of `recurseDir`
hasDirectories = directories: attrs: hasDirectories = directories: attrs:
builtins.all builtins.all
(b: b) lib.id
(builtins.map (builtins.map
(directory: (directory:
builtins.hasAttr directory attrs && builtins.hasAttr directory attrs &&
builtins.getAttr directory attrs == "set") lib.isAttrs (builtins.getAttr directory attrs))
directories); directories);
and = lib.all lib.id;
# pkgs helpers # pkgs helpers
forEachSystem = lib.genAttrs [ forEachSystem = lib.genAttrs [
"aarch64-linux" "aarch64-linux"
@ -159,13 +161,14 @@ rec {
createConfigurations = createConfigurations =
pred: mkHost: machines: pred: mkHost: machines:
lib.foldAttrs lib.foldAttrs
(acc: x: acc) lib.const
[ ] [ ]
(builtins.attrValues (builtins.attrValues
(builtins.mapAttrs (builtins.mapAttrs
(system: hosts: (system: hosts:
lib.attrsets.filterAttrs lib.attrsets.filterAttrs
(host: config: config != null) (host: config:
config != null)
(builtins.mapAttrs (builtins.mapAttrs
(host: config: (host: config:
if (pred system host config) if (pred system host config)
@ -178,9 +181,15 @@ rec {
autoNixosConfigurations = autoNixosConfigurations =
createConfigurations createConfigurations
(system: host: config: (system: host: config:
hasFiles and
[
(hasFiles
[ "configuration.nix" ] [ "configuration.nix" ]
config) config)
(hasDirectories
[ "home" ]
config)
])
(system: host: config: (system: host: config:
mkNixosHost mkNixosHost
../machines/nixos/${system}/${host} ../machines/nixos/${system}/${host}
@ -194,9 +203,12 @@ rec {
autoNixOnDroidConfigurations = autoNixOnDroidConfigurations =
createConfigurations createConfigurations
(system: host: config: (system: host: config:
hasFiles and
[
(hasFiles
[ "configuration.nix" "home.nix" ] [ "configuration.nix" "home.nix" ]
config) config)
])
(system: host: config: (system: host: config:
mkNixOnDroidHost mkNixOnDroidHost
../machines/nix-on-droid/${system}/${host} ../machines/nix-on-droid/${system}/${host}
@ -207,9 +219,15 @@ rec {
autoDarwinConfigurations = autoDarwinConfigurations =
createConfigurations createConfigurations
(system: host: config: (system: host: config:
hasFiles and
[
(hasFiles
[ "configuration.nix" ] [ "configuration.nix" ]
config) config)
(hasDirectories
[ "home" ]
config)
])
(system: host: config: (system: host: config:
mkNixDarwinHost mkNixDarwinHost
../machines/nix-darwin/${system}/${host} ../machines/nix-darwin/${system}/${host}
@ -223,9 +241,12 @@ rec {
autoHomeConfigurations = autoHomeConfigurations =
createConfigurations createConfigurations
(system: host: config: (system: host: config:
hasFiles and
[
(hasFiles
[ "home.nix" ] [ "home.nix" ]
config) config)
])
(system: host: config: (system: host: config:
mkHomeManagerHost mkHomeManagerHost
../machines/home-manager/${system}/${host} ../machines/home-manager/${system}/${host}