2021-02-06 15:35:38 +01:00
|
|
|
# Nix related settings
|
2021-12-22 23:47:27 +01:00
|
|
|
{ config, inputs, lib, options, pkgs, ... }:
|
2021-05-29 20:28:27 +02:00
|
|
|
let
|
|
|
|
cfg = config.my.system.nix;
|
|
|
|
in
|
2021-02-06 15:35:38 +01:00
|
|
|
{
|
2021-05-29 20:28:27 +02:00
|
|
|
options.my.system.nix = with lib; {
|
|
|
|
enable = my.mkDisableOption "nix configuration";
|
|
|
|
|
2023-02-20 22:26:51 +01:00
|
|
|
linkInputs = my.mkDisableOption "link inputs to `/etc/nix/inputs/`";
|
|
|
|
|
2021-05-29 20:28:27 +02:00
|
|
|
addToRegistry = my.mkDisableOption "add inputs and self to registry";
|
2021-12-22 23:47:27 +01:00
|
|
|
|
|
|
|
addToNixPath = my.mkDisableOption "add inputs and self to nix path";
|
2023-02-11 12:03:32 +01:00
|
|
|
|
|
|
|
overrideNixpkgs = my.mkDisableOption "point nixpkgs to pinned system version";
|
2021-02-06 15:35:38 +01:00
|
|
|
};
|
2021-05-29 20:28:27 +02:00
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
2023-02-23 22:00:30 +01:00
|
|
|
{
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.addToNixPath -> cfg.linkInputs;
|
|
|
|
message = ''
|
|
|
|
enabling `my.system.nix.addToNixPath` needs to have
|
|
|
|
`my.system.nix.linkInputs = true`
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-05-29 20:28:27 +02:00
|
|
|
{
|
|
|
|
nix = {
|
2022-09-29 21:58:48 +02:00
|
|
|
package = pkgs.nix;
|
2021-05-29 20:28:27 +02:00
|
|
|
|
2022-02-08 14:32:00 +01:00
|
|
|
settings = {
|
|
|
|
experimental-features = [ "nix-command" "flakes" ];
|
|
|
|
};
|
2021-05-29 20:28:27 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
(lib.mkIf cfg.addToRegistry {
|
|
|
|
nix.registry = {
|
|
|
|
# Allow me to use my custom package using `nix run self#pkg`
|
|
|
|
self.flake = inputs.self;
|
|
|
|
# Use pinned nixpkgs when using `nix run pkgs#<whatever>`
|
|
|
|
pkgs.flake = inputs.nixpkgs;
|
2023-02-11 12:03:32 +01:00
|
|
|
# ... And with `nix run nixpkgs#<whatever>`
|
|
|
|
nixpkgs.flake = lib.mkIf cfg.overrideNixpkgs inputs.nixpkgs;
|
2021-05-29 20:28:27 +02:00
|
|
|
# Add NUR to run some packages that are only present there
|
|
|
|
nur.flake = inputs.nur;
|
|
|
|
};
|
|
|
|
})
|
2021-12-22 23:47:27 +01:00
|
|
|
|
2023-02-20 22:26:51 +01:00
|
|
|
(lib.mkIf cfg.linkInputs {
|
|
|
|
environment.etc =
|
|
|
|
let
|
|
|
|
makeLink = n: v: {
|
|
|
|
name = "nix/inputs/${n}";
|
|
|
|
value = { source = v.outPath; };
|
|
|
|
};
|
|
|
|
makeLinks = lib.mapAttrs' makeLink;
|
2023-02-24 10:25:38 +01:00
|
|
|
channels = {
|
|
|
|
self = inputs.self;
|
|
|
|
pkgs = inputs.nixpkgs;
|
|
|
|
nur = inputs.nur;
|
|
|
|
} // lib.optionalAttrs cfg.overrideNixpkgs {
|
|
|
|
nixpkgs = inputs.nixpkgs;
|
|
|
|
};
|
2023-02-20 22:26:51 +01:00
|
|
|
in
|
2023-02-24 10:25:38 +01:00
|
|
|
makeLinks channels;
|
2023-02-20 22:26:51 +01:00
|
|
|
})
|
|
|
|
|
2021-12-22 23:47:27 +01:00
|
|
|
(lib.mkIf cfg.addToNixPath {
|
2023-02-11 11:53:52 +01:00
|
|
|
nix.nixPath = [
|
2023-02-23 22:00:30 +01:00
|
|
|
"self=/etc/nix/inputs/self"
|
2023-02-24 10:25:38 +01:00
|
|
|
"pkgs=/etc/nix/inputs/pkgs"
|
2023-02-23 22:00:30 +01:00
|
|
|
"nur=/etc/nix/inputs/nur"
|
2023-02-11 12:03:32 +01:00
|
|
|
]
|
2023-02-23 22:00:30 +01:00
|
|
|
++ lib.optional cfg.overrideNixpkgs "nixpkgs=/etc/nix/inputs/nixpkgs"
|
2023-02-11 11:53:52 +01:00
|
|
|
++ options.nix.nixPath.default;
|
2021-12-22 23:47:27 +01:00
|
|
|
})
|
2021-05-29 20:28:27 +02:00
|
|
|
]);
|
2021-02-06 15:35:38 +01:00
|
|
|
}
|