{ config, pkgs, lib, ... }: let inherit (lib) mkOption types; rootChannelsPath = "/nix/var/nix/profiles/per-user/root/channels"; channelPath = "${rootChannelsPath}/${config.vuizvui.channelName}"; in { options.vuizvui = { modifyNixPath = mkOption { type = types.bool; default = true; description = '' Whether to modify NIX_PATH for vuizvui, so that <nixpkgs> points to the path within the Nix channel instead of the nixpkgs or nixos channel from the root user. ''; }; enableGlobalNixpkgsConfig = mkOption { type = types.bool; default = false; description = '' Enabling this links nixos-config to be used by nixpkgs-config, which essentially means that attributes defined in are also in effect for user environments. ''; }; channelName = mkOption { type = types.str; default = "vuizvui"; description = '' The channel name which is used to refer to vuizvui. ''; }; }; config = { # Expose all packages in ../../pkgs as pkgs.vuizvui in modules. nixpkgs.overlays = lib.mkBefore (lib.singleton (lib.const (super: { vuizvui = import ../../pkgs { pkgs = super; }; }))); nix = { settings = { substituters = [ "https://hydra.build/" ]; trusted-public-keys = [ "headcounter.org:/7YANMvnQnyvcVB6rgFTdb8p5LG1OTXaO+21CaOSBzg=" ]; }; }; environment.variables.NIXPKGS_CONFIG = let inherit (config.vuizvui) enableGlobalNixpkgsConfig; nixpkgsCfg = toString (pkgs.writeText "nixpkgs-try-config.nix" '' if (builtins.tryEval ).success then import else {} ''); in lib.mkIf enableGlobalNixpkgsConfig (lib.mkForce nixpkgsCfg); nix.nixPath = let nixosConfig = "/etc/nixos/configuration.nix"; nixpkgsConfig = "nixpkgs-config=${pkgs.writeText "nixpkgs-config.nix" '' (import ${pkgs.path}/nixos/lib/eval-config.nix { modules = [ ${nixosConfig} ]; }).config.nixpkgs.config ''}"; nixPath = [ "vuizvui=${channelPath}" "nixpkgs=${channelPath}/nixpkgs" "nixos-config=${nixosConfig}" rootChannelsPath ] ++ lib.optional config.vuizvui.enableGlobalNixpkgsConfig nixpkgsConfig; in lib.mkIf config.vuizvui.modifyNixPath (lib.mkOverride 90 nixPath); # correct path used by command-not-found which is enabled by default programs.command-not-found.dbPath = lib.mkDefault "${channelPath}/nixpkgs/programs.sqlite"; }; }