From fc8ae06a0694c226ece6db85e5e207b6151d399b Mon Sep 17 00:00:00 2001 From: Dmitriy Kholkin Date: Sun, 2 Mar 2025 14:35:26 +0300 Subject: [PATCH] feat: new 'nix' module with some good defaults --- modules/nixos/default.nix | 11 ++++-- modules/nixos/nix/default.nix | 65 +++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 modules/nixos/nix/default.nix diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index facb35d..c352385 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -1,4 +1,11 @@ -{ ... }: +{ lib, ... }: +let + inherit (lib) filterAttrs; + inherit (builtins) attrNames readDir; + moduleDirs = + dir: + map (name: dir + "/${name}") (attrNames (filterAttrs (_: type: type == "directory") (readDir dir))); +in { - + imports = moduleDirs ./.; } diff --git a/modules/nixos/nix/default.nix b/modules/nixos/nix/default.nix new file mode 100644 index 0000000..a2b76f8 --- /dev/null +++ b/modules/nixos/nix/default.nix @@ -0,0 +1,65 @@ +{ + config, + lib, + inputs, + flake-self, + ... +}: +let + inherit (lib) mkEnableOption mkIf; + cfg = config.ataraxia.defaults.nix; +in +{ + options.ataraxia.defaults.nix = { + enable = mkEnableOption "Nix defaults"; + }; + + config = mkIf cfg.enable { + environment.etc.nixpkgs.source = config.nixpkgs.flake.source; + environment.etc.self.source = flake-self.outPath; + nix = { + channel.enable = false; + extraOptions = '' + keep-outputs = true + keep-derivations = true + # Prevent Nix from fetching the registry every time + flake-registry = ${inputs.flake-registry}/flake-registry.json + ''; + gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 90d"; + }; + registry.ataraxia.flake = flake-self; + settings = { + auto-optimise-store = true; + experimental-features = [ + "nix-command" + "flakes" + ]; + require-sigs = true; + substituters = [ + "https://cache.nixos.org" + "https://nix-community.cachix.org" + "https://hyprland.cachix.org" + "https://ataraxiadev-foss.cachix.org" + "https://numtide.cachix.org" + "https://devenv.cachix.org" + ]; + trusted-public-keys = [ + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=" + "ataraxiadev-foss.cachix.org-1:ws/jmPRUF5R8TkirnV1b525lP9F/uTBsz2KraV61058=" + "numtide.cachix.org-1:2ps1kLBUWjxIneOy1Ik6cQjb41X0iXVXeHigGmycPPE=" + "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=" + ]; + trusted-users = [ + "root" + "deploy" + "@wheel" + ]; + }; + }; + }; +}