Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add templates to allow easy inheritance of Ghaf #164

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/src/ref_impl/custom_product.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
Copyright 2022-2023 TII (SSRC) and the Ghaf contributors
SPDX-License-Identifier: CC-BY-SA-4.0
-->

# Derive a Custom Project From Ghaf

Ghaf is a framework for creating virtualized edge devices, it is therefore expected that projects wishing to use Ghaf should import it to create a derived work
for the specific use case.

Ghaf provides a number templates for the reference hardware to ease this process.

## Creating a custom derivation

1. Check the available target templates
```
nix flake show github:tiiuae/ghaf
```
2. Select the appropriate template e.g. `target-aarch64-nvidia-orin-agx`
```
nix flake new --template github:tiiuae/ghaf#target-aarch64-nvidia-orin-agx /my/new/project/folder
```
3. Change the placeholder `<PROJ NAME>` to your new projects name e.g. `cool_project`
```
sed -i 's/PROJ_NAME/cool_project/g' flake.nix
```
4. Hack, test, commit, contribute back to Ghaf ;) ...
1 change: 1 addition & 0 deletions docs/src/ref_impl/reference_implementations.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ The same goes with the architectural variants as headless devices or end-user de
- [Build and Run](./build_and_run.md)
- [Development](./development.md)
- [Cross-Compilation](./cross_compilation.md)
- [Define a Custom Project from Ghaf](./custom_product.md)
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@

# Hydra jobs
(import ./hydrajobs.nix {inherit self;})

#templates
(import ./templates {inherit self;})
];
}
42 changes: 42 additions & 0 deletions templates/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2022-2023 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{self}: {
templates = {
#TODO Enable when module system is in place
# # Module template
# ghaf-module = {
# path = ./module;
# description = "A config to bootstrap a Ghaf compatible module";
# };

# A Selection of targets that utilize Ghaf to define more feature rich
# projects/products.

# ARM targets
target-aarch64-nvidia-orin-agx = {
path = ./targets/aarch64/nvidia/orin-agx;
description = "A Ghaf based configuration for the Nvidia Orin AGX";
};
target-aarch64-nvidia-orin-nx = {
path = ./targets/aarch64/nvidia/orin-nx;
description = "A Ghaf based configuration for the Nvidia Orin NX";
};
target-aarch64-nxp-imx8 = {
path = ./targets/aarch64/nxp/imx8;
description = "A Ghaf based configuration for the NXP iMX8";
};

# x86 targets
target-x86_64-generic = {
path = ./targets/x86_64/generic;
description = "A Ghaf based configuration for x86_64 targets";
};

#TODO Enable this when polarfire is merged
# # RISC-v targets
# target-riscv64-microchip-polarfire = {
# path = ./targets/riscv64/microchip/polarfire;
# description = "A Ghaf based configuration for the Microchip Polarfire";
# };
};
}
72 changes: 72 additions & 0 deletions templates/targets/aarch64/nvidia/orin-agx/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2022-2023 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
description = "<PROJ NAME> - Ghaf based configuration";

nixConfig = {
extra-trusted-substituters = [
"https://cache.vedenemo.dev"
"https://cache.ssrcdevops.tii.ae"
];
extra-trusted-public-keys = [
"cache.vedenemo.dev:RGHheQnb6rXGK5v9gexJZ8iWTPX6OcSeS56YeXYzOcg="
"cache.ssrcdevops.tii.ae:oOrzj9iCppf+me5/3sN/BxEkp5SaFkHfKTPPZ97xXQk="
];
};

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
flake-utils.url = "github:numtide/flake-utils";
jetpack-nixos = {
url = "github:anduril/jetpack-nixos";
inputs.nixpkgs.follows = "nixpkgs";
};
ghaf = {
url = "github:tiiuae/ghaf";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
jetpack-nixos.follows = "jetpack-nixos";
};
};
};

outputs = {
self,
ghaf,
nixpkgs,
jetpack-nixos,
flake-utils,
}: let
systems = with flake-utils.lib.system; [
x86_64-linux
aarch64-linux
];
mkFlashScript = import (ghaf + "/modules/hardware/nvidia-jetson-orin/mk-flash-script.nix");
in
# Combine list of attribute sets together
nixpkgs.lib.foldr nixpkgs.lib.recursiveUpdate {} [
(flake-utils.lib.eachSystem systems (system: {
formatter = nixpkgs.legacyPackages.${system}.alejandra;
}))

{
nixosConfigurations.PROJ_NAME-ghaf-debug = ghaf.nixosConfigurations.nvidia-jetson-orin-debug.extendModules {
modules = [
{
#insert your additional modules here e.g.
# virtualisation.docker.enable = true;
# users.users."ghaf".extraGroups = ["docker"];
}
];
};
packages.aarch64-linux.PROJ_NAME-ghaf-debug = self.nixosConfigurations.PROJ_NAME-ghaf-debug.config.system.build.${self.nixosConfigurations.PROJ_NAME-ghaf-debug.config.formatAttr};

packages.x86_64-linux.PROJ_NAME-ghaf-debug-flash-script = mkFlashScript {
inherit nixpkgs jetpack-nixos;
hostConfiguration = self.nixosConfigurations.PROJ_NAME-ghaf-debug;
flash-tools-system = flake-utils.lib.system.x86_64-linux;
};
}
];
}
72 changes: 72 additions & 0 deletions templates/targets/aarch64/nvidia/orin-nx/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2022-2023 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
description = "PROJ_NAME - Ghaf based configuration";

nixConfig = {
extra-trusted-substituters = [
"https://cache.vedenemo.dev"
"https://cache.ssrcdevops.tii.ae"
];
extra-trusted-public-keys = [
"cache.vedenemo.dev:RGHheQnb6rXGK5v9gexJZ8iWTPX6OcSeS56YeXYzOcg="
"cache.ssrcdevops.tii.ae:oOrzj9iCppf+me5/3sN/BxEkp5SaFkHfKTPPZ97xXQk="
];
};

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
flake-utils.url = "github:numtide/flake-utils";
jetpack-nixos = {
url = "github:anduril/jetpack-nixos";
inputs.nixpkgs.follows = "nixpkgs";
};
ghaf = {
url = "github:tiiuae/ghaf";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
jetpack-nixos.follows = "jetpack-nixos";
};
};
};

outputs = {
self,
ghaf,
nixpkgs,
jetpack-nixos,
flake-utils,
}: let
systems = with flake-utils.lib.system; [
x86_64-linux
aarch64-linux
];
mkFlashScript = import (ghaf + "/modules/hardware/nvidia-jetson-orin/mk-flash-script.nix");
in
# Combine list of attribute sets together
nixpkgs.lib.foldr nixpkgs.lib.recursiveUpdate {} [
(flake-utils.lib.eachSystem systems (system: {
formatter = nixpkgs.legacyPackages.${system}.alejandra;
}))

{
nixosConfigurations.PROJ_NAME-ghaf-debug = ghaf.nixosConfigurations.nvidia-jetson-orin-debug.extendModules {
modules = [
{
#insert your additional modules here e.g.
# virtualisation.docker.enable = true;
# users.users."ghaf".extraGroups = ["docker"];
}
];
};
packages.aarch64-linux.PROJ_NAME-ghaf-debug = self.nixosConfigurations.PROJ_NAME-ghaf-debug.config.system.build.${self.nixosConfigurations.fog-ghaf-debug.config.formatAttr};

packages.x86_64-linux.PROJ_NAME-ghaf-debug-flash-script = mkFlashScript {
inherit nixpkgs jetpack-nixos;
hostConfiguration = self.nixosConfigurations.PROJ_NAME-ghaf-debug;
flash-tools-system = flake-utils.lib.system.x86_64-linux;
};
}
];
}
62 changes: 62 additions & 0 deletions templates/targets/aarch64/nxp/imx8/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2022-2023 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
description = "PROJ_NAME - Ghaf based configuration";

nixConfig = {
extra-trusted-substituters = [
"https://cache.vedenemo.dev"
"https://cache.ssrcdevops.tii.ae"
];
extra-trusted-public-keys = [
"cache.vedenemo.dev:RGHheQnb6rXGK5v9gexJZ8iWTPX6OcSeS56YeXYzOcg="
"cache.ssrcdevops.tii.ae:oOrzj9iCppf+me5/3sN/BxEkp5SaFkHfKTPPZ97xXQk="
];
};

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
flake-utils.url = "github:numtide/flake-utils";
nixos-hardware.url = "github:nixos/nixos-hardware";
ghaf = {
url = "github:tiiuae/ghaf";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
nixos-hardware.follows = "nixos-hardware";
};
};
};

outputs = {
self,
ghaf,
nixpkgs,
nixos-hardware,
flake-utils,
}: let
systems = with flake-utils.lib.system; [
x86_64-linux
aarch64-linux
];
in
# Combine list of attribute sets together
nixpkgs.lib.foldr nixpkgs.lib.recursiveUpdate {} [
(flake-utils.lib.eachSystem systems (system: {
formatter = nixpkgs.legacyPackages.${system}.alejandra;
}))

{
nixosConfigurations.PROJ_NAME-ghaf-debug = ghaf.nixosConfigurations.imx8qm-mek-debug.extendModules {
modules = [
{
#insert your additional modules here e.g.
# virtualisation.docker.enable = true;
# users.users."ghaf".extraGroups = ["docker"];
}
];
};
packages.aarch64-linux.PROJ_NAME-ghaf-debug = self.nixosConfigurations.PROJ_NAME-ghaf-debug.config.system.build.${self.nixosConfigurations.PROJ_NAME-ghaf-debug.config.formatAttr};
}
];
}
65 changes: 65 additions & 0 deletions templates/targets/x86_64/generic/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2022-2023 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
description = "PROJ_NAME - Ghaf based configuration";

nixConfig = {
extra-trusted-substituters = [
"https://cache.vedenemo.dev"
"https://cache.ssrcdevops.tii.ae"
];
extra-trusted-public-keys = [
"cache.vedenemo.dev:RGHheQnb6rXGK5v9gexJZ8iWTPX6OcSeS56YeXYzOcg="
"cache.ssrcdevops.tii.ae:oOrzj9iCppf+me5/3sN/BxEkp5SaFkHfKTPPZ97xXQk="
];
};

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
flake-utils.url = "github:numtide/flake-utils";
nixos-hardware.url = "github:nixos/nixos-hardware";
ghaf = {
url = "github:tiiuae/ghaf";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
nixos-hardware.follows = "nixos-hardware";
};
};
};

outputs = {
self,
ghaf,
nixpkgs,
nixos-hardware,
flake-utils,
}: let
systems = with flake-utils.lib.system; [
x86_64-linux
];
in
# Combine list of attribute sets together
nixpkgs.lib.foldr nixpkgs.lib.recursiveUpdate {} [
(flake-utils.lib.eachSystem systems (system: {
formatter = nixpkgs.legacyPackages.${system}.alejandra;
}))

{
nixosConfigurations.PROJ_NAME-ghaf-debug = ghaf.nixosConfigurations.generic-x86_64-debug.extendModules {
modules = [
{
#insert your additional modules here e.g.
# virtualisation.docker.enable = true;
# users.users."ghaf".extraGroups = ["docker"];

# To handle the majority of laptops we need a little something extra
# TODO:: SEE: https://github.com/NixOS/nixos-hardware/blob/master/flake.nix
# nixos-hardware.nixosModules.lenovo-thinkpad-x1-10th-gen
}
];
};
packages.x86_64-linux.PROJ_NAME-ghaf-debug = self.nixosConfigurations.PROJ_NAME-ghaf-debug.config.system.build.${self.nixosConfigurations.PROJ_NAME-ghaf-debug.config.formatAttr};
}
];
}