Skip to content

Instantly share code, notes, and snippets.

@ingenieroariel
Last active January 24, 2019 18:08
Show Gist options
  • Save ingenieroariel/0b9b022d4bfa3ba5e3d2709871a09ce3 to your computer and use it in GitHub Desktop.
Save ingenieroariel/0b9b022d4bfa3ba5e3d2709871a09ce3 to your computer and use it in GitHub Desktop.
#[root@nuc:/etc/nixos]# cat configuration.nix
{ config, lib, pkgs, ... }:
{
imports =
[ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
./qemu.nix
];
boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" "sdhci_pci" ];
boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ];
fileSystems."/" =
{ device = "/dev/disk/by-label/nixos";
fsType = "btrfs";
};
fileSystems."/d" =
{ device = "/dev/disk/by-label/data";
fsType = "btrfs";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-label/boot";
fsType = "vfat";
};
swapDevices = [ ];
nix.maxJobs = lib.mkDefault 8;
powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
boot.loader.grub.useOSProber = true;
system.stateVersion = "18.09";
nixpkgs.config = {
allowUnfree = true;
};
environment.systemPackages = with pkgs; [
git
wget vim tmux htop git ripgrep unzip
tcpdump telnet openssh
gnumake gcc libcxx libcxxabi llvm ninja clang
python3 nodejs nodePackages.node2nix go
firefox kmail vscode vlc
blender godot gimp inkscape
libreoffice
];
networking.networkmanager.enable = true;
networking.nameservers = [ "8.8.8.8" ];
networking.hostName = "nuc";
networking.firewall.allowedTCPPortRanges = [
{ from = 5432; to = 5432; }
{ from = 9000; to = 9000; }
];
networking.firewall.allowPing = true;
time.timeZone = "America/Bogota";
i18n = {
consoleFont = "lat9w-16";
defaultLocale = "en_US.UTF-8";
};
sound.enable = true;
hardware.pulseaudio.enable = true;
hardware.bluetooth.enable = true;
services.xserver.enable = true;
services.xserver.displayManager.sddm.enable = true;
services.xserver.displayManager.sddm.autoLogin.enable = true;
services.xserver.displayManager.sddm.autoLogin.user = "x";
services.xserver.desktopManager.plasma5.enable = true;
services.sshd.enable = true;
virtualisation.libvirtd.enable = true;
services.minio = {
enable = true;
accessKey = "";
secretKey = "";
dataDir = "/d/";
listenAddress = "0.0.0.0:9000";
};
users.users.x = {
isNormalUser = true;
home = "/x";
extraGroups = ["networkmanager" "libvirtd"];
};
qemu-user.riscv = true;
}
diff --git a/configuration.nix b/configuration.nix
index fb13aa6..0b12b96 100644
--- a/configuration.nix
+++ b/configuration.nix
@@ -3,6 +3,7 @@
{
imports =
[ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
+ ./qemu.nix
];
boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" "sdhci_pci" ];
@@ -87,11 +88,14 @@
dataDir = "/d/";
listenAddress = "0.0.0.0:9000";
};
-
+
users.users.x = {
isNormalUser = true;
home = "/x";
extraGroups = ["networkmanager" "libvirtd"];
};
+
+ qemu-user.riscv = true;
+
}
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.qemu-user;
arm = {
interpreter = "${pkgs.qemu-user-arm}/bin/qemu-arm";
magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'';
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff'';
};
aarch64 = {
interpreter = "${pkgs.qemu-user-arm64}/bin/qemu-aarch64";
magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00'';
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff'';
};
riscv64 = {
interpreter = "${pkgs.qemu-riscv}/bin/qemu-riscv64";
magicOrExtension = ''\x7fELF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf3\x00'';
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff'';
};
in {
options = {
qemu-user = {
arm = mkEnableOption "enable 32bit arm emulation";
aarch64 = mkEnableOption "enable 64bit arm emulation";
riscv64 = mkEnableOption "enable 64bit riscv emulation";
};
nix.supportedPlatforms = mkOption {
type = types.listOf types.str;
description = "extra platforms that nix will run binaries for";
default = [];
};
};
config = mkIf (cfg.arm || cfg.aarch64) {
nixpkgs = {
overlays = [ (import ./overlays/qemu-user.nix) ];
};
boot.binfmtMiscRegistrations =
optionalAttrs cfg.arm { inherit arm; } //
optionalAttrs cfg.aarch64 { inherit aarch64; } //
optionalAttrs cfg.riscv64 { inherit riscv64; };
nix.supportedPlatforms = (optionals cfg.arm [ "armv6l-linux" "armv7l-linux" ])
++ (optional cfg.aarch64 "aarch64-linux");
nix.extraOptions = ''
extra-platforms = ${toString config.nix.supportedPlatforms} i686-linux
'';
nix.sandboxPaths = [ "/run/binfmt" ] ++ (optional cfg.arm "${pkgs.qemu-user-arm}") ++ (optional cfg.aarch64 "${pkgs.qemu-user-arm64}");
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment