From 56992b8c945d497a623fe693847c91235be1ae02 Mon Sep 17 00:00:00 2001 From: sefidel Date: Tue, 28 Dec 2021 01:11:25 +0900 Subject: initial commit --- nixos/modules/cachix/caches/nix-community.nix | 12 ++++++++++ nixos/modules/cachix/default.nix | 13 ++++++++++ nixos/modules/default.nix | 5 ++++ nixos/modules/flake.nix | 12 ++++++++++ nixos/modules/nix.nix | 34 +++++++++++++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 nixos/modules/cachix/caches/nix-community.nix create mode 100644 nixos/modules/cachix/default.nix create mode 100644 nixos/modules/default.nix create mode 100644 nixos/modules/flake.nix create mode 100644 nixos/modules/nix.nix (limited to 'nixos/modules') diff --git a/nixos/modules/cachix/caches/nix-community.nix b/nixos/modules/cachix/caches/nix-community.nix new file mode 100644 index 0000000..2b4c408 --- /dev/null +++ b/nixos/modules/cachix/caches/nix-community.nix @@ -0,0 +1,12 @@ +{ config, lib, ... }: + +{ + nix = { + binaryCaches = [ + "https://nix-community.cachix.org" + ]; + binaryCachePublicKeys = [ + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + ]; + }; +} diff --git a/nixos/modules/cachix/default.nix b/nixos/modules/cachix/default.nix new file mode 100644 index 0000000..38ad575 --- /dev/null +++ b/nixos/modules/cachix/default.nix @@ -0,0 +1,13 @@ +{ config, pkgs, lib, ... }: +let + folder = ./caches; + toImport = name: value: folder + ("/" + name); + filterCaches = key: value: value == "regular" && lib.hasSuffix ".nix" key; + imports = lib.mapAttrsToList toImport (lib.filterAttrs filterCaches (builtins.readDir folder)); +in +{ + inherit imports; + nix.binaryCaches = [ "https://cache.nixos.org/" ]; + + environment.systemPackages = [ pkgs.cachix ]; +} diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix new file mode 100644 index 0000000..f17f392 --- /dev/null +++ b/nixos/modules/default.nix @@ -0,0 +1,5 @@ +{ + cachix = import ./cachix; + flake = import ./flake.nix; + nix = import ./nix.nix; +} diff --git a/nixos/modules/flake.nix b/nixos/modules/flake.nix new file mode 100644 index 0000000..a88f9d0 --- /dev/null +++ b/nixos/modules/flake.nix @@ -0,0 +1,12 @@ +{ config, pkgs, lib, ... }: + +{ + options.nix.flakes.enable = lib.mkEnableOption "nix flakes"; + + config = lib.mkIf config.nix.flakes.enable { + nix = { + package = pkgs.nixUnstable; + experimentalFeatures = "nix-command flakes"; + }; + }; +} diff --git a/nixos/modules/nix.nix b/nixos/modules/nix.nix new file mode 100644 index 0000000..04fafac --- /dev/null +++ b/nixos/modules/nix.nix @@ -0,0 +1,34 @@ +{ config, lib, ... }: + +let + allowed = config.nix.allowedUnfree; +in +{ + options.nix = { + experimentalFeatures = lib.mkOption { + type = lib.types.separatedString " "; + default = ""; + description = '' + Enables experimental features + ''; + }; + + allowedUnfree = lib.mkOption { + type = lib.types.listOf lib.types.string; + default = [ ]; + description = '' + Allows for unfree packages by their name. + ''; + }; + }; + + config = lib.mkMerge [ + (lib.mkIf (config.nix.experimentalFeatures != "") { nix.extraOptions = "experimental-features = ${config.nix.experimentalFeatures}"; }) + (lib.mkIf (allowed != [ ]) { nixpkgs.config.allowUnfreePredicate = (pkg: __elem (lib.getName pkg) allowed); }) + { nix.autoOptimiseStore = lib.mkDefault true; } + { + nix.gc.automatic = lib.mkDefault true; + nix.gc.options = lib.mkDefault "--delete-older-than 10d"; + } + ]; +} -- cgit 1.4.1