2023-07-06 17:54:57 +00:00
|
|
|
/*
|
|
|
|
Manages the things that are needed for a traditional nix-channel based
|
|
|
|
configuration to work.
|
|
|
|
|
|
|
|
See also
|
2023-07-23 13:32:15 +00:00
|
|
|
- ./nix.nix
|
|
|
|
- ./nix-flakes.nix
|
2023-07-06 17:54:57 +00:00
|
|
|
*/
|
2023-07-05 11:53:25 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
2023-07-07 21:12:39 +00:00
|
|
|
mkDefault
|
2023-07-05 11:53:25 +00:00
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
types
|
|
|
|
;
|
|
|
|
|
|
|
|
cfg = config.nix;
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2023-07-05 12:05:41 +00:00
|
|
|
nix = {
|
2023-07-07 16:53:19 +00:00
|
|
|
channel = {
|
|
|
|
enable = mkOption {
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether the `nix-channel` command and state files are made available on the machine.
|
|
|
|
|
|
|
|
The following files are initialized when enabled:
|
2023-07-23 13:32:15 +00:00
|
|
|
- `/nix/var/nix/profiles/per-user/root/channels`
|
|
|
|
- `/root/.nix-channels`
|
|
|
|
- `$HOME/.nix-defexpr/channels` (on login)
|
2023-07-07 16:53:19 +00:00
|
|
|
|
|
|
|
Disabling this option will not remove the state files from the system.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-05 12:05:41 +00:00
|
|
|
nixPath = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2023-07-07 16:53:19 +00:00
|
|
|
default =
|
|
|
|
if cfg.channel.enable
|
|
|
|
then [
|
|
|
|
"nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
|
|
|
|
"nixos-config=/etc/nixos/configuration.nix"
|
|
|
|
"/nix/var/nix/profiles/per-user/root/channels"
|
|
|
|
]
|
2023-07-23 13:32:15 +00:00
|
|
|
else [ ];
|
2023-07-07 16:53:19 +00:00
|
|
|
defaultText = ''
|
|
|
|
if nix.channel.enable
|
|
|
|
then [
|
|
|
|
"nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
|
|
|
|
"nixos-config=/etc/nixos/configuration.nix"
|
|
|
|
"/nix/var/nix/profiles/per-user/root/channels"
|
|
|
|
]
|
|
|
|
else [];
|
|
|
|
'';
|
2023-07-05 12:05:41 +00:00
|
|
|
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 11:53:25 +00:00
|
|
|
system = {
|
|
|
|
defaultChannel = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.str;
|
2023-11-22 20:35:51 +00:00
|
|
|
default = "https://nixos.org/channels/nixos-unstable";
|
2023-07-05 11:53:25 +00:00
|
|
|
description = lib.mdDoc "Default NixOS channel to which the root user is subscribed.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2023-07-05 12:05:41 +00:00
|
|
|
environment.extraInit =
|
2023-07-07 16:53:19 +00:00
|
|
|
mkIf cfg.channel.enable ''
|
2023-07-05 12:05:41 +00:00
|
|
|
if [ -e "$HOME/.nix-defexpr/channels" ]; then
|
|
|
|
export NIX_PATH="$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2023-07-08 18:49:37 +00:00
|
|
|
environment.extraSetup = mkIf (!cfg.channel.enable) ''
|
2023-07-23 13:33:50 +00:00
|
|
|
rm --force $out/bin/nix-channel
|
2023-07-07 16:53:19 +00:00
|
|
|
'';
|
|
|
|
|
2023-07-07 21:12:39 +00:00
|
|
|
# NIX_PATH has a non-empty default according to Nix docs, so we don't unset
|
|
|
|
# it when empty.
|
|
|
|
environment.sessionVariables = {
|
2023-07-05 12:05:41 +00:00
|
|
|
NIX_PATH = cfg.nixPath;
|
|
|
|
};
|
|
|
|
|
2023-07-07 21:12:39 +00:00
|
|
|
nix.settings.nix-path = mkIf (! cfg.channel.enable) (mkDefault "");
|
|
|
|
|
2023-10-17 19:39:51 +00:00
|
|
|
systemd.tmpfiles.rules = lib.mkIf cfg.channel.enable [
|
2023-11-01 15:01:49 +00:00
|
|
|
''f /root/.nix-channels - - - - ${config.system.defaultChannel} nixos\n''
|
2023-10-17 19:39:51 +00:00
|
|
|
];
|
2023-07-05 11:53:25 +00:00
|
|
|
};
|
|
|
|
}
|