summaryrefslogtreecommitdiff
path: root/modules/nixfiles/common/nix/default.nix
blob: f6c75ba9e0a4c0395ea84e19f6280e4cd5a998fe (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
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
{
  config,
  inputs,
  lib,
  pkgs,
  pkgsLocal,
  pkgsMaster,
  pkgsPR,
  pkgsRev,
  pkgsStabe,
  this,
  ...
}:
with lib; {
  _module.args = let
    importNixpkgs = nixpkgs:
      import nixpkgs {inherit (config.nixpkgs) config localSystem;};
  in rec {
    pkgsLocal = importNixpkgs "${config.my.home}/src/nixpkgs"; # Impure!
    pkgsMaster = importNixpkgs inputs.nixpkgs-master;
    pkgsStable = importNixpkgs inputs.nixpkgs-stable;
    pkgsRev = rev: hash:
      importNixpkgs (pkgs.fetchFromGitHub {
        owner = "NixOS";
        repo = "nixpkgs";
        inherit rev hash;
      });
    pkgsPR = pr: pkgsRev "refs/pull/${toString pr}/head";
  };

  nix = let
    filteredInputs = filterAttrs (n: _: n != "self") inputs;
  in {
    # https://github.com/NixOS/nix/blob/master/src/libutil/experimental-features.cc
    extraOptions = ''
      max-jobs = auto
      warn-dirty = false
      flake-registry = ${inputs.flake-registry}/flake-registry.json
      extra-experimental-features = ca-derivations
      extra-experimental-features = flakes
      extra-experimental-features = nix-command
      extra-experimental-features = recursive-nix
      keep-going = true
      keep-derivations = ${
        if this.isHeadful
        then "true"
        else "false"
      }
      keep-outputs = ${
        if this.isHeadful
        then "true"
        else "false"
      }
    '';

    nixPath =
      mapAttrsToList (n: v: "${n}=${v}") filteredInputs
      ++ ["nixfiles=${config.my.home}/src/nixfiles"];

    registry =
      mapAttrs (_: flake: {inherit flake;}) filteredInputs
      // {nixfiles.flake = inputs.self;};

    settings = {
      trusted-users = ["root" "@wheel"];

      substituters = [
        "https://azahi.cachix.org"
        "https://cachix.cachix.org"
        "https://nix-community.cachix.org"
        "https://pre-commit-hooks.cachix.org"
      ];
      trusted-public-keys = [
        "azahi.cachix.org-1:2bayb+iWYMAVw3ZdEpVg+NPOHCXncw7WMQ0ElX1GO3s="
        "cachix.cachix.org-1:eWNHQldwUO7G2VkjpnjDbWwy4KQ/HNxht7H4SSoMckM="
        "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
        "pre-commit-hooks.cachix.org-1:Pkk3Panw5AW24TOv6kz3PvLhlH8puAsJTBbOPmBo7Rc="
      ];
    };
  };

  nixpkgs.overlays = with inputs; [
    self.overlays.default
    (_: super:
      {
        nix-bash-completions = super.nix-bash-completions.overrideAttrs (_: _: {
          postPatch = ''
            substituteInPlace _nix \
              --replace 'nix nixos-option' 'nixos-option'
          '';
        });

        helm = with super;
          kubernetes-helm-wrapped.override {
            plugins = with kubernetes-helmPlugins; [helm-secrets];
          };

        alejandra = super.alejandra.overrideAttrs (_: _: {
          patches = [./patches/alejandra-no-ads.patch];
        });
      }
      // (with super; let
        np = nodePackages;
      in {
        # Normalises package names. This is done purely for aesthetics.
        css-language-server = np.vscode-css-languageserver-bin;
        dockerfile-language-server = np.dockerfile-language-server-nodejs;
        editorconfig = editorconfig-core-c;
        go-language-server = gopls;
        html-language-server = np.vscode-html-languageserver-bin;
        inherit (np) bash-language-server;
        inherit (np) vim-language-server;
        inherit (np) yaml-language-server;
        json-language-server = np.vscode-json-languageserver-bin;
        k3d = kube3d;
        lua-language-server = sumneko-lua-language-server;
        nix-language-server = rnix-lsp;
        omnisharp = omnisharp-roslyn;
        tor-browser = tor-browser-bundle-bin;
      }))
    agenix.overlay
    emacs-overlay.overlay
    # nil.overlays.default
    # nix-minecraft-servers.overlays.default
    nur.overlay
    # pollymc.overlay
    xmonad-ng.overlays.default
  ];

  system = {
    stateVersion = builtins.readFile "${inputs.nixpkgs}/.version";

    extraDependencies = with inputs; [
      nixos-hardware
      nixpkgs
      nixpkgs-master
      nixpkgs-stable
      nur
    ];
  };

  environment = {
    sessionVariables.NIX_SHELL_PRESERVE_PROMPT = "1";

    localBinInPath = true;

    defaultPackages = [];
    systemPackages = with pkgs;
      optionals this.isHeadful [
        nix-du
        nix-top
        nix-tree
      ];
  };

  hm.home = {
    packages = with pkgs; [nix-index];

    file.".nix-defexpr/default.nix".text =
      optionalString this.isHeadful
      (
        let
          hostname = strings.escapeNixIdentifier this.hostname;
        in ''
          let
            self = builtins.getFlake "nixfiles";
            configurations = self.nixosConfigurations;
            local = configurations.${hostname};
          in rec {
            inherit self;
            inherit (self) inputs lib;
            inherit (lib) my;
            this = my.configurations.${hostname};
            inherit (local) config;
            inherit (local.config.system.build) toplevel vm vmWithBootLoader manual;
          } // configurations // local._module.args
        ''
      );
  };
}