2023-07-06 13:54:57 -04:00
|
|
|
/*
|
|
|
|
Manages the things that are needed for a traditional nix-channel based
|
|
|
|
configuration to work.
|
|
|
|
|
|
|
|
See also
|
|
|
|
- ./nix.nix
|
2023-07-06 17:27:17 -04:00
|
|
|
- ./nix-flakes.nix
|
2023-07-06 13:54:57 -04:00
|
|
|
*/
|
2023-07-05 07:53:25 -04:00
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
stringAfter
|
|
|
|
types
|
|
|
|
;
|
|
|
|
|
|
|
|
cfg = config.nix;
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2023-07-05 08:05:41 -04:00
|
|
|
nix = {
|
|
|
|
nixPath = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [
|
|
|
|
"nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
|
|
|
|
"nixos-config=/etc/nixos/configuration.nix"
|
|
|
|
"/nix/var/nix/profiles/per-user/root/channels"
|
|
|
|
];
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
The default Nix expression search path, used by the Nix
|
|
|
|
evaluator to look up paths enclosed in angle brackets
|
|
|
|
(e.g. `<nixpkgs>`).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-05 07:53:25 -04:00
|
|
|
system = {
|
|
|
|
defaultChannel = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.str;
|
|
|
|
default = "https://nixos.org/channels/nixos-unstable";
|
|
|
|
description = lib.mdDoc "Default NixOS channel to which the root user is subscribed.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2023-07-05 08:05:41 -04:00
|
|
|
environment.extraInit =
|
|
|
|
''
|
|
|
|
if [ -e "$HOME/.nix-defexpr/channels" ]; then
|
|
|
|
export NIX_PATH="$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.sessionVariables = {
|
|
|
|
NIX_PATH = cfg.nixPath;
|
|
|
|
};
|
|
|
|
|
2023-07-05 07:53:25 -04:00
|
|
|
system.activationScripts.nix-channel = stringAfter [ "etc" "users" ]
|
|
|
|
''
|
|
|
|
# Subscribe the root user to the NixOS channel by default.
|
|
|
|
if [ ! -e "/root/.nix-channels" ]; then
|
|
|
|
echo "${config.system.defaultChannel} nixos" > "/root/.nix-channels"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|