diff --git a/system/hardware/binfmt.nix b/system/hardware/binfmt.nix new file mode 100644 index 0000000..bf30dd7 --- /dev/null +++ b/system/hardware/binfmt.nix @@ -0,0 +1,35 @@ +{ pkgs, config, lib, ... }: +let + + configForSystem = (system: + let + riscv = [ "riscv32-linux" "riscv64-linux" ]; + arm = [ "armv6l-linux" "armv7l-linux" "aarch64-linux" ]; + x86 = [ "i686-linux" "x86_64-linux" ]; + windows = [ "x86_64-windows" "i686-windows" ]; + systems = { + x86_64-linux = riscv ++ arm ++ windows; + aarch64-linux = riscv; + }; + in + if (systems ? "${system}") then systems."${system}" else [] + ); + emulatedSystems = configForSystem "${pkgs.system}"; + cfg = config.nixfiles.binfmt; +in +{ + options.nixfiles.binfmt = { + enable = lib.mkOption { + description = "Whether to configure default binfmt emulated systems for the current architecture"; + type = lib.types.bool; + default = false; + example = true; + }; + }; + + config = lib.mkMerge [ + (lib.mkIf (cfg.enable && (builtins.length emulatedSystems) > 0) { + boot.binfmt = {inherit emulatedSystems;}; + }) + ]; +} diff --git a/system/hardware/default.nix b/system/hardware/default.nix index 2b2c44c..a7e71c8 100644 --- a/system/hardware/default.nix +++ b/system/hardware/default.nix @@ -5,5 +5,6 @@ ./nvidia.nix ./opengl.nix ./sound.nix + ./binfmt.nix ]; } diff --git a/system/profile/base.nix b/system/profile/base.nix index 6949445..4692438 100644 --- a/system/profile/base.nix +++ b/system/profile/base.nix @@ -17,6 +17,7 @@ in # Enable system Nix configuration nix.enable = lib.mkDefault true; }; + nixfiles.binfmt.enable = true; # locale settings i18n = {