aboutsummaryrefslogtreecommitdiff
path: root/configuration.nix
blob: 979c3d1db3d999f3cd67e485c69c40c7030f38fb (about) (plain) (blame)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
{ config, pkgs, ... }:

let
  log-redirect = name: ">> /tmp/cron-dbg.${name}.euandreh.log 2>&1";
  cron-for-name = prefix: name: cron:
    "${cron} andreh ${prefix}/${name}.sh ${log-redirect name}";
  daily-at-12h30min = "30 12 * * *";
  every-x-hours = "0 * * * *";
  pub-crons = {
    no-mail = { deliver-enqueued-emails = every-x-hours; };

    with-mail = {
      report-summary = "30 13 * * *";

      sync-mail = daily-at-12h30min;
      job-annex = daily-at-12h30min;
      job-repo-update = daily-at-12h30min;
      job-notmuch-dump = daily-at-12h30min;
      job-mbox-archive = daily-at-12h30min;
      job-copy-box-backups = daily-at-12h30min;
      job-run-local-backup = daily-at-12h30min;
      job-mr-remotes-backup = daily-at-12h30min;
    };
  };
  priv-crons = { pacheco = "0 12 5 * *"; };
  crons = builtins.attrValues
    (builtins.mapAttrs (cron-for-name "/home/andreh/dev/libre/dotfiles/cron")
      pub-crons.no-mail) ++ builtins.attrValues (builtins.mapAttrs
        (cron-for-name "/home/andreh/dev/libre/dotfiles/cron/generated")
        pub-crons.with-mail) ++ builtins.attrValues
    (builtins.mapAttrs (cron-for-name "/home/andreh/annex/cron") priv-crons);
  privateConfiguration = import /etc/nixos/private-configuration.nix;
  proprietaryPackages = with pkgs; [ slack zoom-us openfortivpn skype chromium ];
  allowUnfree = builtins.length proprietaryPackages > 0;
in {
  imports = [ # Include the results of the hardware scan.
    /etc/nixos/hardware-configuration.nix
  ];

  # Use the systemd-boot EFI boot loader.
  boot = {
    loader = {
      systemd-boot.enable = true;
      efi.canTouchEfiVariables = true;
    };
    initrd.luks.devices = {
      crypted = {
        device = "/dev/nvme0n1p2";
        preLVM = true;
      };
    };
  };

  hardware = {
    bluetooth = { enable = true; };
    pulseaudio = {
      package = pkgs.pulseaudioFull;
      enable = true;
      extraModules = [ pkgs.pulseaudio-modules-bt ];
      extraConfig = ''
        # Switch between headset and headphone mode (e.g. for calls and music) automatically
        load-module module-bluetooth-policy auto_switch=2
        # Echo cancellation and noise cleanup of mic
        load-module module-echo-cancel aec_method=webrtc

        # https://til.flourishing.stream/2020/05/24/cancelamento-de-ruido-pulseaudio/
        ### Enable Echo/Noise-Cancellation
        load-module module-echo-cancel use_master_format=1 aec_method=webrtc aec_args="analog_gain_control=0\ digital_gain_control=1" source_name=echoCancel_source sink_name=echoCancel_sink
        set-default-source echoCancel_source
        set-default-sink echoCancel_sink
      '';
    };
  };

  networking = {
    hostName = "usurpador-nixos";
    networkmanager.enable = true;
  };

  system.autoUpgrade = {
    enable = true;
    channel = "https://nixos.org/channels/nixos-unstable";
  };

  console = {
    keyMap = "br-abnt2";
    font = "Lat2-Terminus16";
  };

  # Select internationalisation properties.
  i18n = { defaultLocale = "fr_FR.UTF-8"; };

  # Set your time zone.
  time.timeZone = "America/Sao_Paulo";

  fonts.fonts = with pkgs; [
    source-code-pro
    fira-code
    fira-mono
    fira-code-symbols
    freefont_ttf
    symbola
  ];

  documentation = {
    enable = true;
    man.enable = true;
    dev.enable = true;
    man.generateCaches = true;
  };

  environment = {
    enableDebugInfo = true;

    systemPackages = let
      bmake-with-alias = pkgs.bmake.overrideAttrs (oldAttrs: {
        postInstall = ''
          ln -s $out/bin/bmake $out/bin/make
        '';
      });
      tinycc-with-posix-alias = pkgs.tinycc.overrideAttrs (oldAttrs: {
        postInstall = ''
          ln -s $out/bin/tcc $out/bin/c99
        '';
      });
      flex-with-posix-alias = pkgs.flex.overrideAttrs (oldAttrs: {
        postInstall = ''
          ln -s $out/bin/flex $out/bin/lex
        '';
      });
      pax-with-good-path = pkgs.pax.overrideAttrs (oldAttrs: {
        postPatch = ''
          substituteInPlace ar_io.c --replace 'putenv' '// putenv'
          ${({ postPatch = ""; } // oldAttrs).postPatch}
        '';
      });

      nu-packages = with pkgs; [
        awscli
        yubioath-desktop
        leiningen
        openjdk8
        clojure # =clj=
        kubernetes
        nssTools # =pk12util=
        python3
      ];

    in with pkgs;
    [
      ## Documentation
      posix_man_pages
      scheme-manpages

      ## Personal data tools
      gitAndTools.git-open
      gitAndTools.gitFull
      gitAndTools.git-annex
      gitAndTools.gitRemoteGcrypt
      git-crypt
      git-lfs
      mr
      borgbackup
      pass
      gnupg
      pinentry_gtk2
      fossil
      mercurial

      ## CLI tools
      groff
      mktorrent
      diffoscope
      bundix
      bash-completion
      nix-bash-completions
      youtube-dl
      wget
      tmux
      tmuxinator
      sox # =play=, SoX - Sound eXchange
      gettext
      rlwrap
      jq
      rq
      openvpn
      xclip
      psmisc # =killall=
      xorg.xkill
      gksu
      tree
      unzip # used by extract bash function and Clojure go-to-source
      feh
      nixUnstable # =nix=
      bind # =dig=
      rsync
      moreutils # =vipe=, =sponge=
      graphviz # =dot= and others
      graph-easy # ASCII drawings for GraphViz output
      mkpasswd
      direnv
      recutils
      sqlite
      trash-cli
      entr
      mailutils
      ffmpeg-full
      ledger
      gnuplot
      ranger
      electrum
      zathura
      st
      pavucontrol
      newsboat
      acpi
      xsel
      pinentry
      nixfmt
      # nvi # broken, now using the one from Guix
      fzf
      calcurse
      pandoc
      buku # replaces Firefox bookmarks
      cloc
      inetutils # telnet
      nodePackages.node2nix
      lsof
      lsscsi
			bpytop

      ## Mail
      isync
      notmuch
      afew
      alot
      w3m
      urlscan

      ## Conversations
      gomuks
      weechat # replacing ERC
      poezio

      ## Programming tools
      perl
      shellcheck
      mrsh
      dash
      gcc
      clang
      clang-tools
      valgrind
      gdb
      scdoc
      sbcl

      ## POSIX
      bmake-with-alias
      byacc
      bc
      pax-with-good-path
      lzip
      flex-with-posix-alias
      gnugrep
      file
      ed
      tinycc-with-posix-alias
      m4
      llvmPackages.bintools # ar, nm and friends
      units

      ## Containers and VMs
      qemu
      expect

      ## xmonad
      xorg.xmodmap
      xorg.xmessage
      dmenu
      escrotum
      xorg.xbacklight
      playerctl
      lightdm
      fvwm # =xpmroot=
      haskellPackages.xmobar
      arandr
      alsaUtils # for xmonad volume commands
      yad

      ## EuAndreh overlay
      xyz-euandreh.remembering-latest
      xyz-euandreh.autoqemu-latest

      ## GUI programs
      audacity
      zbar
      calibre
      (mpv-with-scripts.override {
        scripts = with mpvScripts; [ mpris sponsorblock ];
      })
      firefox

      ## Desktop programs
      cmus
      mutagen

      ## Candidates to be replaced by alternatives
      transmission-gtk # https://github.com/btpd/btpd
      tdesktop # telegram -> gomuks
    ] ++ proprietaryPackages ++ nu-packages;
  };

  nixpkgs = {
    config = {
      android_sdk.accept_license = allowUnfree;
      allowUnfree = allowUnfree;
    };
    overlays = let
      version = "main";
      use-local = false;
      euandreh-nixpkgs = import (if use-local then
        ../package-repository/default.nix
      else
        fetchTarball {
          url =
            "https://git.euandreh.xyz/package-repository/snapshot/package-repository-${version}.tar.gz";

        }) { inherit pkgs; };
    in [ euandreh-nixpkgs ];
  };

  # Look at
  # https://www.vivaolinux.com.br/topico/Off-Code-Cafe/Me-apresente-sua-distro

  programs = {
    bash.enableCompletion = true;
    autojump.enable = true;
    msmtp = {
      enable = true;
      extraConfig = builtins.readFile /home/andreh/.config/msmtp/config;
      setSendmail = false;
    };
  };

  xdg.portal.enable = true;
  services = {

    mail.sendmailSetuidWrapper = {
      program = "sendmail";
      source = "${pkgs.msmtp}/bin/msmtpq";
      setuid = false;
      setgid = false;
    };

    blueman.enable = true;

    # We can see the actual generated crontab at /etc/crontab
    cron = {
      enable = true;
      systemCronJobs = crons;
    };

    logrotate = {
      enable = true;
      extraConfig = ''
        compress

        /tmp/*.euandreh.log {
          rotate 5
          daily
          olddir /home/andreh/archive/logs/cron/
          createolddir 744 andreh users
          su andreh users
        }

        /home/andreh/.bash_history {
          rotate 30
          daily
          olddir /home/andreh/archive/bash_history/
          createolddir 744 andreh users
          su andreh users
        }
      '';
    };

    xserver = {
      enable = true;
      layout = "br";
      xkbOptions = "caps:swapescape";

      # Touchpad support
      libinput.enable = true;

      config = ''
        Section "Device"
          Identifier  "Intel Graphics"
          Driver      "intel01"
          Option      "Backlight"  "intel_backlight"
        EndSection
      '';

      windowManager.xmonad = {
        enable = true;
        enableContribAndExtras = true;
      };
      desktopManager = { xterm.enable = false; };
      displayManager = {
        defaultSession = "none+xmonad";

        lightdm.enable = true;

        # The config inception was inspired by:
        # http://ubuntuforum-br.org/index.php?topic=13784.0
        # Lambda symbol name taken from:
        # http://wiki.linuxquestions.org/wiki/List_of_Keysyms_Recognised_by_Xmodmap
        # To test a keycode:
        # xmodmap -e 'keycode 118 = bar Greek_lamda'
        sessionCommands = ''
          ${pkgs.fvwm}/bin/xpmroot  ~/annex/docs/emotion.png &
        '';
      };
    };

    pcscd.enable = true; # required by yubioath
  };

  security = {
    sudo.enable = true;
    doas = {
      enable = true;
      extraConfig = ''
        permit persist setenv { NIX_PATH } :wheel
      '';
    };
  };

  users = {
    extraUsers = let
      andrehUser = {
        andreh = {
          isNormalUser = true;
          uid = 1000;
          description = "EuAndreh";
          extraGroups = [ "wheel" "networkmanager" "docker" ];
        };
      };
      # From the Guix manual:
      # https://www.gnu.org/software/guix/manual/en/html_node/Build-Environment-Setup.html#Build-Environment-Setup
      buildUser = (i: {
        "guixbuilder${i}" = { # guixbuilder$i
          group = "guixbuild"; # -g guixbuild
          extraGroups = [ "guixbuild" ]; # -G guixbuild
          home = "/var/empty"; # -d /var/empty
          shell = pkgs.nologin; # -s `which nologin`
          description = "Guix build user ${i}"; # -c "Guix buid user $i"
          isSystemUser = true; # --system
        };
      });
      # merge all users
    in pkgs.lib.fold (str: acc: acc // buildUser str) andrehUser
    # for i in `seq -w 1 10`
    (map (pkgs.lib.fixedWidthNumber 2) (builtins.genList (n: n + 1) 10));

    extraGroups.guixbuild = { name = "guixbuild"; };
  };

  systemd = {
    services = {
      # Derived from Guix guix-daemon.service.in
      # https://git.savannah.gnu.org/cgit/guix.git/tree/etc/guix-daemon.service.in?id=00c86a888488b16ce30634d3a3a9d871ed6734a2
      guix-daemon = {
        enable = true;
        description = "Build daemon for GNU Guix";
        serviceConfig = {
          ExecStart =
            "/var/guix/profiles/per-user/root/current-guix/bin/guix-daemon --build-users-group=guixbuild";
        };
        wantedBy = [ "multi-user.target" ];
      };
    };
    user.services = {
      mpris-proxy = {
        enable = true;
        description = "Mpris proxy, added to support bluetooth media keys";
        serviceConfig = {
          After = [ "network.target" "sound.target" ];
          ExecStart = "${pkgs.bluez}/bin/mpris-proxy";
          WantedBy = [ "default.target" ];
        };
      };
    };
  };

  # This value determines the NixOS release with which your system is to be
  # compatible, in order to avoid breaking some software such as database
  # servers. You should change this only after NixOS release notes say you
  # should.
  system.stateVersion = "20.03"; # Did you read the comment?
}