summaryrefslogtreecommitdiff
path: root/modules/shared/defaults/nix.nix
blob: 9c59f104068de7c219eae463482feb4c8d0513d4 (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
{
  config,
  lib,
  pkgs,
  inputs,
  ...
}:
let
  inherit (pkgs.stdenv.hostPlatform) isLinux;

  # TODO: remove this nonsense when all implementations remove repl-flake
  hasReplFlake =
    lib.versionOlder config.nix.package.version "2.22.0" # repl-flake was removed in nix 2.22.0
    || (
      lib.versionAtLeast config.nix.package.version "2.90.0"
      && lib.versionOlder config.nix.package.version "2.91.0"
    ); # but not until lix 2.91

  hasAlwaysAllowSubstitutes = lib.versionAtLeast config.nix.package.version "2.19.0";
in
{
  config = lib.mkMerge [
    {
      nix = {
        settings = {
          auto-optimise-store = lib.mkDefault isLinux;
          experimental-features = [
            "nix-command"
            "flakes"
            "auto-allocate-uids"
          ];

          extra-trusted-substituters = [
            "https://getchoo.cachix.org"
            "https://nix-community.cachix.org"
          ];

          extra-trusted-public-keys = [
            "getchoo.cachix.org-1:ftdbAUJVNaFonM0obRGgR5+nUmdLMM+AOvDOSx0z5tE="
            "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
          ];
        };

        gc = {
          automatic = lib.mkDefault true;
          options = lib.mkDefault "--delete-older-than 5d";
        };

        registry = lib.mapAttrs (lib.const (flake: {
          to = lib.mkDefault {
            type = "path";
            path = flake.outPath;
          };
        })) inputs;

        nixPath = lib.mapAttrsToList (name: lib.const "${name}=flake:${name}") inputs;
      };

      nixpkgs = {
        config.allowUnfree = lib.mkDefault true;
      };
    }

    (lib.mkIf hasReplFlake {
      nix.settings.experimental-features = [ "repl-flake" ];
    })

    (lib.mkIf hasAlwaysAllowSubstitutes {
      nix.settings.always-allow-substitutes = true;
    })
  ];
}