From 003c08cb096051b104e71dcc8bdb4f5cbfb95608 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 29 May 2021 20:28:27 +0200 Subject: [PATCH] modules: system: nix: make it configurable --- modules/system/nix.nix | 46 ++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/modules/system/nix.nix b/modules/system/nix.nix index bfde967..0f2f8c3 100644 --- a/modules/system/nix.nix +++ b/modules/system/nix.nix @@ -1,19 +1,35 @@ # Nix related settings -{ inputs, pkgs, ... }: - +{ config, inputs, lib, pkgs, ... }: +let + cfg = config.my.system.nix; +in { - nix = { - package = pkgs.nixFlakes; - registry = { - # Allow me to use my custom package using `nix run self#pkg` - self.flake = inputs.self; - # Use pinned nixpkgs when using `nix run pkgs#` - pkgs.flake = inputs.nixpkgs; - # Add NUR to run some packages that are only present there - nur.flake = inputs.nur; - }; - extraOptions = '' - experimental-features = nix-command flakes - ''; + options.my.system.nix = with lib; { + enable = my.mkDisableOption "nix configuration"; + + addToRegistry = my.mkDisableOption "add inputs and self to registry"; }; + + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + nix = { + package = pkgs.nixFlakes; + + extraOptions = '' + experimental-features = nix-command flakes + ''; + }; + } + + (lib.mkIf cfg.addToRegistry { + nix.registry = { + # Allow me to use my custom package using `nix run self#pkg` + self.flake = inputs.self; + # Use pinned nixpkgs when using `nix run pkgs#` + pkgs.flake = inputs.nixpkgs; + # Add NUR to run some packages that are only present there + nur.flake = inputs.nur; + }; + }) + ]); }