-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathflake.nix
More file actions
100 lines (86 loc) · 3.02 KB
/
flake.nix
File metadata and controls
100 lines (86 loc) · 3.02 KB
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
# Copyright 2024 Edgeless Systems GmbH
# SPDX-License-Identifier: BUSL-1.1
{
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs?ref=nixos-unstable";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
treefmt-nix,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
# mkSet creates a set of packages based on a given set of overlays.
mkSet =
overlays:
import nixpkgs {
inherit system overlays;
config.allowUnfree = true;
config.nvidia.acceptLicense = true;
};
# setsFromDirectory reads overlays from a directory and creates a set of pkgs instances for each.
# The filename is used as attribute name in the resulting set, the .nix extension is stripped.
setsFromDirectory =
dir:
builtins.listToAttrs (
map (file: rec {
name = builtins.substring 0 (builtins.stringLength file - 4) (baseNameOf file);
value = mkSet ((defaultOverlays name) ++ [ (import (dir + "/${file}")) ]);
}) (builtins.attrNames (builtins.readDir dir))
);
# reverseContrastNesting takes a pkgs instance and reverses the nesting by moving the
# contrastPkgs attributes to the top level and the originally top-level nixpkgs attributes
# to a nested nixpkgs attribute. This allows easy access to contrastPkgs via the nix flake
# CLI while still exposing the overlayed packages from nixpkgs under the nixpkgs attribute.
reverseContrastNesting =
pkgs:
pkgs.contrastPkgs
// {
nixpkgs = removeAttrs pkgs [
"fenix"
"contrastPkgs"
];
};
defaultOverlays = set: [
(final: _prev: { fenix = self.inputs.fenix.packages.${final.stdenv.hostPlatform.system}; })
(_final: _prev: { runtimePkgs = self.legacyPackages.x86_64-linux.${set}; })
(import ./overlays/nixpkgs.nix)
(import ./overlays/contrast.nix)
(import ./overlays/runtimepkgs.nix)
];
sets = setsFromDirectory ./overlays/sets;
pkgs = sets.base;
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
devShells = pkgs.callPackages ./dev-shells { };
formatter = treefmtEval.config.build.wrapper;
checks.formatting = treefmtEval.config.build.check self;
legacyPackages = nixpkgs.lib.mapAttrs (_name: reverseContrastNesting) sets;
}
);
nixConfig = {
extra-substituters = [ "https://edgelesssys.cachix.org" ];
extra-trusted-public-keys = [
"edgelesssys.cachix.org-1:erQG/S1DxpvJ4zuEFvjWLx/4vujoKxAJke6lK2tWeB0="
];
};
}