-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
139 lines (125 loc) · 4.32 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
138
139
{
description = "refnode's Nix configurations";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
nix-darwin.url = "github:lnl7/nix-darwin";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager/release-24.05";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
pre-commit-hooks.url = "github:cachix/git-hooks.nix";
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs @ {
self,
nixpkgs,
nixpkgs-unstable,
nix-darwin,
home-manager,
pre-commit-hooks,
...
}: let
user = "refnode";
flake = self;
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
# Uses lib.genAttrs to generate a attribute set, in this case using
# the systems as defined in `supportedSystems` as names.
# https://nixos.org/manual/nixpkgs/stable/#function-library-lib.attrsets.genAttrs
# This is a partial function as it misses the function param to lib.genAttrs
forEachSystem = nixpkgs.lib.genAttrs supportedSystems;
# Taken from https://github.com/Misterio77/nix-config
#
# Let's break that down, because it's a nice example.
#
# Let's assume, the function is called as in the formatter output below:
# pkgsForEachSystem(pkgs: pkgs.alejandra)
#
# pkgsForEachSystem is a function takes a function `f` as argument.
# So `(pkgs: pkgs.alejandra)` is the function passed as argument.
#
# In the function body lib.genAttrs takes the list of supportedSystems
# and maps the list to an attribute set using the function
# (system: f pkgsFor.${system})
#
# Let's assume the iteration passes `x86_64-linux` as system.
# The function body `(system: f pkgsFor.${system})` then becomes
# (x86_64-linux: (pkgs: pkgs.alejandra) pkgsFor.x86_64-linux)
# The function `(pkgs: pkgs.alejandra)` gets `pkgsFor.x86_64-linux` as
# argument for `pkgs` and finally evaluates to pkgs.x86_64-linux.alejandra.
pkgsForEachSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f pkgsFor.${system});
# Rewriting the function, taking inspiration from
# https://github.com/Misterio77/nix-config
# Using lib.genAttrs to import nixpkgs provides a nice way to quick
# access or pass pkgs for a certain targetSystem by simply access eg.
# pkgsFor.x86_64-linux or pkgsFor.${system} as pkgsFor is finally an
# attribute set, with system keys referencing to nixpkgs for that
# system.
pkgsFor = nixpkgs.lib.genAttrs supportedSystems (
system:
import nixpkgs {
inherit system;
overlays = [
localOverlays
];
# activate unfree when I know that I need it.
config.allowUnfree = false;
}
);
unstablePkgsFor = nixpkgs.lib.genAttrs supportedSystems (
system:
import nixpkgs-unstable {
inherit system;
overlays = [];
# activate unfree when I know that I need it.
config.allowUnfree = false;
}
);
# add local scripts as derivations using an overlay
# could be also done by just passing additional args to the submodules
# using the overlay approach, the repo local derivations are addressable
# by pkgs.myderivation in the submodule
localOverlays = import ./overlays;
in {
formatter = pkgsForEachSystem (pkgs: pkgs.alejandra);
checks = forEachSystem (
system: let
pkgs = pkgsFor.${system};
in
import ./checks {inherit pre-commit-hooks system;}
);
devShells = forEachSystem (
system: let
pkgs = pkgsFor.${system};
checks = self.checks.${system};
in {
default = import ./shell.nix {inherit pkgs checks;};
}
);
# Build darwin flake using:
# $ darwin-rebuild build --flake .#defiant
darwinConfigurations = let
system = "aarch64-darwin";
pkgs = pkgsFor.${system};
pkgsUnstable = unstablePkgsFor.${system};
in {
defiant = import ./lib {
inherit
pkgs
pkgsUnstable
nix-darwin
home-manager
system
user
flake
inputs
;
};
};
nixosConfigurations = {};
};
}