forked from RCMast3r/hytech_nixos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
162 lines (136 loc) · 4.75 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
162
{
description = "Build image for KSU-MS's Pi running the ksu_daq flake and some other gizmos later";
# Cache to reduce build times dont worry about it
nixConfig = {
extra-substituters = [ "https://raspberry-pi-nix.cachix.org" ];
extra-trusted-public-keys = [
"raspberry-pi-nix.cachix.org-1:WmV2rdSangxW0rZjY/tBvBDSaNFQ3DyEQsVw8EvHn9o="
];
};
# All the outside things to fetch from the internet
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/c871670c7dad94b3454b8fc9a8a35e1ab92d8b3e";
data_acq.url = "github:KSU-MS/ksu_daq";
raspberry-pi-nix.url = "github:tstat/raspberry-pi-nix";
};
# All the things going into the generated image
outputs = { self, nixpkgs, data_acq, raspberry-pi-nix }: rec {
shared_config = {
# Target architecture
nixpkgs.hostPlatform.system = "aarch64-linux";
# Overlays
nixpkgs.overlays = [ (data_acq.overlays.default) ];
# NTP time sync flag (network time protocol)
services.timesyncd.enable = true;
# Disable needing a signature on bins
nix.settings.require-sigs = false;
# User setup
users.users.root.initialPassword = "root";
users.users.nixos.group = "nixos";
users.users.nixos.password = "nixos";
users.users.nixos.extraGroups = [ "wheel" ];
# users.groups.nixos = { };
users.users.nixos.isNormalUser = true;
system.activationScripts.createRecordingsDir = nixpkgs.lib.stringAfter [ "users" ] ''
mkdir -p /home/nixos/recordings
chown nixos:users /home/nixos/recordings
'';
# Network settings
networking.hostName = "Philipp";
networking.firewall.enable = false;
networking.useDHCP = false;
# SSH settings
services.openssh = { enable = true; };
users.extraUsers.nixos.openssh.authorizedKeys.keys = [ ];
systemd.services.sshd.wantedBy =
nixpkgs.lib.mkOverride 40 [ "multi-user.target" ];
# Git setup
programs.git = {
enable = true;
config = {
user.name = "";
user.email = "";
};
};
};
# Config for can device
can_config = {
# Lol its just another network config
networking = {
can.enable = true;
can.interfaces = {
can0 = {
bitrate = 1000000;
};
};
};
};
xbee_config = {
# Serial udev rule for xbee
services.udev.extraRules = ''
KERNEL=="ttyUSB*", SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", SYMLINK+="xboi"
# Identify
# Find the ATTRS with this command
# udevadm info --attribute-walk --name=/dev/*
# Set perms
# Symlink it for a consistant name
'';
};
pi5_config = { pkgs, lib, ... }: {
# More networking config
networking = {
interfaces.end0.ipv4.addresses = [{
address = "192.168.1.7"; # Your static IP address
prefixLength = 24; # Netmask, 24 for 255.255.255.0
}];
defaultGateway = "192.168.1.1";
};
};
# shoutout to https://github.com/tstat/raspberry-pi-nix absolute goat
nixosConfigurations.rpi = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
./modules/data_acq.nix
./modules/can_network.nix
(
{ pkgs, ... }: {
config = {
# Utils and other apps you want
environment.systemPackages = with pkgs; [
can-utils
iperf3
];
# Settings for the image that is generated
sdImage.compressImage = false;
raspberry-pi-nix.uboot.enable = false;
# One shot systemd service to fix wacky fucking network bug
systemd.services.restart-network-setup = {
description = "Restart Network Setup Service";
wantedBy = [ "multi-user.target" ];
after = [ "network-setup.service" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.systemd}/bin/systemctl restart network-setup.service";
RemainAfterExit = true;
};
};
};
# Start the logging service
options = {
services.data_writer.options.enable = true;
};
}
)
# Getting the RPi firmware
raspberry-pi-nix.nixosModules.raspberry-pi
# Running the configs made earlier
shared_config
can_config
pi5_config
];
};
# Defineing the build commands for the terminal
images.rpi_sd = nixosConfigurations.rpi.config.system.build.sdImage;
images.rpi_top = nixosConfigurations.rpi.config.system.build.toplevel;
};
}