-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake-channels.nix
77 lines (57 loc) · 1.98 KB
/
flake-channels.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ options, config, pkgs, lib, cheznix, nixpkgs-follows, ... }:
let
inherit (config.home) homeDirectory;
## backward compatible to nix channels
prefix = ".nix-defexpr/channels";
flakeSelfName = "cheznix";
flakeInputs' = lib.collectFlakeInputs flakeSelfName cheznix;
## remove the local flakes
## to reduce trivial rebuilds
flakeInputs'' = removeAttrs flakeInputs' [
flakeSelfName
nixpkgs-follows
];
flakeInputs = flakeInputs'' // {
## include the patched nixpkgs
inherit (pkgs) nixpkgs-patched;
## include the home-manager flake itself from nixpkgs
home-manager.outPath = pkgs.home-manager.src;
};
generateLinks = prefix: name: flake: {
source = flake.outPath;
target = "${prefix}/${name}";
};
links = lib.mapAttrs (generateLinks prefix) flakeInputs;
addActivationScript = lib.mapAttrs (name: script:
lib.hm.dag.entryAfter [ "installPackages" ] script
);
in {
config.home.activation = addActivationScript {
## add `nixpkgs-follows` to flake registry at "runtime"
userFlakeRegistry = ''
flake=''${FLAKE_CONFIG_URI%#*} ## scheme: "path:$HOME/..."
nixpkgs="$flake/${nixpkgs-follows}"
## ^ relies on the subdir structure of the input!
nix registry add "${nixpkgs-follows}" "$nixpkgs"
nix registry add "${flakeSelfName}" "$flake"
nix registry add "home-manager" "${links.home-manager.source}"
## cool but unnecessary: double copy takes a long time
# nix registry add "nixpkgs-patched" "${links.nixpkgs-patched.source}"
'';
## prevent cheznix inputs from being garbage collected
userFlakeChannels = lib.concatStrings (
lib.mapAttrsToList
(name: link: ''
ln -sfT "${link.source}" "${homeDirectory}/${link.target}"
'')
links
);
};
config.programs = lib.mkIf (options.programs ? nixpkgs-helpers) {
## use `nixpkgs-follows` as a flakeref
nixpkgs-helpers = {
enable = true;
flakeref = nixpkgs-follows;
};
};
}