aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/turris-board.nix
blob: 4b8aa0df9ed9887a79c54de3fe83d7615d3e6c2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{ config, lib, pkgs, ... }:

with lib;

{

  options = {
    turris.board = mkOption {
      type = types.enum [ "omnia" "mox" ];
      description = "The unique Turris board identifier.";
    };

    turris.device = mkOption {
      type = types.str;
      example = "/dev/mmcblk0";
      description = "The device used to boot the Turris system.";
    };
  };

  config = {
    assertions = [{
      assertion = config.turris.board != null;
      message = "Turris board has to be specified";
    }];

    # We do not need Grub as U-Boot supports boot using extlinux like file
    boot.loader.grub.enable = false;
    boot.loader.generic-extlinux-compatible.enable = true;
    # Use early print to the serial console
    boot.kernelParams = [
      "earlyprintk" "console=ttyMV0,115200" "earlycon=ar3700_uart,0xd0012000"
      "boot.shell_on_fail"
    ];

    # Use the latest kernel
    boot.kernelPackages = pkgs.linuxPackages_latest;

    # The supported deployment is on BTRFS
    boot.supportedFilesystems = [ "btrfs" ];

    # Cover nix memory consumption peaks by compressing the RAM
    zramSwap = {
      enable = true;
      memoryPercent = 100;
    };
    # Nix is really memory hungry so we have to sometimes also use swap device.
    # We expect that to be the second partition on the root device.
    swapDevices = [{
      device = config.turris.device + "p2";
      priority = 0;
    }];

    fileSystems = {
      # Root filesystem is expected to be on:
      # Mox: SD card
      # Omnia: internam MMC storage
      "/" = {
        device = config.turris.device + "p1";
        fsType = "btrfs";
      };
    };

    # The default hostname
    # TODO set this only if not already set
    networking.hostName = "nixturris";

    # Enable flakes for nix as we are using that instead of legacy setup
    nix = {
      package = pkgs.nixFlakes;
      extraOptions = "experimental-features = nix-command flakes";
    };

    # Allow root access over SSH
    # TODO allow disable as it is nice only for initial setup
    services.openssh = {
      enable = true;
      passwordAuthentication = true;
      permitRootLogin = "yes";
    };

    # Set default editor
    # TODO probably switch to nano later on
    programs.vim.defaultEditor = true;

    # The additional administration packages
    environment.systemPackages =  with pkgs; [
      (pkgs.nixos-rebuild.override { nix = config.nix.package.out; })
      git # This is required to access the repository
      htop
    ];

    # No need for installer tools in standard system
    system.disableInstallerTools = true;
  };
}