aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/turris-defaults.nix
blob: 01c3deb4b35713ad5708e68b6da8e51ee0b28c23 (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
{ config, lib, pkgs, ... }:

with lib;

let

  cnf = config.turris.defaults;

in {

  options = {
    turris.defaults = {
      enable = mkOption {
        type = types.bool;
        default = true;
        description = "Use default Turris configuration";
      };
      rootLabel = mkOption {
        type = types.str;
        default = "NixTurris";
        description = "GPT partition label the root system is stored on";
      };
      swapLabel = mkOption {
        type = types.str;
        default = "NixTurrisSwap";
        description = "GPT partition label for available swap parition";
      };
    };
  };

  config = mkIf cnf.enable {
    # We do not need Grub as U-Boot supports boot using extlinux like file
    boot.loader.grub.enable = mkDefault false;
    boot.loader.generic-extlinux-compatible.enable = mkDefault true;
    # Use early print to the serial console
    boot.kernelParams = [
      "boot.shell_on_fail"
    ] ++ optionals (config.turris.board == "mox") [
      "earlycon=ar3700_uart,0xd0012000" "console=ttyMV0,115200"
      "pcie_aspm=off" # Fix for crashes due to SError Interrupt on ath10k load
    ] ++ optionals (config.turris.board == "omnia") [
      "earlyprintk" "console=ttyS0,115200"
    ];

    # Use the latest kernel
    boot.kernelPackages = mkDefault pkgs.linuxPackages_latest;
    #boot.kernelPackages = mkDefault (if (config.turris.board == "mox") then
    #  pkgs.linuxPackages_latest
    #else
    #  pkgs.linuxPackages_5_15);

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

    # Cover nix memory consumption peaks by compressing the RAM
    zramSwap = {
      enable = true;
      memoryPercent = 80;
    };
    # Nix is really memory hungry so we have to sometimes also use swap device.
    swapDevices = [{
      device = "/dev/disk/by-partlabel/" + cnf.swapLabel;
      priority = 0;
    }];

    fileSystems = {
      "/" = {
        device = "/dev/disk/by-partlabel/" + cnf.rootLabel;
        fsType = "btrfs";
      };
    };

    # The default hostname
    networking.hostName = mkDefault "nixturris";

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

    # The additional administration packages
    environment.systemPackages =  with pkgs; [
      htop
    ] ++ optionals (config.turris.board == "mox") [
      mox-otp
    ] ++ optionals (config.turris.board == "omnia") [
      libatsha204
    ];

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