From 05aa451895cf38fb799b91b632e0206d4ca81d7c Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Fri, 22 Dec 2023 00:33:35 +0800 Subject: [PATCH] refactor: systems --- constants.nix | 21 ++++++++++++--------- systems/default.nix | 22 ++++++++++++++-------- systems/nixos.nix | 36 ++++++++++++++++++++---------------- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/constants.nix b/constants.nix index b50514f5..23ec3eb8 100644 --- a/constants.nix +++ b/constants.nix @@ -1,15 +1,18 @@ -rec { +let + systemAttrs = { + # linux systems + x64_system = "x86_64-linux"; + riscv64_system = "riscv64-linux"; + aarch64_system = "aarch64-linux"; + # darwin systems + x64_darwin = "x86_64-darwin"; + aarch64_darwin = "aarch64-darwin"; + }; +in systemAttrs // { # user information username = "ryan"; userfullname = "Ryan Yin"; useremail = "xiaoyin_c@qq.com"; - # linux systems - x64_system = "x86_64-linux"; - riscv64_system = "riscv64-linux"; - aarch64_system = "aarch64-linux"; - # darwin systems - x64_darwin = "x86_64-darwin"; - aarch64_darwin = "aarch64-darwin"; - allSystems = [x64_system riscv64_system aarch64_system x64_darwin aarch64_darwin]; + allSystems = builtins.attrValues systemAttrs; } diff --git a/systems/default.nix b/systems/default.nix index 8f1dc31b..12e45ecf 100644 --- a/systems/default.nix +++ b/systems/default.nix @@ -18,14 +18,20 @@ } // inputs; - allSystemSpecialArgs = with constants; { - x64_system_specialArgs = specialArgsForSystem x64_system; - aarch64_system_specialArgs = specialArgsForSystem aarch64_system; - riscv64_system_specialArgs = specialArgsForSystem riscv64_system; - - x64_darwin_specialArgs = specialArgsForSystem x64_darwin; - aarch64_darwin_specialArgs = specialArgsForSystem aarch64_darwin; - }; + allSystemSpecialArgs = builtins.listToAttrs ( + map + (attr: { + name = attr + "_specialArgs"; + value = specialArgsForSystem constants.${attr}; + }) + [ + "x64_system" + "aarch64_system" + "riscv64_system" + "x64_darwin" + "aarch64_darwin" + ] + ); args = lib.attrsets.mergeAttrsList [ inputs diff --git a/systems/nixos.nix b/systems/nixos.nix index fb0b75ab..cb883ded 100644 --- a/systems/nixos.nix +++ b/systems/nixos.nix @@ -1,5 +1,6 @@ args: with args; let + lib = nixpkgs.lib; nixosSystem = import ../lib/nixosSystem.nix; base_args = { @@ -23,25 +24,28 @@ in { # take system images for idols # https://github.com/nix-community/nixos-generators - packages."${x64_system}" = - # genAttrs returns an attribute set with the given keys and values(host => image). - nixpkgs.lib.genAttrs [ - "ai_i3" - "ai_hyprland" - ] + packages."${x64_system}" = lib.attrsets.mergeAttrsList [ ( + # lib.genAttrs [ "foo" "bar" ] (name: "x_" + name) + # => { foo = "x_foo"; bar = "x_bar"; } + nixpkgs.lib.genAttrs + [ + "ai_i3" + "ai_hyprland" + ] # generate iso image for hosts with desktop environment - host: - self.nixosConfigurations.${host}.config.formats.iso + (host: self.nixosConfigurations.${host}.config.formats.iso) ) - // nixpkgs.lib.genAttrs [ - "aquamarine" - "ruby" - "kana" - ] + ( + nixpkgs.lib.genAttrs + [ + "aquamarine" + "ruby" + "kana" + ] # generate proxmox image for virtual machines without desktop environment - host: - self.nixosConfigurations.${host}.config.formats.proxmox - ); + (host: self.nixosConfigurations.${host}.config.formats.proxmox) + ) + ]; }