From 4adc24b8bfe013f3f9ed84955a1f04b32031eb8a Mon Sep 17 00:00:00 2001 From: NullBite Date: Wed, 14 Feb 2024 10:33:09 +0100 Subject: [PATCH] Add nix.nix with nix-related options --- system/common/default.nix | 1 + system/common/nix.nix | 57 +++++++++++++++++++++++++++++++++++++++ system/profile/base.nix | 18 +++++-------- 3 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 system/common/nix.nix diff --git a/system/common/default.nix b/system/common/default.nix index 84e16c5..2ce7502 100644 --- a/system/common/default.nix +++ b/system/common/default.nix @@ -5,5 +5,6 @@ ./me.nix ./remote.nix ./wm.nix + ./nix.nix ]; } diff --git a/system/common/nix.nix b/system/common/nix.nix new file mode 100644 index 0000000..784fcb9 --- /dev/null +++ b/system/common/nix.nix @@ -0,0 +1,57 @@ +{ pkgs, lib, config, options, inputs, ... }: +let + cfg = config.nixfiles.common.nix; +in +{ + options.nixfiles.common.nix = { + enable = lib.mkEnableOption "common Nix configuration"; + registerNixpkgs = lib.mkOption { + type = lib.types.bool; + default = cfg.enable; + example = "true"; + description = "Whether to register the Nixpkgs revision used by Nixfiles to the system's flake registry and make it tye system's channel"; + }; + /* # TODO + register = lib.mkOption { + type = lib.types.bool; + default = cfg.enable; + example = "true"; + description = "Whether to register Nixfiles to the system's flake registry"; + }; + */ + }; + + config = lib.mkMerge [ + ( lib.mkIf cfg.registerNixpkgs { + + # this makes modern nix tools use the system's version of nixpkgs + nix.registry = { + nixpkgs = { + exact = true; + from = { + id = "nixpkgs"; + type = "indirect"; + }; + flake = inputs.nixpkgs; + }; + }; + + # this makes comma and legacy nix utils use the flake nixpkgs for ABI + # compatibility becasue once `, vkcube` couldn't find the correct opengl + # driver or something (also it reduces the download size of temporary shell + # closures) + nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ] ++ options.nix.nixPath.default; + }) + ( lib.mkIf cfg.enable { + + # direnv is a tool to automatically load shell environments upon entering + # a directory. nix-direnv has an extensionn to keep nix shells in the + # system's gcroots so shells can be used after a gc without rebuilding. + programs.direnv.enable = lib.mkDefault true; + + # fallback to building locally if binary cache fails (home-manager should be + # able to handle simple rebuilds offline) + nix.settings.fallback = lib.mkDefault true; + }) + ]; +} diff --git a/system/profile/base.nix b/system/profile/base.nix index 73bb8d6..6949445 100644 --- a/system/profile/base.nix +++ b/system/profile/base.nix @@ -11,8 +11,12 @@ in config = lib.mkMerge [ (lib.mkIf cfg.enable { - # Enable my account - nixfiles.common.me.enable = lib.mkDefault true; + nixfiles.common = { + # Enable my account + me.enable = lib.mkDefault true; + # Enable system Nix configuration + nix.enable = lib.mkDefault true; + }; # locale settings i18n = { @@ -25,10 +29,6 @@ in # Enable flakes nix.settings.experimental-features = ["nix-command" "flakes" ]; - # fallback to building locally if binary cache fails (home-manager should be - # able to handle simple rebuilds offline) - nix.settings.fallback = true; - # Allow unfree packages nixpkgs.config.allowUnfree = true; @@ -83,12 +83,6 @@ in programs.neovim.defaultEditor = lib.mkDefault true; - # this makes comma and legacy nix utils use the flake nixpkgs for ABI - # compatibility becasue once `, vkcube` couldn't find the correct opengl - # driver or something (also it reduces the download size of temporary shell - # closures) - nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ] ++ options.nix.nixPath.default; - programs.ssh.enableAskPassword = lib.mkDefault false; programs.fuse.userAllowOther = lib.mkDefault true;