-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
137 lines (130 loc) · 4.06 KB
/
flake.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{
description = "Flake aggregation for the post-modern developer (tm)";
inputs = {
# hydra: https://status.nixos.org
# tests: https://hydra.nixos.org/job/nixos/trunk-combined/tested#tabs-status
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
# tools
alejandra = {
url = "github:kamadorueda/alejandra";
inputs.nixpkgs.follows = "nixpkgs";
inputs.fenix.follows = "fenix";
};
# buildtools
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs @ {
self,
flake-parts,
...
}: let
lib = inputs.nixpkgs.lib;
overlayAttrs = (import ./overlays.nix {inherit lib;}) // {rustc = inputs.rust-overlay.overlays.default;};
overlays = builtins.attrValues overlayAttrs;
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin"];
flakeDefaults = {
inherit systems;
perSystem = {
system,
pkgs,
...
}: {
formatter = pkgs.alejandra;
_module.args.pkgs = import inputs.nixpkgs {
inherit system overlays;
};
};
};
in
flake-parts.lib.mkFlake {inherit inputs;} {
inherit systems;
imports = [flakeDefaults];
perSystem = {
pkgs,
system,
...
}: let
packages = builtins.mapAttrs (name: _: builtins.getAttr name pkgs) overlayAttrs;
in {
devShells.default = with pkgs;
mkShell {
name = "pkgs";
description = "all packages";
nativeBuildInputs = builtins.attrValues packages;
shellHook = let
versions =
builtins.toString (builtins.map (p: "${builtins.baseNameOf (lib.getExe p)}==${p.version}")
(builtins.attrValues packages));
in ''
echo exes: ${versions}
'';
};
# export all packages for which overlays were defined
inherit packages;
};
flake = {
lib,
pkgs,
...
}: {
inherit systems;
pkgs.nixpkgs = pkgs;
flakeModules = {inherit flakeDefaults;};
# flake schema outputs
# all overlays for independent consumption
overlays = let
nixpkgs = final: prev:
lib.composeManyExtensions overlays final prev;
default = nixpkgs;
in (overlayAttrs // {inherit nixpkgs default;});
# common modules related to `nix-trickle`
nixosModules = {
bin-cache = {
nix.settings.substituters = ["https://cybertreiber.cachix.org"];
nix.settings.trusted-public-keys = ["cybertreiber.cachix.org-1:Hk0+JJqAIfHY6J9/p5RFXvdHO35w/MgtT5BPVSzoCe0="];
};
default = {
pkgs,
lib,
...
}: {
# https://github.com/srid/nixos-config/blob/master/nixos/nix.nix
nixpkgs = {
config.allowUnfree = true;
inherit overlays;
};
nix = {
package = pkgs.nixVersions.latest;
nixPath = ["nixpkgs=${self.inputs.nixpkgs}"]; # Enables use of `nix-shell -p ...` etc
registry.nixpkgs.flake = self.inputs.nixpkgs; # Make `nix shell` etc use pinned nixpkgs
settings = {
max-jobs = "auto";
experimental-features = "nix-command flakes";
};
};
};
};
# templates
templates.pure-system = {
path = ./templates/pure-system;
description = "Example configuration for pure flake systems based on `nix-trickle`";
};
templates.devShell = {
path = ./templates/devShell;
description = "Example devShell based on `nix-trickle`";
};
};
};
}