diff --git a/flake.nix b/flake.nix index 0705297..8f8659c 100644 --- a/flake.nix +++ b/flake.nix @@ -78,25 +78,24 @@ let inherit (self) outputs; util = import ./util { inherit inputs outputs; }; - in - with util; rec { + in rec { # Packages (`nix build`) - packages = forEachPkgs (pkgs: + packages = util.forEachPkgs (pkgs: import ./pkgs { inherit pkgs; } ); # Apps (`nix run`) - apps = forEachPkgs (pkgs: + apps = util.forEachPkgs (pkgs: import ./apps { inherit pkgs; } ); # Dev Shells (`nix develop`) - devShells = forEachPkgs (pkgs: + devShells = util.forEachPkgs (pkgs: import ./shells { inherit pkgs; } ); # Formatter - formatter = forEachPkgs (pkgs: + formatter = util.forEachPkgs (pkgs: pkgs.nixpkgs-fmt ); @@ -107,22 +106,24 @@ overlays = import ./overlays { inherit inputs outputs; }; # Machines - inherit machines; - inherit homeManagerMachines; - inherit nixDarwinMachines; - inherit nixOnDroidMachines; - inherit nixosMachines; + inherit (util) + machines + homeManagerMachines + nixDarwinMachines + nixOnDroidMachines + nixosMachines; # Modules - inherit nixosModules; - inherit nixOnDroidModules; - inherit nixDarwinModules; - inherit homeManagerModules; + inherit (util) + nixosModules + nixOnDroidModules + nixDarwinModules + homeManagerModules; # Configurations - nixosConfigurations = autoNixosConfigurations; - nixOnDroidConfigurations = autoNixOnDroidConfigurations; - darwinConfigurations = autoDarwinConfigurations; - homeConfigurations = autoHomeConfigurations; + nixosConfigurations = util.autoNixosConfigurations; + nixOnDroidConfigurations = util.autoNixOnDroidConfigurations; + darwinConfigurations = util.autoDarwinConfigurations; + homeConfigurations = util.autoHomeConfigurations; }; } diff --git a/util/default.nix b/util/default.nix index c13b4a1..bc5604f 100644 --- a/util/default.nix +++ b/util/default.nix @@ -20,7 +20,7 @@ rec { # NOTE: Implying `attrs` is the output of `recurseDir` hasFiles = files: attrs: builtins.all - (b: b) + lib.id (builtins.map (file: builtins.hasAttr file attrs && @@ -30,13 +30,15 @@ rec { # NOTE: Implying `attrs` is the output of `recurseDir` hasDirectories = directories: attrs: builtins.all - (b: b) + lib.id (builtins.map (directory: builtins.hasAttr directory attrs && - builtins.getAttr directory attrs == "set") + lib.isAttrs (builtins.getAttr directory attrs)) directories); + and = lib.all lib.id; + # pkgs helpers forEachSystem = lib.genAttrs [ "aarch64-linux" @@ -159,28 +161,35 @@ rec { createConfigurations = pred: mkHost: machines: lib.foldAttrs - (acc: x: acc) + lib.const [ ] (builtins.attrValues (builtins.mapAttrs (system: hosts: - lib.attrsets.filterAttrs - (host: config: config != null) - (builtins.mapAttrs + lib.attrsets.filterAttrs (host: config: - if (pred system host config) - then mkHost system host config - else null) - hosts)) + config != null) + (builtins.mapAttrs + (host: config: + if (pred system host config) + then mkHost system host config + else null) + hosts)) machines)); # Configurations autoNixosConfigurations = createConfigurations (system: host: config: - hasFiles - [ "configuration.nix" ] - config) + and + [ + (hasFiles + [ "configuration.nix" ] + config) + (hasDirectories + [ "home" ] + config) + ]) (system: host: config: mkNixosHost ../machines/nixos/${system}/${host} @@ -194,9 +203,12 @@ rec { autoNixOnDroidConfigurations = createConfigurations (system: host: config: - hasFiles - [ "configuration.nix" "home.nix" ] - config) + and + [ + (hasFiles + [ "configuration.nix" "home.nix" ] + config) + ]) (system: host: config: mkNixOnDroidHost ../machines/nix-on-droid/${system}/${host} @@ -207,9 +219,15 @@ rec { autoDarwinConfigurations = createConfigurations (system: host: config: - hasFiles - [ "configuration.nix" ] - config) + and + [ + (hasFiles + [ "configuration.nix" ] + config) + (hasDirectories + [ "home" ] + config) + ]) (system: host: config: mkNixDarwinHost ../machines/nix-darwin/${system}/${host} @@ -223,9 +241,12 @@ rec { autoHomeConfigurations = createConfigurations (system: host: config: - hasFiles - [ "home.nix" ] - config) + and + [ + (hasFiles + [ "home.nix" ] + config) + ]) (system: host: config: mkHomeManagerHost ../machines/home-manager/${system}/${host}