-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
134 lines (132 loc) · 4.65 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
{
description = "Common NixOS modules for my nix use cases";
inputs = {
# Commented out dir=lib because we need the extended lib for using functions such as
# nixosSystem: https://github.com/NixOS/nixpkgs/blob/b878cb4ca34d62b19b06b00518d7cf249530c343/flake.nix#L18
# Leaving this URL to think about reducing the amount of nixpkgs
# and try to make a lean lib usage here
#nixpkgs-lib.url = "github:NixOS/nixpkgs/nixos-unstable";
# This current implementation likely leaves too many copies of nixpkgs everywhere
latestRelease.url = "github:NixOS/nixpkgs/nixos-24.11";
unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
home-manager = {
url = "github:nix-community/home-manager/release-24.11";
inputs.nixpkgs.follows = "latestRelease";
};
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "latestRelease";
};
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "latestRelease";
};
srvos.url = "github:nix-community/srvos";
};
outputs =
{ self
, latestRelease
, ...
} @ inputs:
let
# TODO extend the standard library to include your personal functions, that
# way you only use the extended library in all your other repos
# one way to do it is like this:
# https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/master/flake.nix
libx = import ./lib latestRelease.lib self.nixosModules;
stateVersion = "24.11";
in
{
lib = libx;
nixosModules = with latestRelease.lib; let
folder = ./modules;
toImport = name: (import "${folder}/${name}");
filterModules = _: value: value == "directory";
names = builtins.attrNames (filterAttrs filterModules (builtins.readDir folder));
modules = genAttrs names toImport;
in
modules
// {
tsUnstable = { ... }: {
nixpkgs.overlays = [
(final: prev: {
tailscaleUnstable = inputs.unstable.legacyPackages.${prev.system}.tailscale;
})
];
};
agenix = inputs.agenix.nixosModules.default;
disko = inputs.disko.nixosModules.disko;
srvos = inputs.srvos.nixosModules;
home-manager = inputs.home-manager.nixosModules.home-manager;
pi4Base = { lib, ... }: {
imports = [
"${latestRelease}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
"${latestRelease}/nixos/modules/installer/cd-dvd/channel.nix"
];
networking = {
wireless = {
enable = true;
networks."Atila".psk = "???????????";
};
hostId = "8d0986db"; #worthy-elk
};
system.activationScripts.installConfiguration = ''
if [ ! -f /etc/nixos/configuration.nix ]; then
mkdir -p /etc/nixos
fi
'';
sdImage.firmwareSize = 5000;
fileSystems = {
"/boot/firmware" = {
device = "/dev/disk/by-label/FIRMWARE";
fsType = "vfat";
options = [ "nofail" "noauto" ];
};
"/" = {
device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4";
};
};
};
};
nixosConfigurations = (libx self.outPath).mkHosts {
pi4Base = {
inherit stateVersion;
system = "aarch64-linux";
hostname = "nixos";
extraModules = with self.nixosModules; [
pi4Base
({ lib, ... }: {
# This follows the dvd boot installer
boot.loader.grub.enable = lib.mkForce false;
})
];
};
vm = {
system = "aarch64-linux";
inherit stateVersion;
extraModules = [
self.nixosModules.vm
{
virtualisation.vmVariant.virtualisation.host.pkgs = latestRelease.legacyPackages.aarch64-darwin;
}
];
};
};
packages = {
aarch64-darwin.vm = self.nixosConfigurations.vm.config.system.build.vm;
aarch64-linux.pi4SDBase = self.nixosConfigurations.pi4Base.config.system.build.sdImage;
};
apps.aarch64-darwin.default = {
type = "app";
program = "${
latestRelease.legacyPackages.aarch64-darwin.writeShellScript "run-vm.sh" ''
export NIX_DISK_IMAGE=$(mktemp -u -t vm.qcow2)
echo "IMAGE PATH $NIX_DISK_IMAGE"
trap "rm -f $NIX_DISK_IMAGE" EXIT
${self.packages.aarch64-darwin.vm}/bin/run-vm-vm''
}";
};
};
}