-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
161 lines (143 loc) · 4.68 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
157
158
159
160
161
{
description = "Description for the project";
inputs = {
devshell.url = "github:numtide/devshell";
devshell.inputs.nixpkgs.follows = "nixpkgs";
flake-compat.url = "github:edolstra/flake-compat";
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake {inherit inputs;} ({inputs, ...}: {
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
imports = [
inputs.devshell.flakeModule
inputs.treefmt-nix.flakeModule
];
perSystem = {
config,
lib,
pkgs,
system,
...
}: {
# `nix run '.#' -- <devshell-command>`
apps.default = config.devShells.default.flakeApp;
devshells.default = {
commands = [
# Local GitHub actions runner. Run `act -j native` to execute the
# `native` job.
{
category = "dev";
package = pkgs.act;
}
{
category = "dev";
package = pkgs.ansible;
}
{
category = "dev";
package = pkgs.vagrant.override {
# So that we can use `libguestfs-with-appliance` when calling
# `create-box` (by default, the `vagrant` derivation depends on
# plain old `libguestfs`).
libguestfs = pkgs.libguestfs-with-appliance;
};
}
{
category = "dev";
package = config.packages.vagrant-libvirt-create-box;
}
{
name = "fmt";
category = "dev";
help = "Format this project's code";
command = ''
exec ${config.treefmt.build.wrapper}/bin/treefmt "$@"
'';
}
];
devshell.packages = with pkgs; [
curl
guestfs-tools
gzip
libguestfs-with-appliance
qemu
sshpass # for password auth with Ansible
];
};
packages = let
rpi4 = inputs.nixpkgs.lib.nixosSystem {
inherit system;
modules = [
{
nixpkgs.crossSystem.system = "aarch64-linux";
}
./configuration.nix
];
};
in {
inherit (config.devShells) default;
rpi4-initrd = rpi4.config.system.build.initialRamdisk;
rpi4-kernel = rpi4.config.system.build.kernel;
# From the `vagrant-libvirt` project. Patched to permit injecting
# additional files into the generated Vagrant box archive.
vagrant-libvirt-create-box = let
deps = with pkgs;
[
coreutils
gawk
gnutar
pigz
qemu
]
++ (lib.optional (!stdenv.isDarwin) psmisc);
in
pkgs.runCommand "vagrant-libvirt-create-box" {
src = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/vagrant-libvirt/vagrant-libvirt/main/tools/create_box.sh";
sha256 = "sha256-xrCoMeXV++Dmi766r0i0RO4NMe7LDr3jNdJSXjNrY+4=";
};
nativeBuildInputs = with pkgs; [
makeWrapper
];
meta = {
mainProgram = "vagrant-libvirt-create-box";
description = "create a Vagrant box file from a qcow2 disk image";
};
} ''
script="''${out}/bin/vagrant-libvirt-create-box"
install -D "$src" "$script"
sed -i -e '/^tar[[:space:]]\+cv/ {
s/^tar\([[:space:]]\+\)/tar --transform="s|.*\/||"\1-/
s/\([[:space:]]\+\)|\([[:space:]]\+\)/\1"$@" |\2/
s/^/argc="$#"; if [ "$argc" -ge 3 ]; then shift 3; elif [ "$argc" -eq 2 ]; then shift 2; else shift 1; fi; /
}' "$script"
wrapProgram "$script" --prefix PATH : ${lib.makeBinPath deps}
'';
};
treefmt = {
programs.alejandra.enable = true;
flakeFormatter = true;
projectRootFile = "flake.nix";
};
};
flake = {
nixosConfigurations = {
rpi4 = inputs.nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
./configuration.nix
];
};
};
};
});
}