dotfiles

My PC Dotfiles & Website

modules/system/nix.nix (2960B)


  1## Nix Configuration ##
  2{inputs, ...}: {
  3  flake.modules = {
  4    nixos.nix = {
  5      config,
  6      lib,
  7      pkgs,
  8      ...
  9    }: let
 10      inherit (lib) mkEnableOption mkIf;
 11    in {
 12      options.system.nix = {
 13        tools = mkEnableOption "Enable Additional Nix Tools";
 14        index = mkEnableOption "Enable Package Indexer";
 15      };
 16
 17      config = {
 18        nix = {
 19          # Version
 20          package = pkgs.nixFlakes;
 21
 22          settings = {
 23            sandbox = true;
 24            auto-optimise-store = true;
 25
 26            # User Permissions
 27            allowed-users = [
 28              "root"
 29              "@wheel"
 30            ];
 31            trusted-users = [
 32              "root"
 33              "@wheel"
 34            ];
 35
 36            # Binary Cache
 37            inherit
 38              ((import ../../flake.nix).nixConfig)
 39              substituters
 40              trusted-substituters
 41              trusted-public-keys
 42              ;
 43          };
 44
 45          # Garbage Collection
 46          gc = {
 47            automatic = true;
 48            dates = "weekly";
 49            options = "--delete-older-than 7d";
 50          };
 51
 52          extraOptions = ''
 53            accept-flake-config = true
 54            warn-dirty = false
 55            experimental-features = nix-command flakes recursive-nix
 56            min-free = ${builtins.toString (1024 * 1024 * 1024)}
 57            max-free = ${builtins.toString (10 * 1024 * 1024 * 1024)}
 58          '';
 59
 60          # Registry
 61          nixPath = ["/etc/nix/inputs"];
 62          registry = builtins.mapAttrs (_: value: {flake = value;}) (
 63            lib.filterAttrs (_: value: value ? outputs) inputs
 64          );
 65        };
 66
 67        nixpkgs.flake = {
 68          setNixPath = false;
 69          setFlakeRegistry = false;
 70        };
 71
 72        environment.etc =
 73          lib.mapAttrs' (name: value: {
 74            name = "nix/inputs/${name}";
 75            value = {
 76              source = value.outPath;
 77            };
 78          })
 79          inputs;
 80
 81        ## Tools
 82        nix.settings.system-features = mkIf config.system.nix.tools [
 83          "kvm"
 84          "big-parallel"
 85          "recursive-nix"
 86        ];
 87
 88        environment.systemPackages = mkIf config.system.nix.tools (
 89          with pkgs; [
 90            cachix
 91            dix
 92            manix
 93            alejandra
 94            nix-output-monitor
 95            prettier
 96            shellcheck
 97            statix
 98          ]
 99        );
100      };
101    };
102
103    ## Package Indexer
104    homeManager.nix = {
105      lib,
106      osConfig ? null,
107      ...
108    }: let
109      enable =
110        if osConfig != null
111        then osConfig.system.nix.index
112        else false;
113    in {
114      imports = [inputs.index.homeModules.nix-index];
115
116      home.persist.directories = [
117        ".cache/nix"
118        ".cache/manix"
119      ];
120
121      programs = {
122        nix-index.enable = lib.mkForce enable;
123        nix-index-database.comma.enable = lib.mkForce enable;
124      };
125    };
126  };
127}