Skip to content

Commit d7b48fa

Browse files
committed
add: flake config to build
1 parent 467a8b3 commit d7b48fa

8 files changed

+419
-154
lines changed

.github/workflows/nix-build-using-docker.yaml

+19-11
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ jobs:
2727
- name: Test binfmt availability
2828
run: |
2929
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
30+
# non flake way to build
31+
# - name: Build SD Image
32+
# run: |
33+
# nix-build '<nixos/nixos>' \
34+
# -A config.system.build.sdImage \
35+
# -I nixos-config=./configuration.default.sdImage.nix \
36+
# --argstr system aarch64-linux \
37+
# --option sandbox false
3038
- name: Build SD Image
3139
run: |
32-
nix-build '<nixos/nixos>' \
33-
-A config.system.build.sdImage \
34-
-I nixos-config=./configuration.default.sdImage.nix \
35-
--argstr system aarch64-linux \
36-
--option sandbox false
40+
nix build .#nixosConfigurations.raspberry-pi_3_default.config.system.build.sdImage
3741
- uses: actions/upload-artifact@v4
3842
with:
3943
name: sd-image.img
@@ -62,16 +66,20 @@ jobs:
6266
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
6367
- name: Extract configuration from secrets
6468
run: |
65-
cat << EOF >> configuration.custom.sdImage.nix
69+
cat << EOF >> configuration.nix
6670
${{ secrets.CONFIGURATION_NIX }}
6771
EOF
72+
# non nix flake way to build
73+
# - name: Build SD Image
74+
# run: |
75+
# nix-build '<nixos/nixos>' \
76+
# -A config.system.build.sdImage \
77+
# -I nixos-config=./configuration.custom.sdImage.nix \
78+
# --argstr system aarch64-linux \
79+
# --option sandbox false
6880
- name: Build SD Image
6981
run: |
70-
nix-build '<nixos/nixos>' \
71-
-A config.system.build.sdImage \
72-
-I nixos-config=./configuration.custom.sdImage.nix \
73-
--argstr system aarch64-linux \
74-
--option sandbox false
82+
nix build .#nixosConfigurations.raspberry-pi_3_default.config.system.build.sdImage
7583
- uses: actions/upload-artifact@v4
7684
with:
7785
name: sd-image.img

README.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Model:
77

88
# Using prebuilt image available on Hydra
99

10-
The latest image is on Hydra:
10+
The latest image is on Hydra (example. You might need to change NixOS version in the following URL):
1111

1212
[sd-image](https://hydra.nixos.org/job/nixos/release-20.09/nixos.sd_image.aarch64-linux/latest/download-by-type/file/sd-image)
1313

@@ -47,7 +47,9 @@ I already setup a workflow manual dispatch Github Action in this repo, so to bui
4747
1. Fork the repo so you can build your own custom image
4848
2. Create your build/deployment environment.
4949

50-
From your repo settings page, click the Environments menu. Click New environment. Give it a name other than `default`. Define environment secrets called `CONFIGURATION_NIX`. The content should be your sd Image Nix recipe (not your future NixOS configuration.nix). See the sample template file in: [configuration.default.sdImage.nix](configuration.default.sdImage.nix) or [configuration.sdImage.nix](configuration.sdImage.nix)
50+
From your repo settings page, click the Environments menu. Click New environment. Give it a name other than `default`. Define environment secrets called `CONFIGURATION_NIX`.
51+
The content should be your custom `configuration.nix` file.
52+
This will be imported by the `configuration.sdImage.nix`.
5153

5254
3. Run your workflow
5355

@@ -151,6 +153,25 @@ nix-build '<nixos/nixos>' -A config.system.build.sdImage -I nixos-config=./confi
151153
--option sandbox false
152154
```
153155

156+
# Building using Nix Flake
157+
158+
You must be on a NixOS machine or Nix on Linux. The architecture won't matter.
159+
160+
Following the previous guide on Building in x86_64 or ARM machine with Linux, the command is replaced
161+
with Nix Flake command.
162+
163+
```shell
164+
nix build .#nixosConfigurations.raspberry-pi_3.config.system.build.sdImage
165+
```
166+
167+
Note, that since you can execute nix build on a remote flake, if your `configuration.nix` is already
168+
stored in your repo, then you can build locally against remote flake (no need to git clone).
169+
170+
```shell
171+
# example using this repo as the remote flake address
172+
nix build github:lucernae/nixos-pi#nixosConfigurations.raspberry-pi_3.config.system.build.sdImage
173+
```
174+
154175
# Building using Docker
155176

156177
Theoritically we can also build cross-platform using Docker container.

configuration.default.nix

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{ config, pkgs, lib, ... }:
2+
{
3+
# NixOS wants to enable GRUB by default
4+
boot.loader.grub.enable = false;
5+
# Enables the generation of /boot/extlinux/extlinux.conf
6+
boot.loader.generic-extlinux-compatible.enable = true;
7+
8+
# !!! Set to specific linux kernel version
9+
boot.kernelPackages = pkgs.linuxPackages;
10+
11+
# Disable ZFS on kernel 6
12+
boot.supportedFilesystems = lib.mkForce [
13+
"vfat"
14+
"xfs"
15+
"cifs"
16+
"ntfs"
17+
];
18+
19+
# !!! Needed for the virtual console to work on the RPi 3, as the default of 16M doesn't seem to be enough.
20+
# If X.org behaves weirdly (I only saw the cursor) then try increasing this to 256M.
21+
# On a Raspberry Pi 4 with 4 GB, you should either disable this parameter or increase to at least 64M if you want the USB ports to work.
22+
boot.kernelParams = [ "cma=256M" ];
23+
24+
# File systems configuration for using the installer's partition layout
25+
fileSystems = {
26+
# Prior to 19.09, the boot partition was hosted on the smaller first partition
27+
# Starting with 19.09, the /boot folder is on the main bigger partition.
28+
# The following is to be used only with older images.
29+
/*
30+
"/boot" = {
31+
device = "/dev/disk/by-label/NIXOS_BOOT";
32+
fsType = "vfat";
33+
};
34+
*/
35+
"/" = {
36+
device = "/dev/disk/by-label/NIXOS_SD";
37+
fsType = "ext4";
38+
};
39+
};
40+
41+
# !!! Adding a swap file is optional, but strongly recommended!
42+
swapDevices = [{ device = "/swapfile"; size = 1024; }];
43+
44+
# Settings above are the bare minimum
45+
# All settings below are customized depending on your needs
46+
47+
# systemPackages
48+
environment.systemPackages = with pkgs; [
49+
vim
50+
curl
51+
wget
52+
nano
53+
bind
54+
kubectl
55+
kubernetes-helm
56+
iptables
57+
openvpn
58+
python3
59+
nodejs
60+
docker-compose
61+
];
62+
63+
services.openssh = {
64+
enable = true;
65+
settings.PermitRootLogin = "yes";
66+
};
67+
68+
programs.zsh = {
69+
enable = true;
70+
ohMyZsh = {
71+
enable = true;
72+
theme = "bira";
73+
};
74+
};
75+
76+
77+
virtualisation.docker.enable = true;
78+
79+
networking.firewall.enable = false;
80+
81+
# WiFi
82+
hardware = {
83+
enableRedistributableFirmware = true;
84+
firmware = [ pkgs.wireless-regdb ];
85+
};
86+
87+
# put your own configuration here, for example ssh keys:
88+
users.defaultUserShell = pkgs.zsh;
89+
users.mutableUsers = true;
90+
users.groups = {
91+
nixos = {
92+
gid = 1000;
93+
name = "nixos";
94+
};
95+
};
96+
users.users = {
97+
nixos = {
98+
uid = 1000;
99+
home = "/home/nixos";
100+
name = "nixos";
101+
group = "nixos";
102+
shell = pkgs.zsh;
103+
extraGroups = [ "wheel" "docker" ];
104+
};
105+
};
106+
users.users.root.openssh.authorizedKeys.keys = [
107+
# Your ssh key
108+
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqlXJv/noNPmZMIfjJguRX3O+Z39xeoKhjoIBEyfeqgKGh9JOv7IDBWlNnd3rHVnVPzB9emiiEoAJpkJUnWNBidL6vPYn13r6Zrt/2WLT6TiUFU026ANdqMjIMEZrmlTsfzFT+OzpBqtByYOGGe19qD3x/29nbszPODVF2giwbZNIMo2x7Ww96U4agb2aSAwo/oQa4jQsnOpYRMyJQqCUhvX8LzvE9vFquLlrSyd8khUsEVV/CytmdKwUUSqmlo/Mn7ge/S12rqMwmLvWFMd08Rg9NHvRCeOjgKB4EI6bVwF8D6tNFnbsGVzTHl7Cosnn75U11CXfQ6+8MPq3cekYr lucernae@lombardia-N43SM"
109+
];
110+
system.stateVersion = "23.05";
111+
}

configuration.default.sdImage.nix

+4-98
Original file line numberDiff line numberDiff line change
@@ -6,106 +6,12 @@
66

77
# For nixpkgs cache
88
<nixos/nixos/modules/installer/cd-dvd/channel.nix>
9-
];
10-
11-
sdImage.compressImage = true;
12-
13-
14-
# NixOS wants to enable GRUB by default
15-
boot.loader.grub.enable = false;
16-
# Enables the generation of /boot/extlinux/extlinux.conf
17-
boot.loader.generic-extlinux-compatible.enable = true;
18-
19-
# !!! Set to specific linux kernel version
20-
boot.kernelPackages = pkgs.linuxPackages;
219

22-
# Disable ZFS on kernel 6
23-
boot.supportedFilesystems = lib.mkForce [
24-
"vfat"
25-
"xfs"
26-
"cifs"
27-
"ntfs"
10+
# main configuration
11+
./configuration.default.nix
2812
];
2913

30-
# !!! Needed for the virtual console to work on the RPi 3, as the default of 16M doesn't seem to be enough.
31-
# If X.org behaves weirdly (I only saw the cursor) then try increasing this to 256M.
32-
# On a Raspberry Pi 4 with 4 GB, you should either disable this parameter or increase to at least 64M if you want the USB ports to work.
33-
boot.kernelParams = ["cma=256M"];
34-
35-
# File systems configuration for using the installer's partition layout
36-
fileSystems = {
37-
# Prior to 19.09, the boot partition was hosted on the smaller first partition
38-
# Starting with 19.09, the /boot folder is on the main bigger partition.
39-
# The following is to be used only with older images.
40-
/*
41-
"/boot" = {
42-
device = "/dev/disk/by-label/NIXOS_BOOT";
43-
fsType = "vfat";
44-
};
45-
*/
46-
"/" = {
47-
device = "/dev/disk/by-label/NIXOS_SD";
48-
fsType = "ext4";
49-
};
50-
};
51-
52-
# !!! Adding a swap file is optional, but strongly recommended!
53-
swapDevices = [ { device = "/swapfile"; size = 1024; } ];
54-
55-
# Settings above are the bare minimum
56-
# All settings below are customized depending on your needs
57-
58-
# systemPackages
59-
environment.systemPackages = with pkgs; [
60-
vim curl wget nano bind kubectl kubernetes-helm iptables openvpn
61-
python3 nodejs docker-compose ];
62-
63-
services.openssh = {
64-
enable = true;
65-
settings.PermitRootLogin = "yes";
66-
};
67-
68-
programs.zsh = {
69-
enable = true;
70-
ohMyZsh = {
71-
enable = true;
72-
theme = "bira";
73-
};
74-
};
75-
76-
77-
virtualisation.docker.enable = true;
78-
79-
networking.firewall.enable = false;
80-
81-
# WiFi
82-
hardware = {
83-
enableRedistributableFirmware = true;
84-
firmware = [ pkgs.wireless-regdb ];
85-
};
14+
sdImage.compressImage = true;
8615

87-
# put your own configuration here, for example ssh keys:
88-
users.defaultUserShell = pkgs.zsh;
89-
users.mutableUsers = true;
90-
users.groups = {
91-
nixos = {
92-
gid = 1000;
93-
name = "nixos";
94-
};
95-
};
96-
users.users = {
97-
nixos = {
98-
uid = 1000;
99-
home = "/home/nixos";
100-
name = "nixos";
101-
group = "nixos";
102-
shell = pkgs.zsh;
103-
extraGroups = [ "wheel" "docker" ];
104-
};
105-
};
106-
users.users.root.openssh.authorizedKeys.keys = [
107-
# Your ssh key
108-
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqlXJv/noNPmZMIfjJguRX3O+Z39xeoKhjoIBEyfeqgKGh9JOv7IDBWlNnd3rHVnVPzB9emiiEoAJpkJUnWNBidL6vPYn13r6Zrt/2WLT6TiUFU026ANdqMjIMEZrmlTsfzFT+OzpBqtByYOGGe19qD3x/29nbszPODVF2giwbZNIMo2x7Ww96U4agb2aSAwo/oQa4jQsnOpYRMyJQqCUhvX8LzvE9vFquLlrSyd8khUsEVV/CytmdKwUUSqmlo/Mn7ge/S12rqMwmLvWFMd08Rg9NHvRCeOjgKB4EI6bVwF8D6tNFnbsGVzTHl7Cosnn75U11CXfQ6+8MPq3cekYr lucernae@lombardia-N43SM"
109-
];
110-
system.stateVersion = "23.05";
16+
system.copySystemConfiguration = true;
11117
}

0 commit comments

Comments
 (0)