srid / nixos-flake

A flake-parts module to manage NixOS and macOS machines, along with home-manager support, in a unified fashion.
https://community.flake.parts/nixos-flake
MIT License
175 stars 19 forks source link

How to get support for more NixOS architectures #26

Closed brsvh closed 1 year ago

brsvh commented 1 year ago

Presently, when using mkLinuxSystem, the system parameter is look like hardcoded to x86_64-linux.

https://github.com/srid/nixos-flake/blob/d54b31a542f9d34e051f434806b607e70835adb1/flake-module.nix#L124-L129

What should I do if I desire to create host configurations for other architectures like aarch64-linux?

I am try to use nixpkgs.lib.makeOverridable and then update system attribute, but I don't know if that's right because I am Nix noob.

I have noticed that the darwin generator has a system parameter, and I think it might be possible to add a similar parameter to mkLinuxSystem and set a default value to x86_64-linux to keep compatibility with existed configurations.

srid commented 1 year ago

I have noticed that the darwin generator has a system parameter, and I think it might be possible to add a similar parameter to mkLinuxSystem and set a default value to x86_64-linux to keep compatibility with existed configurations.

Sounds good to me, PR welcome!

srid commented 1 year ago

Alternatively, or in addition, we can expose the specialArgsFor set from lib.

brsvh commented 1 year ago

I am not certain about the specific implementation details. To implement the goal of passing system, mod (imports), and specialArgs to mkLinuxSystem, it would be necessary to pass an attribute set when calling the function. This might introduce some potential break changes that I initially wanted to avoid.

And it doesn't look different from using nixpkgs.lib.nixosSystem directly.

In fact, I just discovered a few hours ago that setting default values for function parameters is only possible within an attribute set (Maybe it can be set via the let scope, but it doesn't matter).

srid commented 1 year ago

nixos-flake's API is not stablized, so it is fine to introduce breaking changes.

And it doesn't look different from using nixpkgs.lib.nixosSystem directly.

Hence, exposing the specialArgsFor set from lib should be sufficient. Then you can just use

inputs.nixpkgs.lib.nixosSystem { 
   system = "aarch64-linux"; 
   specialArgs = inputs.nixpkgs.nixos-flake.lib.specialArgsFor.nixos; 
   modules = [ ({
    # My configuration ...
   }) ]; 
 }; 
srid commented 1 year ago

Hence, exposing the specialArgsFor set from lib should be sufficient. Then you can just use

inputs.nixpkgs.lib.nixosSystem { 
   system = "aarch64-linux"; 
   specialArgs = inputs.nixpkgs.nixos-flake.lib.specialArgsFor.nixos; 
   modules = [ ({
    # My configuration ...
   }) ]; 
 }; 

I've implemented this in fed6487

srid commented 1 year ago

https://github.com/srid/nixos-flake/pull/28

srid commented 1 year ago

df6fe273ff64dc29de2c93805045b5348d70bc26