-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflake.nix
156 lines (137 loc) · 5.4 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{
description = "CODe maCHInes - Declarative and Reprodicible Development Environements as Code";
nixConfig = {
extra-substituters = "https://codchi.cachix.org";
extra-trusted-public-keys = "codchi.cachix.org-1:dVwdzogJgZO2x8kPKW02HNt2dpd/P/z46pY465MkokY=";
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
rust-overlay = {
url = "github:oxalica/rust-overlay";
flake = false; # prevent fetching transitive inputs TODO
};
# nixvim = {
# url = "github:nix-community/nixvim";
# inputs.nixpkgs.follows = "nixpkgs";
# };
};
outputs = inputs@{ self, nixpkgs, rust-overlay, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [
(import rust-overlay)
(self: _: {
codchi = self.callPackage ./codchi { inherit (inputs) self; platform = "linux"; };
codchi-windows = self.callPackage ./codchi { inherit (inputs) self; platform = "win"; };
codchiw-windows = self.callPackage ./codchiw { inherit (inputs) self; platform = "win"; };
codchi-utils = self.callPackage ./utils { };
mkContainer = type: driver: (import ./nix/container
{
inherit inputs;
inherit (nixpkgs) lib;
pkgs = self;
}
{
config.${type} = {
enable = true;
driver.${driver}.enable = true;
};
}
);
store-lxd = self.mkContainer "store" "lxd";
store-lxd-tarball = self.store-lxd.config.build.tarball;
store-wsl = self.mkContainer "store" "wsl";
store-wsl-tarball = self.store-wsl.config.build.tarball;
machine-lxd = self.mkContainer "machine" "lxd";
machine-lxd-tarball = self.machine-lxd.config.build.tarball;
machine-wsl = self.mkContainer "machine" "wsl";
machine-wsl-tarball = self.machine-wsl.config.build.tarball;
# nixvim = { inherit (inputs.nixvim.legacyPackages.${system}) makeNixvim; };
})
#(inputs.nixvim.overlays.default)
];
config.allowUnfree = true;
};
drivers = [ "wsl" "lxd" ];
inherit (nixpkgs.lib) foldl' recursiveUpdate;
mergeAttrList = foldl' recursiveUpdate { };
lib = import ./nix/lib.nix;
in
mergeAttrList
[
{
inherit lib;
nixosModules.default = import ./nix/nixos;
nixosModules.codchi = {
imports = [ ./configuration.nix ];
environment.systemPackages = self.devShells.${system}.default.nativeBuildInputs;
};
packages.${system} = {
inherit (pkgs) store-lxd store-wsl machine-lxd machine-wsl codchi-utils;
default = pkgs.codchi;
windows = pkgs.codchi-windows;
inherit (pkgs) codchiw-windows;
inherit (pkgs.pkgsStatic) busybox;
# editor = pkgs.nixvim.makeNixvim (import ./editor.nix);
};
devShells.${system} = {
default = pkgs.callPackage ./codchi/shell.nix { platform = "linux"; };
windows = pkgs.callPackage ./codchi/shell.nix { platform = "win"; codchi = pkgs.codchi-windows; };
};
checks.${system}.populate-cache =
let
container = base: [
base.config.build.tarball.passthru.createFiles
base.config.build.runtime
];
buildInputs = [
# self.nixosConfigurations.lxd-base.config.system.build.toplevel
# self.nixosConfigurations.wsl-base.config.system.build.toplevel
self.packages.${system}.default
self.packages.${system}.windows
]
++ container self.packages.${system}.store-lxd
++ container self.packages.${system}.store-wsl
++ container self.packages.${system}.machine-lxd
++ container self.packages.${system}.machine-wsl
;
in
pkgs.runCommandLocal "populate-cache" { } ''
echo ${toString buildInputs} > $out
'';
}
(
let
inherit (nixpkgs.lib) flip mapAttrs mapAttrs' nameValuePair;
inherit (builtins) readDir;
examples = flip mapAttrs (readDir ./nix/examples) (path: _: "${./nix/examples}/${path}");
exampleModules = flip mapAttrs examples (_: path: import "${path}/configuration.nix");
exampleTemplates = flip mapAttrs examples
(name: path: {
inherit path;
description = "NixOS module for ${name}";
});
mkExampleSystems = driver:
flip mapAttrs exampleModules
(_: module: lib.codeMachine {
inherit system driver nixpkgs;
# specialArgs.inputs = inputs;
modules = [ module ];
});
in
{
templates = exampleTemplates;
nixosModules = exampleModules;
nixosConfigurations = mergeAttrList
(flip map drivers
(driver:
(mapAttrs'
(name: nameValuePair "${driver}-${name}"))
(mkExampleSystems driver)
));
}
)
];
}