refactor: replace mapAttrs' with mapAttrs

This commit is contained in:
Ryan Yin
2023-12-22 01:43:28 +08:00
parent e4abf62ec3
commit 8ac24e4f13
5 changed files with 23 additions and 28 deletions

View File

@@ -1,5 +1,10 @@
let rec {
systemAttrs = { # user information
username = "ryan";
userfullname = "Ryan Yin";
useremail = "xiaoyin_c@qq.com";
allSystemAttrs = {
# linux systems # linux systems
x64_system = "x86_64-linux"; x64_system = "x86_64-linux";
riscv64_system = "riscv64-linux"; riscv64_system = "riscv64-linux";
@@ -8,12 +13,5 @@ let
x64_darwin = "x86_64-darwin"; x64_darwin = "x86_64-darwin";
aarch64_darwin = "aarch64-darwin"; aarch64_darwin = "aarch64-darwin";
}; };
in systemAttrs // { allSystems = builtins.attrValues allSystemAttrs;
# user information
username = "ryan";
userfullname = "Ryan Yin";
useremail = "xiaoyin_c@qq.com";
inherit systemAttrs;
allSystems = builtins.attrValues systemAttrs;
} }

View File

@@ -1,12 +1,13 @@
args: args:
with args; let with args;
with allSystemAttrs; let
lib = nixpkgs.lib; lib = nixpkgs.lib;
colmenaSystem = import ../lib/colmenaSystem.nix; colmenaSystem = import ../lib/colmenaSystem.nix;
# x86_64 related # x86_64 related
x64_base_args = { x64_base_args = {
inherit home-manager; inherit home-manager;
inherit nixpkgs; # or nixpkgs-unstable inherit nixpkgs; # or nixpkgs-unstable
specialArgs = x64_system_specialArgs; specialArgs = allSystemSpecialArgs.x64_system;
}; };
# riscv64 related # riscv64 related
@@ -44,7 +45,8 @@ in {
colmena = { colmena = {
meta = { meta = {
nixpkgs = import nixpkgs {system = x64_system;}; nixpkgs = import nixpkgs {system = x64_system;};
specialArgs = x64_system_specialArgs; specialArgs = allSystemSpecialArgs.x64_system;
nodeSpecialArgs = { nodeSpecialArgs = {
# riscv64 SBCs # riscv64 SBCs

View File

@@ -3,8 +3,8 @@ with args; let
macosSystem = import ../lib/macosSystem.nix; macosSystem = import ../lib/macosSystem.nix;
x64_args = { x64_args = {
inherit nix-darwin home-manager; inherit nix-darwin home-manager;
system = x64_darwin; system = allSystemAttrs.x64_darwin;
specialArgs = x64_darwin_specialArgs; specialArgs = allSystemSpecialArgs.x64_darwin;
nixpkgs = nixpkgs-darwin; nixpkgs = nixpkgs-darwin;
}; };
aarch64_args = { aarch64_args = {
@@ -13,7 +13,6 @@ with args; let
specialArgs = aarch64_darwin_specialArgs; specialArgs = aarch64_darwin_specialArgs;
nixpkgs = nixpkgs-darwin; nixpkgs = nixpkgs-darwin;
}; };
in { in {
# macOS's configuration # macOS's configuration
darwinConfigurations = { darwinConfigurations = {

View File

@@ -18,21 +18,16 @@
} }
// inputs; // inputs;
# mapAttrs' allSystemSpecialArgs =
# (name: value: nameValuePair ("foo_" + name) ("bar-" + value)) lib.attrsets.mapAttrs
# { x = "a"; y = "b"; } (name: value: specialArgsForSystem value)
# => { foo_x = "bar-a"; foo_y = "bar-b"; } constants.allSystemAttrs;
allSystemSpecialArgs = with lib.attrsets;
mapAttrs'
(name: value: nameValuePair (name + "_specialArgs") (specialArgsForSystem value))
constants.systemAttrs;
args = lib.attrsets.mergeAttrsList [ args = lib.attrsets.mergeAttrsList [
inputs inputs
constants constants
vars vars
allSystemSpecialArgs {inherit self allSystemSpecialArgs;}
{inherit self;}
]; ];
in in
lib.attrsets.mergeAttrsList [ lib.attrsets.mergeAttrsList [

View File

@@ -1,5 +1,6 @@
args: args:
with args; let with args;
with allSystemAttrs; let
lib = nixpkgs.lib; lib = nixpkgs.lib;
nixosSystem = import ../lib/nixosSystem.nix; nixosSystem = import ../lib/nixosSystem.nix;
@@ -7,7 +8,7 @@ with args; let
inherit home-manager nixos-generators; inherit home-manager nixos-generators;
inherit nixpkgs; # or nixpkgs-unstable inherit nixpkgs; # or nixpkgs-unstable
system = x64_system; system = x64_system;
specialArgs = x64_system_specialArgs; specialArgs = allSystemSpecialArgs.x64_system;
}; };
in { in {
nixosConfigurations = { nixosConfigurations = {