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