Skip to content

Commit

Permalink
add: flake config to build
Browse files Browse the repository at this point in the history
  • Loading branch information
lucernae committed Mar 30, 2024
1 parent 467a8b3 commit d7b48fa
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 154 deletions.
30 changes: 19 additions & 11 deletions .github/workflows/nix-build-using-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ jobs:
- name: Test binfmt availability
run: |
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
# non flake way to build
# - name: Build SD Image
# run: |
# nix-build '<nixos/nixos>' \
# -A config.system.build.sdImage \
# -I nixos-config=./configuration.default.sdImage.nix \
# --argstr system aarch64-linux \
# --option sandbox false
- name: Build SD Image
run: |
nix-build '<nixos/nixos>' \
-A config.system.build.sdImage \
-I nixos-config=./configuration.default.sdImage.nix \
--argstr system aarch64-linux \
--option sandbox false
nix build .#nixosConfigurations.raspberry-pi_3_default.config.system.build.sdImage
- uses: actions/upload-artifact@v4
with:
name: sd-image.img
Expand Down Expand Up @@ -62,16 +66,20 @@ jobs:
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
- name: Extract configuration from secrets
run: |
cat << EOF >> configuration.custom.sdImage.nix
cat << EOF >> configuration.nix
${{ secrets.CONFIGURATION_NIX }}
EOF
# non nix flake way to build
# - name: Build SD Image
# run: |
# nix-build '<nixos/nixos>' \
# -A config.system.build.sdImage \
# -I nixos-config=./configuration.custom.sdImage.nix \
# --argstr system aarch64-linux \
# --option sandbox false
- name: Build SD Image
run: |
nix-build '<nixos/nixos>' \
-A config.system.build.sdImage \
-I nixos-config=./configuration.custom.sdImage.nix \
--argstr system aarch64-linux \
--option sandbox false
nix build .#nixosConfigurations.raspberry-pi_3_default.config.system.build.sdImage
- uses: actions/upload-artifact@v4
with:
name: sd-image.img
Expand Down
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Model:

# Using prebuilt image available on Hydra

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

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

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

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)
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 custom `configuration.nix` file.
This will be imported by the `configuration.sdImage.nix`.

3. Run your workflow

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

# Building using Nix Flake

You must be on a NixOS machine or Nix on Linux. The architecture won't matter.

Following the previous guide on Building in x86_64 or ARM machine with Linux, the command is replaced
with Nix Flake command.

```shell
nix build .#nixosConfigurations.raspberry-pi_3.config.system.build.sdImage
```

Note, that since you can execute nix build on a remote flake, if your `configuration.nix` is already
stored in your repo, then you can build locally against remote flake (no need to git clone).

```shell
# example using this repo as the remote flake address
nix build github:lucernae/nixos-pi#nixosConfigurations.raspberry-pi_3.config.system.build.sdImage
```

# Building using Docker

Theoritically we can also build cross-platform using Docker container.
Expand Down
111 changes: 111 additions & 0 deletions configuration.default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{ config, pkgs, lib, ... }:
{
# NixOS wants to enable GRUB by default
boot.loader.grub.enable = false;
# Enables the generation of /boot/extlinux/extlinux.conf
boot.loader.generic-extlinux-compatible.enable = true;

# !!! Set to specific linux kernel version
boot.kernelPackages = pkgs.linuxPackages;

# Disable ZFS on kernel 6
boot.supportedFilesystems = lib.mkForce [
"vfat"
"xfs"
"cifs"
"ntfs"
];

# !!! Needed for the virtual console to work on the RPi 3, as the default of 16M doesn't seem to be enough.
# If X.org behaves weirdly (I only saw the cursor) then try increasing this to 256M.
# 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.
boot.kernelParams = [ "cma=256M" ];

# File systems configuration for using the installer's partition layout
fileSystems = {
# Prior to 19.09, the boot partition was hosted on the smaller first partition
# Starting with 19.09, the /boot folder is on the main bigger partition.
# The following is to be used only with older images.
/*
"/boot" = {
device = "/dev/disk/by-label/NIXOS_BOOT";
fsType = "vfat";
};
*/
"/" = {
device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4";
};
};

# !!! Adding a swap file is optional, but strongly recommended!
swapDevices = [{ device = "/swapfile"; size = 1024; }];

# Settings above are the bare minimum
# All settings below are customized depending on your needs

# systemPackages
environment.systemPackages = with pkgs; [
vim
curl
wget
nano
bind
kubectl
kubernetes-helm
iptables
openvpn
python3
nodejs
docker-compose
];

services.openssh = {
enable = true;
settings.PermitRootLogin = "yes";
};

programs.zsh = {
enable = true;
ohMyZsh = {
enable = true;
theme = "bira";
};
};


virtualisation.docker.enable = true;

networking.firewall.enable = false;

# WiFi
hardware = {
enableRedistributableFirmware = true;
firmware = [ pkgs.wireless-regdb ];
};

# put your own configuration here, for example ssh keys:
users.defaultUserShell = pkgs.zsh;
users.mutableUsers = true;
users.groups = {
nixos = {
gid = 1000;
name = "nixos";
};
};
users.users = {
nixos = {
uid = 1000;
home = "/home/nixos";
name = "nixos";
group = "nixos";
shell = pkgs.zsh;
extraGroups = [ "wheel" "docker" ];
};
};
users.users.root.openssh.authorizedKeys.keys = [
# Your ssh key
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqlXJv/noNPmZMIfjJguRX3O+Z39xeoKhjoIBEyfeqgKGh9JOv7IDBWlNnd3rHVnVPzB9emiiEoAJpkJUnWNBidL6vPYn13r6Zrt/2WLT6TiUFU026ANdqMjIMEZrmlTsfzFT+OzpBqtByYOGGe19qD3x/29nbszPODVF2giwbZNIMo2x7Ww96U4agb2aSAwo/oQa4jQsnOpYRMyJQqCUhvX8LzvE9vFquLlrSyd8khUsEVV/CytmdKwUUSqmlo/Mn7ge/S12rqMwmLvWFMd08Rg9NHvRCeOjgKB4EI6bVwF8D6tNFnbsGVzTHl7Cosnn75U11CXfQ6+8MPq3cekYr lucernae@lombardia-N43SM"
];
system.stateVersion = "23.05";
}
102 changes: 4 additions & 98 deletions configuration.default.sdImage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,106 +6,12 @@

# For nixpkgs cache
<nixos/nixos/modules/installer/cd-dvd/channel.nix>
];

sdImage.compressImage = true;


# NixOS wants to enable GRUB by default
boot.loader.grub.enable = false;
# Enables the generation of /boot/extlinux/extlinux.conf
boot.loader.generic-extlinux-compatible.enable = true;

# !!! Set to specific linux kernel version
boot.kernelPackages = pkgs.linuxPackages;

# Disable ZFS on kernel 6
boot.supportedFilesystems = lib.mkForce [
"vfat"
"xfs"
"cifs"
"ntfs"
# main configuration
./configuration.default.nix
];

# !!! Needed for the virtual console to work on the RPi 3, as the default of 16M doesn't seem to be enough.
# If X.org behaves weirdly (I only saw the cursor) then try increasing this to 256M.
# 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.
boot.kernelParams = ["cma=256M"];

# File systems configuration for using the installer's partition layout
fileSystems = {
# Prior to 19.09, the boot partition was hosted on the smaller first partition
# Starting with 19.09, the /boot folder is on the main bigger partition.
# The following is to be used only with older images.
/*
"/boot" = {
device = "/dev/disk/by-label/NIXOS_BOOT";
fsType = "vfat";
};
*/
"/" = {
device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4";
};
};

# !!! Adding a swap file is optional, but strongly recommended!
swapDevices = [ { device = "/swapfile"; size = 1024; } ];

# Settings above are the bare minimum
# All settings below are customized depending on your needs

# systemPackages
environment.systemPackages = with pkgs; [
vim curl wget nano bind kubectl kubernetes-helm iptables openvpn
python3 nodejs docker-compose ];

services.openssh = {
enable = true;
settings.PermitRootLogin = "yes";
};

programs.zsh = {
enable = true;
ohMyZsh = {
enable = true;
theme = "bira";
};
};


virtualisation.docker.enable = true;

networking.firewall.enable = false;

# WiFi
hardware = {
enableRedistributableFirmware = true;
firmware = [ pkgs.wireless-regdb ];
};
sdImage.compressImage = true;

# put your own configuration here, for example ssh keys:
users.defaultUserShell = pkgs.zsh;
users.mutableUsers = true;
users.groups = {
nixos = {
gid = 1000;
name = "nixos";
};
};
users.users = {
nixos = {
uid = 1000;
home = "/home/nixos";
name = "nixos";
group = "nixos";
shell = pkgs.zsh;
extraGroups = [ "wheel" "docker" ];
};
};
users.users.root.openssh.authorizedKeys.keys = [
# Your ssh key
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqlXJv/noNPmZMIfjJguRX3O+Z39xeoKhjoIBEyfeqgKGh9JOv7IDBWlNnd3rHVnVPzB9emiiEoAJpkJUnWNBidL6vPYn13r6Zrt/2WLT6TiUFU026ANdqMjIMEZrmlTsfzFT+OzpBqtByYOGGe19qD3x/29nbszPODVF2giwbZNIMo2x7Ww96U4agb2aSAwo/oQa4jQsnOpYRMyJQqCUhvX8LzvE9vFquLlrSyd8khUsEVV/CytmdKwUUSqmlo/Mn7ge/S12rqMwmLvWFMd08Rg9NHvRCeOjgKB4EI6bVwF8D6tNFnbsGVzTHl7Cosnn75U11CXfQ6+8MPq3cekYr lucernae@lombardia-N43SM"
];
system.stateVersion = "23.05";
system.copySystemConfiguration = true;
}
Loading

0 comments on commit d7b48fa

Please sign in to comment.