-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.nix
107 lines (107 loc) · 2.73 KB
/
lib.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
{
self,
# stable version nixpkgs
stable,
# unstable version nixpkgs
unstable,
minimumOverlays,
}: let
inherit (builtins) typeOf;
in rec {
# provides a NixOS system which will be cross-compiled.
mkSystemCross = {
host,
target,
system,
modules,
nixpkgs,
}: let
pkgs =
(import
nixpkgs
{
system = host;
overlays = minimumOverlays;
})
.pkgs
.pkgsCross
."${target}";
in
nixpkgs.lib.nixosSystem
{
inherit system pkgs;
modules =
[
nixpkgs.nixosModules.notDetected
(
{config, ...}: {
# Pins nixpkgs of system to `inputs.nixpkgs`.
nix.registry.nixpkgs.flake = nixpkgs;
# Allows commands like `nix shell self#jmpunkt.emacs`
nix.registry.self.flake = self;
nixpkgs.overlays = minimumOverlays ++ [(mkUnstableOverlay system)];
}
)
]
++ modules;
};
# provides NixOS system with default settings.
mkSystem = {
system,
modules,
nixpkgs,
inputs,
}:
nixpkgs.lib.nixosSystem
{
inherit system;
specialArgs = {inherit inputs;};
modules =
[
nixpkgs.nixosModules.notDetected
(
{config, ...}: {
# Pins nixpkgs of system to `inputs.nixpkgs`.
nix.registry.nixpkgs.flake = nixpkgs;
# pin system nixpkgs to the same version as the flake
# input (https://github.com/nix-community/nix-index/issues/167#issuecomment-989849343)
nix.nixPath = ["nixpkgs=${nixpkgs}"];
# Allows commands like `nix shell self#jmpunkt.emacs`
nix.registry.self.flake = self;
nixpkgs.overlays = minimumOverlays ++ [(mkUnstableOverlay system)];
}
)
]
++ modules;
};
mkPkgs = system: nixpkgs: additionalOverlays:
import
nixpkgs
{
inherit system;
overlays = minimumOverlays ++ additionalOverlays;
config.allowUnfree = true;
};
# Creates an overlay for a system which includes an attribute
# `unstable` of all unstable nixpkgs.
mkUnstableOverlay = system: (final: prev: {unstable = mkPkgs system unstable [];});
# Provide the attribute path for building a SD image.
packageSD = target:
target
.config
.system
.build
.sdImage;
# Provide the attribute path for building an ISO.
packageISO = target:
target
.config
.system
.build
.isoImage;
# Provide the attribute path for building a NixOS system derivation.
packageSystem = target:
target.config.system.build.toplevel;
packageVM = target:
target.config.system.build.vm;
}