# Edit this configuration file which defines what would be installed on the
# system.  To Help while choosing option value, you can watch at the manual
# page of configuration.nix or at the last chapter of the manual available
# on the virtual console 8 (Alt+F8).

{config, pkgs, ...}:

{
  require = [
    # Include the configuration for part of your system which have been
    # detected automatically.
    ./hardware-configuration.nix
  ];

  boot = {
    initrd.checkJournalingFS = false;

    initrd.kernelModules = [
      # Specify all kernel modules that are necessary for mounting the root
      # file system.
      #
      # "ext4" "ata_piix"
    ];    

    loader.grub = {
      # Use grub 2 as boot loader.
      enable = true;
      version = 2;
  
      # Define on which hard drive you want to install Grub.
      device = "/dev/sdb";

      memtest86 = true;
    };

    postBootCommands = "${pkgs.cryptsetup}/sbin/cryptsetup create -d /dev/urandom cswap /dev/vg_angel/swap && mkswap /dev/mapper/cswap && swapon /dev/mapper/cswap";
  };

  networking = {
    hostName = "angel-nixos"; # Define your hostname.
#    defaultGateway = "192.168.2.1";
#    wireless.enable = true;
#    extraHosts = "192.168.2.111 printer";
#    interfaces =
#     [ { ipAddress = "192.168.3.2";
#         name = "wlan0";
#         subnetMask = "255.255.255.0";
#       }
#       { ipAddress = "192.168.6.1";
#         name = "eth1";
#         subnetMask = "255.255.255.0";
#       }
#    ];
#    nameservers = [ "192.168.2.1" ];
    useDHCP = true;
    # interfaceMonitor.enable = true; # Watch for plugged cable.
  };

  # Add file system entries for each partition that you want to see mounted
  # at boot time.  You can add filesystems which are not mounted at boot by
  # adding the noauto option.
  fileSystems = [
    # Mounted at boot.
    { mountPoint = "/";
      device = "/dev/vg_angel/NixOS64Root";
      fsType = "ext3";
    }
    { mountPoint = "/d/angel-big";
      device = "/dev/vg_angel/Big";
      fsType = "ext3";
    }
    { mountPoint = "/home";
      device = "/dev/vg_angel/Home";
      fsType = "ext3";
    }
    { mountPoint = "/tmp";
      device = "tmpfs";
      fsType = "tmpfs";
    }

    # Not mounted at boot.
    { mountPoint = "/d/angel-sec";
      device = "/dev/mapper/angel-sec";
      options = "noauto";
    }
    { mountPoint = "/d/d9";
      device = "/dev/disk/by-label/d9";
      options = "noauto";
    }
    { mountPoint = "/d/debian64";
      device = "/dev/vg_angel/Debian64Root";
      options = "noauto";
    }
    {
      mountPoint = "/d/elbow-big";
      device = "/dev/vg_elbow/Big";
      options = "noauto";
    }
    { mountPoint = "/d/flake-ext";
      device = "/dev/disk/by-label/FlakeExt";
      options = "noauto";
    }
    { mountPoint = "/d/flake-fat";
      device = "/dev/disk/by-label/FlakeFat";
      options = "noauto";
    }
    { mountPoint = "/d/flake-sec";
      device = "/dev/mapper/flake-sec";
      options = "noauto";
    }
    { mountPoint = "/d/nexs-fat";
      device = "/dev/disk/by-label/NEXSFAT";
      options = "noauto";
    }
    { mountPoint = "/d/nexs-sec";
      device = "/dev/mapper/nexs-sec";
      options = "noauto";
    }
    { mountPoint = "/d/waals-root";
      device = "/dev/vg_waals/WaalsRoot";
      options = "noauto";
    }
    { mountPoint = "/d/waals-sec";
      device = "/dev/mapper/waals-sec";
      options = "noauto";
    }
  ];

  swapDevices = [
    # List swap partitions that are mounted at boot time.
    #
    # { device = "/dev/sda1"; }
  ];

  security =
  { pam.services = [ { name = "xscreensaver"; } ];
    sudo.configFile = "root ALL=(ALL) SETENV: ALL\n%wheel ALL=(ALL) NOPASSWD: SETENV: ALL\n";
  };

  # Select internationalisation properties.
  i18n = {
  #   consoleFont = "lat9w-16";
  #   consoleKeyMap = "us";
    defaultLocale = "en_CA.UTF-8";
  };

  # List services that you want to enable:
  services =
  { 
    dhcpd =
    { enable = true;
      extraConfig = "\nsubnet 192.168.6.0 netmask 255.255.255.0 {\nrange 192.168.6.10 192.168.6.19;\n}\n";
      interfaces = [ "eth1" ];
      machines =
      [ { ethernetAddress = "00:1a:6b:38:4a:6b";
          hostName = "glider";
          ipAddress = "192.168.6.2";
        }
      ];
    };
    nixosManual =
    { showManual = true;
    };
    openssh =
    { enable = true;
      ports = [ 22 7549 ];
    };
    #printing =
    #{ cupsdConf = ''
    #    LogLevel debug
    #  '';
    #  drivers = [ pkgs.samsungUnifiedLinuxDriver ];
    #  enable = true;
    #};
    ttyBackgrounds.enable = false;
    xserver =
    { enable = true;
      #config = pkgs.lib.mkOverride 50 (builtins.readFile ./xorg.conf);
      layout = "us";
    #  deviceSection = ''Option "TwinView"'';
    #  exportConfiguration = true;
      desktopManager.xfce.enable = true;
      #videoDrivers = [ "nvidia" ];
    };
  };

  hardware.enableAllFirmware = true;

  time.timeZone = "America/Los_Angeles";

  fonts =
  {
    enableCoreFonts = true;
    enableGhostscriptFonts = true;
    extraFonts = [ pkgs.wqy_zenhei ];
  };

}

