From d6a63ed7e5ce4bd34290eb2ef3de7ba75607b09b Mon Sep 17 00:00:00 2001 From: chn Date: Mon, 11 Aug 2025 12:26:57 +0800 Subject: [PATCH] init aarch64 support --- devices/r2s/default.nix | 23 +++++++++++++++++++++++ flake/lib/buildNixpkgsConfig/default.nix | 6 +++--- flake/nixos.nix | 3 +-- modules/model.nix | 1 + modules/system/nixpkgs.nix | 5 ++++- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/devices/r2s/default.nix b/devices/r2s/default.nix index e69de29b..87304b33 100644 --- a/devices/r2s/default.nix +++ b/devices/r2s/default.nix @@ -0,0 +1,23 @@ +inputs: +{ + config = + { + nixos = + { + model.arch = "aarch64"; + system = + { + fileSystems = + { + mount.btrfs."/dev/disk/by-partlabel/r2s-root" = { "/nix" = "/nix"; "/nix/rootfs/current" = "/"; }; + swap = [ "/nix/swap/swap" ]; + }; + network = {}; + }; + services = + { + sshd = {}; + }; + }; + }; +} diff --git a/flake/lib/buildNixpkgsConfig/default.nix b/flake/lib/buildNixpkgsConfig/default.nix index bef11f24..6a67f789 100644 --- a/flake/lib/buildNixpkgsConfig/default.nix +++ b/flake/lib/buildNixpkgsConfig/default.nix @@ -1,12 +1,12 @@ -# inputs = { lib, topInputs, ...}; nixpkgs = { march, cuda, nixRoot, nixos }; +# inputs = { lib, topInputs, ...}; nixpkgs = { march, cuda, nixRoot, nixos, arch }; { inputs, nixpkgs }: let platformConfig = - if nixpkgs.march == null then { system = "x86_64-linux"; } + if nixpkgs.march == null then { system = "${nixpkgs.arch or "x86_64"}-linux"; } else { ${if nixpkgs.nixos then "hostPlatform" else "localSystem"} = - { system = "x86_64-linux"; gcc = { arch = nixpkgs.march; tune = nixpkgs.march; }; }; + { system = "${nixpkgs.arch or "x86_64"}-linux"; gcc = { arch = nixpkgs.march; tune = nixpkgs.march; }; }; }; cudaConfig = inputs.lib.optionalAttrs (nixpkgs.cuda != null) ( diff --git a/flake/nixos.nix b/flake/nixos.nix index 8f98eaa8..3401525e 100644 --- a/flake/nixos.nix +++ b/flake/nixos.nix @@ -2,7 +2,6 @@ let singles = [ "nas" "pc" "vps4" "vps6" "one" "srv3" ]; cluster = { srv1 = 3; srv2 = 2; }; - arch.r2s = "aarch64"; deviceModules = builtins.listToAttrs ( (builtins.map @@ -28,7 +27,7 @@ let in builtins.mapAttrs (n: v: inputs.nixpkgs.lib.nixosSystem { - system = "${arch.${n} or "x86_64"}-linux"; + system = null; specialArgs = { topInputs = inputs; inherit localLib; }; modules = localLib.mkModules v; }) diff --git a/modules/model.nix b/modules/model.nix index 2bff7dc0..672e8af7 100644 --- a/modules/model.nix +++ b/modules/model.nix @@ -3,6 +3,7 @@ inputs: options.nixos.model = let inherit (inputs.lib) mkOption types; in { hostname = mkOption { type = types.nonEmptyStr; }; + arch = mkOption { type = types.nonEmptyStr; default = "x86_64"; }; type = mkOption { type = types.enum [ "minimal" "desktop" "server" ]; default = "minimal"; }; private = mkOption { type = types.bool; default = false; }; cluster = mkOption diff --git a/modules/system/nixpkgs.nix b/modules/system/nixpkgs.nix index a94603d2..adda0699 100644 --- a/modules/system/nixpkgs.nix +++ b/modules/system/nixpkgs.nix @@ -16,7 +16,10 @@ inputs: config = let inherit (inputs.config.nixos.system) nixpkgs; in { nixpkgs = inputs.localLib.buildNixpkgsConfig - { inherit inputs; nixpkgs = nixpkgs // { nixRoot = null; nixos = true; }; }; + { + inherit inputs; + nixpkgs = nixpkgs // { nixRoot = null; nixos = true; inherit (inputs.config.nixos.model) arch; }; + }; boot.kernelPatches = inputs.lib.mkIf (nixpkgs.march != null) [{ name = "native kernel";