class qdii::base {
  # Command line
  package { [
    'curl',
    'cscope',
    'fakeroot',
    'fwupd',
    'fzf',
    'git',
    'jq',
    'lsof',
    'mosh',
    'nmap',
    'net-tools',
    'powerline',
    'ripgrep',
    'sed',
    'sudo',
    'tcpdump',
    'traceroute',
    'zoxide',
    'zsh-syntax-highlighting',
  ]:
    ensure => installed
  }

  if ($::operatingsystem == 'ArchLinux') {
    package { [
      'cronie',
      'nix',
      'rxvt-unicode',
      'yay',
    ]: ensure => installed }
    service { 'cronie':
      ensure  => 'running',
      enable  => true,
      require => Package['cronie'],
    }
  }

  if ($::operatingsystem == 'Debian') or ($::operatingsystem == 'Ubuntu') {
    package { [
      'bsdmainutils',
      'cron',
      'nix-bin',
      'python3-pygments',
      'silversearcher-ag',
    ]: ensure => installed
    }
    service { 'cron':
      ensure  => 'running',
      require => Package['cron'],
    }
  }

  if $::fqdn == 'limo.dodges.it' {
    package { [
      'acpi',
      'audacity',
      'fcitx',
      'fcitx-libpinyin',
      'fcitx-im',
      'gimp',
      'nextcloud-client',
      'pipewire-pulse',
      'vlc',
      'xorg-xev',
    ]:
      ensure => installed
    }
  }

  if $::fqdn !~ /.*\.google\.com$/ {
    file { '/etc/sudoers.d/qdii':
      ensure =>  file,
      source => 'puppet:///modules/qdii/dotfiles/sudoers',
    }
    file { "$qdii::homedir/.ssh":
      ensure => directory,
    }
    -> file { "$qdii::homedir/.ssh/authorized_keys":
      ensure => file,
      source => 'puppet:///modules/qdii/misc/authorized_keys',
    }
  }
  file { '/usr/share/X11/xkb/symbols':
    ensure => directory,
  } ->
  file { '/usr/share/X11/xkb/symbols/fr':
    ensure => file,
    source => 'puppet:///modules/qdii/misc/xkb.fr',
  } ->
  file { '/usr/share/X11/xkb/rules/base.lst':
    ensure => file,
    source => 'puppet:///modules/qdii/misc/base.lst',
  }
  if $::fqdn == 'limo.dodges.it' {
    file { 'refind.conf':
      ensure => file,
      path   => '/efi/EFI/refind/refind.conf',
      source => 'puppet:///modules/qdii/dotfiles/refind.conf',
      owner  => 'root',
      mode   => '0644',
    }
  }
  if $qdii::at_work == false {
    class { 'locales':
      default_locale  => 'en_US.UTF-8',
      locales         => [
        'de_DE.UTF-8 UTF-8',
        'en_US.UTF-8 UTF-8',
        'es_ES.UTF-8 UTF-8',
        'fr_FR.UTF-8 UTF-8'
      ],
    }
  }
  file { "qdii_config_dir":
    path   => "$qdii::homedir/.config",
    ensure => directory,
    owner  => 'qdii',
  }
  -> file { "$qdii::homedir/.config/powerline":
    ensure => directory,
    owner  => 'qdii',
  }
  -> file { "$qdii::homedir/.config/powerline/config.json":
    ensure => file,
    source => 'puppet:///modules/qdii/dotfiles/powerline-config.json',
    owner  => 'qdii',
  }
  file { "$qdii::homedir/.config/fontconfig":
    ensure => directory,
    require => File['qdii_config_dir'],
    owner  => 'qdii',
  }
  if $qdii::at_work {
    $suffix = '.work'
  } else {
    $suffix = '.perso'
  }
  file { "environment-directory":
    ensure  => "directory",
    path    => "$qdii::homedir/.config/environment.d",
    owner   => "qdii",
    require => File['qdii_config_dir'],
  }
  -> file { "environment.d":
    ensure => "file",
    path   => "$qdii::homedir/.config/environment.d/10-qdii.conf",
    source => "puppet:///modules/qdii/misc/environment.d.perso",
    owner  => "qdii",
  }
  if $::fqdn == 'limo.dodges.it' {
    file { "sigtop":
      source => 'puppet:///modules/qdii/misc/sigtop',
      owner  => 'qdii',
      path   => '/usr/local/bin/sigtop',
      mode   => '0777',
    }
    file { "backup-signal":
      source => 'puppet:///modules/qdii/misc/backup-signal',
      owner  => 'qdii',
      path   => '/usr/local/bin/backup-signal',
      mode   => '0777',
    }
    systemd::timer{'backup-signal.timer':
      timer_source   => 'puppet:///modules/qdii/misc/backup-signal.timer',
      service_source => 'puppet:///modules/qdii/misc/backup-signal.service',
      active         => true,
      enable         => true,
    }
  }
  if $qdii::is_server {
    if ($::operatingsystem == 'Debian') or ($::operatingsystem == 'Ubuntu') {
      $ethtool = '/usr/sbin/ethtool'
    } else {
      $ethtool = '/usr/bin/ethtool'
    }
    $wol_iface = $facts['networking']['primary']
    # cron { 'enable_wake_on_lan':
    #   ensure  => 'present',
    #   command => "$ethtool -s $wol_iface wol g",
    #   user    => 'root',
    #   special => 'reboot',
    # }
  }

  file { 'nix_config_dir_user':
    ensure  => directory,
    path    => "$qdii::homedir/.config/nix",
    owner   => 'qdii',
    require => File['qdii_config_dir'],
  }
  -> file { 'nix_config_file_user':
    ensure => file,
    path   => "$qdii::homedir/.config/nix/nix.conf",
    source => 'puppet:///modules/qdii/dotfiles/nix.conf',
    owner  => 'qdii',
  }
}
