ctucx.git: nixfiles

ctucx' nixfiles

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 
{ inputs, pkgs, config, lib, ... }:

let
  devices = {
    #mobile devices
    blechkasten.id    = "HGPWBVY-RD4JKBQ-X3V53IB-KRVDXEQ-4YLN5F2-WPPSMYR-SOXGTY6-IDFOAAC";
    coladose.id       = "BNCAOEB-CYTYIBA-ZKFJKRB-DX4C3MT-SDH7IWQ-5EI35PJ-YUIJSYH-COCGUAW";
    seifenkiste.id    = "6YZT5PZ-EKXZBMV-C2MJL75-OCQ36LC-L3QIRPW-VJ5EU3C-2ICZDDO-IZ7IGAO";

    iphone.id         = "3SM3LJV-XMHYW2D-MU5WQ3T-KGYUJOI-LXOL6YI-BSVZ2B5-QJ6GVXN-MPWMKQ7";

    #servers
    hector = {
      name = "hector.ctu.cx";
      id   = "MVGBPSX-YSZNBDO-E7HZFGJ-WULYWQ5-XDHVMJO-BKA4R37-GPPRLLS-Z5DQMQJ";
    };
    wanderduene = {
      name = "wanderduene.ctu.cx";
      id   = "WEFYARN-GY3WZXB-TIXBI56-ZZ77AHS-GFH5SH2-Q35NTBI-VPT3OEM-EQNAMQH";
    };
    briefkasten = {
      name = "briefkasten.home.ctu.cx";
      id   = "QI2EPUE-4VMZ3XV-LXX3GXP-RHCWTRY-AACLSGL-YG7MIYV-THST74N-KJGIBQ6";
    };
  };

  enabledShares = {
    blechkasten = [
      "Blechelse"
    ];

    briefkasten = [
      "ctucx-music-orig"
      "ctucx-media"
      "Blechelse"
      "YouTube"
    ];
  };

  deviceNames       = builtins.attrNames (lib.filterAttrs isCurrentHost devices);
  shareDeviceNames  = share: builtins.attrNames (lib.filterAttrs (n: v: builtins.elem share v) enabledShares);

  filterCurrentHost = devices: lib.remove config.networking.hostName devices;

  isCurrentHost     = n: v: n != config.networking.hostName;
  isShareEnabled    = share:
    if builtins.hasAttr config.networking.hostName enabledShares then
      (if builtins.elem share enabledShares.${config.networking.hostName} then true else false)
    else
      false;

  dataDir            = config.services.syncthing.dataDir;

in {

  dataDir = dataDir;

  devices = (lib.mkMerge [ (lib.filterAttrs isCurrentHost devices)]);

  folders = {

    "${dataDir}/Audiobooks" = {
      enable            = lib.mkDefault true;
      id                = "ctucx-audiobooks";
      label             = "Audiobooks";
      devices           = deviceNames;
      versioning.type   = "trashcan";
      versioning.params = {
        cleanoutDays = "3";
      };
    };

    "${dataDir}/Documents" = {
      enable            = lib.mkDefault true;
      id                = "ctucx-documents";
      label             = "Documents";
      devices           = deviceNames;
      versioning.type   = "trashcan";
      versioning.params = {
        cleanoutDays = "3";
      };
    };

    "${dataDir}/Music" = {
      enable            = lib.mkDefault true;
      id                = "ctucx-music";
      label             = "Music";
      devices           = deviceNames;
      versioning.type   = "trashcan";
      versioning.params = {
        cleanoutDays = "3";
      };
    };

    "${dataDir}/Music (Originals)" = rec {
      enable            = lib.mkDefault (isShareEnabled "${id}");
      id                = "ctucx-music-orig";
      label             = "Music (Originals)";
      devices           = filterCurrentHost (shareDeviceNames "${id}");
      versioning.type   = "trashcan";
      versioning.params = {
        cleanoutDays = "3";
      };
    };

    "${dataDir}/Pictures" = {
      enable            = lib.mkDefault true;
      id                = "ctucx-pictures";
      label             = "Pictures";
      devices           = deviceNames;
      versioning.type   = "trashcan";
      versioning.params = {
        cleanoutDays = "3";
      };
    };

    "${dataDir}/Videos" = {
      enable            = lib.mkDefault true;
      id                = "ctucx-videos";
      label             = "Videos";
      devices           = deviceNames;
      versioning.type   = "trashcan";
      versioning.params = {
        cleanoutDays = "3";
      };
    };

    "${dataDir}/Media (legacy)" = rec {
      enable            = lib.mkDefault (isShareEnabled "${id}");
      id                = "ctucx-media";
      label             = "Media (legacy)";
      devices           = filterCurrentHost (shareDeviceNames "${id}");
      versioning.type   = "trashcan";
      versioning.params = {
        cleanoutDays = "3";
      };
    };




    "${dataDir}/Bahn-Richtlinien" = {
      enable            = lib.mkDefault true;
      id                = "Bahn-Richtlinien";
      label             = "Bahn-Richtlinien";
      devices           = (lib.mkMerge [ deviceNames]);
      versioning.type   = "trashcan";
      versioning.params = {
        cleanoutDays = "3";
      };
    };

    "${dataDir}/Bahn-Blechelse" = rec {
      enable            = lib.mkDefault true;
      id                = "Blechelse";
      label             = "Bahn-Blechelse";
      devices           = (lib.mkMerge [ (filterCurrentHost (shareDeviceNames "${id}"))]);
      versioning.type   = "trashcan";
      versioning.params = {
        cleanoutDays = "3";
      };
    };

  };
}