From 8ac24e4f13f356d1603f4ee42fb0e5f703c18d37 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Fri, 22 Dec 2023 01:43:28 +0800 Subject: [PATCH] refactor: replace mapAttrs' with mapAttrs --- constants.nix | 18 ++++++++---------- systems/colmena.nix | 8 +++++--- systems/darwin.nix | 5 ++--- systems/default.nix | 15 +++++---------- systems/nixos.nix | 5 +++-- 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/constants.nix b/constants.nix index 128d4b05..038fef18 100644 --- a/constants.nix +++ b/constants.nix @@ -1,5 +1,10 @@ -let - systemAttrs = { +rec { + # user information + username = "ryan"; + userfullname = "Ryan Yin"; + useremail = "xiaoyin_c@qq.com"; + + allSystemAttrs = { # linux systems x64_system = "x86_64-linux"; riscv64_system = "riscv64-linux"; @@ -8,12 +13,5 @@ let x64_darwin = "x86_64-darwin"; aarch64_darwin = "aarch64-darwin"; }; -in systemAttrs // { - # user information - username = "ryan"; - userfullname = "Ryan Yin"; - useremail = "xiaoyin_c@qq.com"; - - inherit systemAttrs; - allSystems = builtins.attrValues systemAttrs; + allSystems = builtins.attrValues allSystemAttrs; } diff --git a/systems/colmena.nix b/systems/colmena.nix index fc91a4aa..52b4e6c0 100644 --- a/systems/colmena.nix +++ b/systems/colmena.nix @@ -1,12 +1,13 @@ args: -with args; let +with args; +with allSystemAttrs; let lib = nixpkgs.lib; colmenaSystem = import ../lib/colmenaSystem.nix; # x86_64 related x64_base_args = { inherit home-manager; inherit nixpkgs; # or nixpkgs-unstable - specialArgs = x64_system_specialArgs; + specialArgs = allSystemSpecialArgs.x64_system; }; # riscv64 related @@ -44,7 +45,8 @@ in { colmena = { meta = { nixpkgs = import nixpkgs {system = x64_system;}; - specialArgs = x64_system_specialArgs; + specialArgs = allSystemSpecialArgs.x64_system; + nodeSpecialArgs = { # riscv64 SBCs diff --git a/systems/darwin.nix b/systems/darwin.nix index 0857be83..c3a62a23 100644 --- a/systems/darwin.nix +++ b/systems/darwin.nix @@ -3,8 +3,8 @@ with args; let macosSystem = import ../lib/macosSystem.nix; x64_args = { inherit nix-darwin home-manager; - system = x64_darwin; - specialArgs = x64_darwin_specialArgs; + system = allSystemAttrs.x64_darwin; + specialArgs = allSystemSpecialArgs.x64_darwin; nixpkgs = nixpkgs-darwin; }; aarch64_args = { @@ -13,7 +13,6 @@ with args; let specialArgs = aarch64_darwin_specialArgs; nixpkgs = nixpkgs-darwin; }; - in { # macOS's configuration darwinConfigurations = { diff --git a/systems/default.nix b/systems/default.nix index d8ab65aa..cb995a9e 100644 --- a/systems/default.nix +++ b/systems/default.nix @@ -18,21 +18,16 @@ } // inputs; - # mapAttrs' - # (name: value: nameValuePair ("foo_" + name) ("bar-" + value)) - # { x = "a"; y = "b"; } - # => { foo_x = "bar-a"; foo_y = "bar-b"; } - allSystemSpecialArgs = with lib.attrsets; - mapAttrs' - (name: value: nameValuePair (name + "_specialArgs") (specialArgsForSystem value)) - constants.systemAttrs; + allSystemSpecialArgs = + lib.attrsets.mapAttrs + (name: value: specialArgsForSystem value) + constants.allSystemAttrs; args = lib.attrsets.mergeAttrsList [ inputs constants vars - allSystemSpecialArgs - {inherit self;} + {inherit self allSystemSpecialArgs;} ]; in lib.attrsets.mergeAttrsList [ diff --git a/systems/nixos.nix b/systems/nixos.nix index cb883ded..499853da 100644 --- a/systems/nixos.nix +++ b/systems/nixos.nix @@ -1,5 +1,6 @@ args: -with args; let +with args; +with allSystemAttrs; let lib = nixpkgs.lib; nixosSystem = import ../lib/nixosSystem.nix; @@ -7,7 +8,7 @@ with args; let inherit home-manager nixos-generators; inherit nixpkgs; # or nixpkgs-unstable system = x64_system; - specialArgs = x64_system_specialArgs; + specialArgs = allSystemSpecialArgs.x64_system; }; in { nixosConfigurations = {