From 70d949e7e0451e69743b8af382c8273978431784 Mon Sep 17 00:00:00 2001 From: reo101 Date: Fri, 19 Jul 2024 01:33:09 +0300 Subject: [PATCH] refactor(nix): `config` -> `configuration` Avoid shadowin `flake-parts`' `config` --- nix/configurations.nix | 36 ++++++++++++------------- nix/deploy.nix | 10 +++---- nix/utils.nix | 60 +++++++++++++++++++++--------------------- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/nix/configurations.nix b/nix/configurations.nix index bdc0d23..5501284 100644 --- a/nix/configurations.nix +++ b/nix/configurations.nix @@ -142,14 +142,14 @@ let (builtins.mapAttrs (system: hosts: lib.concatMapAttrs - (host: config: + (host: configuration: lib.optionalAttrs (and [ (host != "__template__") - (pred system host config) + (pred system host configuration) ]) { - ${host} = mkHost system host config; + ${host} = mkHost system host configuration; }) hosts) machines)); @@ -160,36 +160,36 @@ in # Configurations nixosConfigurations = createConfigurations - (system: host: config: + (system: host: configuration: and [ (hasFiles [ "configuration.nix" ] - config) + configuration) # (hasDirectories # [ "home" ] # config) ]) - (system: host: config: + (system: host: configuration: mkNixosHost ../machines/nixos/${system}/${host} system host (builtins.map (lib.strings.removeSuffix ".nix") - (builtins.attrNames (config."home" or { })))) + (builtins.attrNames (configuration."home" or { })))) config.flake.nixosMachines; nixOnDroidConfigurations = createConfigurations - (system: host: config: + (system: host: configuration: and [ (hasFiles [ "configuration.nix" "home.nix" ] - config) + configuration) ]) - (system: host: config: + (system: host: configuration: mkNixOnDroidHost ../machines/nix-on-droid/${system}/${host} system @@ -198,36 +198,36 @@ in darwinConfigurations = createConfigurations - (system: host: config: + (system: host: configuration: and [ (hasFiles [ "configuration.nix" ] - config) + configuration) (hasDirectories [ "home" ] - config) + configuration) ]) - (system: host: config: + (system: host: configuration: mkNixDarwinHost ../machines/nix-darwin/${system}/${host} system host (builtins.map (lib.strings.removeSuffix ".nix") - (builtins.attrNames (config."home" or { })))) + (builtins.attrNames (configuration."home" or { })))) config.flake.nixDarwinMachines; homeConfigurations = createConfigurations - (system: host: config: + (system: host: configuration: and [ (hasFiles [ "home.nix" ] - config) + configuration) ]) - (system: host: config: + (system: host: configuration: mkHomeManagerHost ../machines/home-manager/${system}/${host} system diff --git a/nix/deploy.nix b/nix/deploy.nix index 496b642..fdac8b0 100644 --- a/nix/deploy.nix +++ b/nix/deploy.nix @@ -3,7 +3,7 @@ let inherit (import ./utils.nix { inherit lib self; }) accumulateMachines - config-type-to-deploy-type; + configuration-type-to-deploy-type; in { flake = { @@ -11,10 +11,10 @@ in accumulateMachines # TODO: nix-on-droid ["nixos" "nix-darwin"] - ({ host, system, config-type, config }: + ({ host, system, configuration-type, configuration }: let deploy-config-path = - ../machines/${config-type}/${system}/${host}/deploy.nix; + ../machines/${configuration-type}/${system}/${host}/deploy.nix; deploy-config = import deploy-config-path; in @@ -27,9 +27,9 @@ in profiles.system = deploy-config // { path = let - deploy-type = config-type-to-deploy-type config-type; + deploy-type = configuration-type-to-deploy-type configuration-type; in - inputs.deploy-rs.lib.${system}.activate.${deploy-type} config; + inputs.deploy-rs.lib.${system}.activate.${deploy-type} configuration; }; }; } diff --git a/nix/utils.nix b/nix/utils.nix index 8cf4175..b7ccf92 100644 --- a/nix/utils.nix +++ b/nix/utils.nix @@ -30,83 +30,83 @@ rec { # NOTE: Implying last argument is the output of `recurseDir` hasDirectories = allSatisfy lib.isAttrs; - gen-config-type-to = mappings: mkError: config-type: - mappings.${config-type} or + gen-configuration-type-to = mappings: mkError: configuration-type: + mappings.${configuration-type} or (builtins.throw - (mkError config-type)); + (mkError configuration-type)); - config-type-to-outputs-machines = - gen-config-type-to + configuration-type-to-outputs-machines = + gen-configuration-type-to { nixos = "nixosMachines"; nix-on-droid = "nixOnDroidMachines"; nix-darwin = "nixDarwinMachines"; home-manager = "homeMachines"; } - (config-type: + (configuration-type: builtins.throw - "Invaild config-type \"${config-type}\" for flake outputs' machines"); + "Invaild configuration-type \"${configuration-type}\" for flake outputs' machines"); - config-type-to-outputs-configurations = - gen-config-type-to + configuration-type-to-outputs-configurations = + gen-configuration-type-to { nixos = "nixosConfigurations"; nix-on-droid = "nixOnDroidConfigurations"; nix-darwin = "darwinConfigurations"; home-manager = "homeConfigurations"; } - (config-type: + (configuration-type: builtins.throw - "Invaild config-type \"${config-type}\" for flake outputs' configurations"); + "Invaild configuration-type \"${configuration-type}\" for flake outputs' configurations"); - config-type-to-deploy-type = - gen-config-type-to + configuration-type-to-deploy-type = + gen-configuration-type-to { nixos = "nixos"; nix-darwin = "darwin"; } - (config-type: + (configuration-type: builtins.throw - "Invaild config-type \"${config-type}\" for deploy-rs deployment"); + "Invaild configuration-type \"${configuration-type}\" for deploy-rs deployment"); - accumulateMachines = config-types: host-system-config-type-config-fn: + accumulateMachines = configuration-types: host-system-configuration-type-configuration-fn: lib.flip lib.concatMapAttrs (lib.genAttrs - config-types - (config-type: + configuration-types + (configuration-type: let - machines = config-type-to-outputs-machines config-type; + machines = configuration-type-to-outputs-machines configuration-type; in self.${machines})) - (config-type: machines: + (configuration-type: machines: lib.pipe machines [ # Filter out nondirectories (lib.filterAttrs - (system: configs: - builtins.isAttrs configs)) + (system: configurations: + builtins.isAttrs configurations)) # Convert non-template configs into `system-and-config` pairs (lib.concatMapAttrs - (system: configs: + (system: configurations: (lib.concatMapAttrs - (host: config: + (host: configuration: lib.optionalAttrs (host != "__template__") { ${host} = { inherit system; - config = + configuration = let - configurations = config-type-to-outputs-configurations config-type; + configurations = configuration-type-to-outputs-configurations configuration-type; in self.${configurations}.${host}; }; }) - configs))) - # Convert each `system-and-config` pair into a deploy-rs node + configurations))) + # Convert each `system-and-config` pair into a *whatever* (lib.concatMapAttrs - (host: { system, config }: - host-system-config-type-config-fn { inherit host system config-type config; })) + (host: { system, configuration }: + host-system-configuration-type-configuration-fn { inherit host system configuration-type configuration; })) ]); }