From d05b910886d8e998661480414525b0fde860643e Mon Sep 17 00:00:00 2001 From: Julien Malka Date: Sat, 1 Jan 2022 19:16:42 +0100 Subject: [PATCH] Trying to add new machine --- flake.nix | 8 ++++++- lib/default.nix | 4 ++-- machines/lisa/default.nix | 1 + rpi.nix | 45 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 rpi.nix diff --git a/flake.nix b/flake.nix index b489496..f4e89d5 100644 --- a/flake.nix +++ b/flake.nix @@ -31,6 +31,7 @@ outputs = { self, home-manager, nixpkgs, unstable, sops-nix, neovim-nightly-overlay, nur, ... }@inputs: let pkgs = import nixpkgs { system = "x86_64-linux"; }; + pkgsrpi = import nixpkgs { system = "aarch64-linux";}; lib = nixpkgs.lib.extend (import ./lib inputs); in with lib; @@ -42,10 +43,15 @@ }) (builtins.attrNames (builtins.readDir ./modules))); - nixosConfigurations = builtins.mapAttrs (name: value: (mkMachine name value self.nixosModules)) (importConfig ./machines); + nixosConfigurations = builtins.mapAttrs (name: value: (mkMachine {host=name; host-config=value; modules=self.nixosModules;})) (importConfig ./machines) // + {"lambda" = mkMachine { host = "lambda"; host-config = import ./rpi.nix; modules=self.nixosModules; system="aarch64-linux";};}; packages."x86_64-linux" = { tinystatus = import ./packages/tinystatus { inherit pkgs; }; mosh = pkgs.callPackage ./packages/mosh {}; }; + packages."aarch64-linux" = { + tinystatus = import ./packages/tinystatus { pkgs = pkgsrpi; }; + mosh = pkgsrpi.callPackage ./packages/mosh {}; + }; }; } diff --git a/lib/default.nix b/lib/default.nix index 8f0597d..0e79722 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -9,9 +9,9 @@ let in { - mkMachine = host: host-config: modules: nixpkgs.lib.nixosSystem { + mkMachine = {host, host-config, modules, system ? "x86_64-linux"}: nixpkgs.lib.nixosSystem { lib = final; - system = "x86_64-linux"; + system = system; specialArgs = { inherit inputs; }; diff --git a/machines/lisa/default.nix b/machines/lisa/default.nix index 7351de2..26bb2d4 100644 --- a/machines/lisa/default.nix +++ b/machines/lisa/default.nix @@ -33,6 +33,7 @@ }; nix.maxJobs = lib.mkDefault 4; + boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; services.fail2ban.enable = true; diff --git a/rpi.nix b/rpi.nix new file mode 100644 index 0000000..eef55be --- /dev/null +++ b/rpi.nix @@ -0,0 +1,45 @@ +{ config, pkgs, lib, ... }: +{ + # NixOS wants to enable GRUB by default + boot.loader.grub.enable = false; + + # if you have a Raspberry Pi 2 or 3, pick this: + boot.kernelPackages = pkgs.linuxPackages_latest; + + # A bunch of boot parameters needed for optimal runtime on RPi 3b+ + boot.kernelParams = ["cma=256M"]; + boot.loader.raspberryPi.enable = true; + boot.loader.raspberryPi.version = 3; + boot.loader.raspberryPi.uboot.enable = true; + boot.loader.raspberryPi.firmwareConfig = '' + gpu_mem=256 + ''; + environment.systemPackages = with pkgs; [ + libraspberrypi + tinystatus + ]; + + # File systems configuration for using the installer's partition layout + fileSystems = { + "/" = { + device = "/dev/disk/by-label/NIXOS_SD"; + fsType = "ext4"; + }; + }; + + # Preserve space by sacrificing documentation and history + documentation.nixos.enable = false; + nix.gc.automatic = true; + nix.gc.options = "--delete-older-than 30d"; + boot.cleanTmpDir = true; + + # Configure basic SSH access + services.openssh.enable = true; +# services.openssh.permitRootLogin = "yes"; + + # Use 1GB of additional swap memory in order to not run out of memory + # when installing lots of things while running other things at the same time. + swapDevices = [ { device = "/swapfile"; size = 1024; } ]; + + luj.hmgr.julien = {}; +}