From 1379670cd947e29bf246562626585b532cb13048 Mon Sep 17 00:00:00 2001 From: NullBite Date: Sun, 21 Apr 2024 12:24:48 -0400 Subject: [PATCH] Add nix configuration for home-manager This ensures home-manager devices use the the already downloaded nixpkgs for ad-hoc commands like nix-shell and comma, as well as adds this flake to the registry (currently assumed to be located at ~/nixfiles, I should make this configurable later) --- home/common/default.nix | 1 + home/common/nix.nix | 45 +++++++++++++++++++++++++++++++++++++++++ home/profile/base.nix | 1 + 3 files changed, 47 insertions(+) create mode 100644 home/common/nix.nix diff --git a/home/common/default.nix b/home/common/default.nix index 7a094ae..f16e801 100644 --- a/home/common/default.nix +++ b/home/common/default.nix @@ -3,5 +3,6 @@ imports = [ ./wm.nix ./nodm.nix + ./nix.nix ]; } diff --git a/home/common/nix.nix b/home/common/nix.nix new file mode 100644 index 0000000..b76cf6f --- /dev/null +++ b/home/common/nix.nix @@ -0,0 +1,45 @@ +{ pkgs, lib, config, osConfig ? { }, options, nixpkgs, ... }: +let + cfg = config.nixfiles.common.nix; + standalone = !(osConfig ? home-manager); +in { + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + nix.registry = { + nixfiles = { + exact = true; + from = { + id = "nixfiles"; + type = "indirect"; + }; + to = { + type = "git"; + url = "file://${config.home.homeDirectory}/nixfiles"; + }; + }; + }; + } + + (lib.mkIf standalone { + home.sessionVariables.NIX_PATH = "nixpkgs=${nixpkgs}\${NIX_PATH:+:\${NIX_PATH}}"; + nix.registry = { + nixpkgs = { + exact = true; + from = { + id = "nixpkgs"; + type = "indirect"; + }; + to = { + type = "github"; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "${nixpkgs.rev}"; + }; + }; + }; + }) + ]); + options.nixfiles.common.nix = { + enable = lib.mkEnableOption "Nix configuration"; + }; +} diff --git a/home/profile/base.nix b/home/profile/base.nix index b50468a..6ac2d65 100644 --- a/home/profile/base.nix +++ b/home/profile/base.nix @@ -15,6 +15,7 @@ in config = lib.mkIf cfg.enable { nixfiles.programs.comma.enable = true; + nixfiles.common.nix.enable = true; home.sessionVariables = lib.mkMerge [ (lib.mkIf config.programs.neovim.enable {