Skip to content

Commit

Permalink
reformat with nixfmt
Browse files Browse the repository at this point in the history
Signed-off-by: Jörg Thalheim <[email protected]>
  • Loading branch information
Mic92 authored and brianmcgillion committed Aug 15, 2024
1 parent f5bc408 commit 1f2aed3
Show file tree
Hide file tree
Showing 241 changed files with 4,307 additions and 4,091 deletions.
14 changes: 11 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
# This file originates from:
# https://github.com/nix-community/flake-compat
# This file provides backward compatibility to nix < 2.4 clients
{system ? builtins.currentSystem}: let
{
system ? builtins.currentSystem,
}:
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);

inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;
inherit (lock.nodes.flake-compat.locked)
owner
repo
rev
narHash
;

flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
Expand All @@ -20,4 +28,4 @@
src = ./.;
};
in
flake.defaultNix
flake.defaultNix
34 changes: 19 additions & 15 deletions docs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@
mdbook-alerts,
mdbook-footnote,
revision ? "",
options ? {},
}: let
options ? { },
}:
let
optionsDocMd =
(nixosOptionsDoc {
inherit revision options;
transformOptions = x:
# TODO this hides the other modules (e.g. microvm.nix)
# But they are stilled passed as options modules ???
if lib.strings.hasPrefix "ghaf" x.name
then x
else x // {visible = false;};
transformOptions =
x:
# TODO this hides the other modules (e.g. microvm.nix)
# But they are stilled passed as options modules ???
if lib.strings.hasPrefix "ghaf" x.name then x else x // { visible = false; };
markdownByDefault = true;
})
.optionsCommonMark;
combinedSrc = runCommandLocal "ghaf-doc-src" {} ''
}).optionsCommonMark;
combinedSrc = runCommandLocal "ghaf-doc-src" { } ''
mkdir $out
cp -r ${./.}/* $out
chmod +w $out/src/ref_impl/modules_options.md
Expand All @@ -32,10 +31,14 @@
sed 's/\(file:\/\/\)\?\/nix\/store\/[^/]*-source/https:\/\/github.com\/tiiuae\/ghaf\/blob\/main/g' ${optionsDocMd} >> $out/src/ref_impl/modules_options.md
'';
in
# TODO Change this, runCommandLocal is not intended for longer running processes
runCommandLocal "ghaf-doc"
# TODO Change this, runCommandLocal is not intended for longer running processes
runCommandLocal "ghaf-doc"
{
nativeBuildInputs = [mdbook mdbook-footnote mdbook-alerts];
nativeBuildInputs = [
mdbook
mdbook-footnote
mdbook-alerts
];
src = combinedSrc;

# set the package Meta info
Expand All @@ -47,6 +50,7 @@ in
"aarch64-linux"
];
};
} ''
}
''
${mdbook}/bin/mdbook build -d $out $src
''
15 changes: 7 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

inputs = {
#TODO: clean this up before merging to main
nixpkgs.url = "github:tiiuae/nixpkgs/nixos-unstable-texinfo"; #"flake:mylocalnixpkgs"; #
nixpkgs.url = "github:tiiuae/nixpkgs/nixos-unstable-texinfo"; # "flake:mylocalnixpkgs"; #
#nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

#
Expand Down Expand Up @@ -130,13 +130,12 @@
};
};

outputs = inputs @ {flake-parts, ...}: let
lib = import ./lib.nix {inherit inputs;};
in
flake-parts.lib.mkFlake
{
inherit inputs;
} {
outputs =
inputs@{ flake-parts, ... }:
let
lib = import ./lib.nix { inherit inputs; };
in
flake-parts.lib.mkFlake { inherit inputs; } {
# Toggle this to allow debugging in the repl
# see:https://flake.parts/debug
debug = false;
Expand Down
47 changes: 29 additions & 18 deletions hydrajobs/flake-module.nix
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{self, ...}: let
mkBpmpEnabled = cfg: let
bpmpEnableModule = {lib, ...}: {
ghaf.hardware.nvidia = {
virtualization.enable = lib.mkForce true;
virtualization.host.bpmp.enable = lib.mkForce true;
passthroughs.host.uarta.enable = lib.mkForce true;
};
};
newCfg = cfg.extendModules {modules = [bpmpEnableModule];};
package = newCfg.config.system.build.${newCfg.config.formatAttr};
in
{ self, ... }:
let
mkBpmpEnabled =
cfg:
let
bpmpEnableModule =
{ lib, ... }:
{
ghaf.hardware.nvidia = {
virtualization.enable = lib.mkForce true;
virtualization.host.bpmp.enable = lib.mkForce true;
passthroughs.host.uarta.enable = lib.mkForce true;
};
};
newCfg = cfg.extendModules { modules = [ bpmpEnableModule ]; };
package = newCfg.config.system.build.${newCfg.config.formatAttr};
in
package;
in {
in
{
flake.hydraJobs = {
generic-x86_64-debug.x86_64-linux = self.packages.x86_64-linux.generic-x86_64-debug;
lenovo-x1-carbon-gen11-debug.x86_64-linux = self.packages.x86_64-linux.lenovo-x1-carbon-gen11-debug;
nvidia-jetson-orin-agx-debug.aarch64-linux = self.packages.aarch64-linux.nvidia-jetson-orin-agx-debug;
nvidia-jetson-orin-agx-debug.aarch64-linux =
self.packages.aarch64-linux.nvidia-jetson-orin-agx-debug;
nvidia-jetson-orin-nx-debug.aarch64-linux = self.packages.aarch64-linux.nvidia-jetson-orin-nx-debug;
intel-vm-debug.x86_64-linux = self.packages.x86_64-linux.vm-debug;
nxp-imx8mp-evk-debug.x86_64-linux = self.packages.aarch64-linux.nxp-imx8mp-evk-debug;
docs.x86_64-linux = self.packages.x86_64-linux.doc;
docs.aarch64-linux = self.packages.aarch64-linux.doc;
microchip-icicle-kit-debug.x86_64-linux = self.packages.riscv64-linux.microchip-icicle-kit-debug;
# Build cross-copmiled images
nvidia-jetson-orin-agx-debug-from-x86_64.x86_64-linux = self.packages.x86_64-linux.nvidia-jetson-orin-agx-debug-from-x86_64;
nvidia-jetson-orin-nx-debug-from-x86_64.x86_64-linux = self.packages.x86_64-linux.nvidia-jetson-orin-nx-debug-from-x86_64;
nvidia-jetson-orin-agx-debug-from-x86_64.x86_64-linux =
self.packages.x86_64-linux.nvidia-jetson-orin-agx-debug-from-x86_64;
nvidia-jetson-orin-nx-debug-from-x86_64.x86_64-linux =
self.packages.x86_64-linux.nvidia-jetson-orin-nx-debug-from-x86_64;

# Build also cross-compiled images without demo apps
nvidia-jetson-orin-agx-debug-nodemoapps-from-x86_64.x86_64-linux = self.packages.x86_64-linux.nvidia-jetson-orin-agx-debug-nodemoapps-from-x86_64;
nvidia-jetson-orin-nx-debug-nodemoapps-from-x86_64.x86_64-linux = self.packages.x86_64-linux.nvidia-jetson-orin-nx-debug-nodemoapps-from-x86_64;
nvidia-jetson-orin-agx-debug-nodemoapps-from-x86_64.x86_64-linux =
self.packages.x86_64-linux.nvidia-jetson-orin-agx-debug-nodemoapps-from-x86_64;
nvidia-jetson-orin-nx-debug-nodemoapps-from-x86_64.x86_64-linux =
self.packages.x86_64-linux.nvidia-jetson-orin-nx-debug-nodemoapps-from-x86_64;

# BPMP virt enabled versions
nvidia-jetson-orin-agx-debug-bpmp.aarch64-linux = mkBpmpEnabled self.nixosConfigurations.nvidia-jetson-orin-agx-debug;
Expand Down
117 changes: 63 additions & 54 deletions lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
# SPDX-License-Identifier: MIT
# FlattenTree and rakeLeaves originate from
# https://github.com/divnix/digga
{inputs, ...}: let
{ inputs, ... }:
let
inherit (inputs) nixpkgs;
in
nixpkgs.lib.extend (lib: _:
# some utils for importing trees
rec {
/*
nixpkgs.lib.extend (
lib: _:
# some utils for importing trees
rec {
/*
*
Filters Nix packages based on the target system platform.
Returns a filtered attribute set of Nix packages compatible with the target system.
Expand All @@ -35,15 +37,21 @@ in
- [system] Target system platform (e.g., "x86_64-linux").
- [pkgsSet] a set of Nix packages.
*/
platformPkgs = system:
lib.filterAttrs
(_: value: let
platforms = lib.attrByPath ["meta" "platforms"] [] value;
*/
platformPkgs =
system:
lib.filterAttrs (
_: value:
let
platforms = lib.attrByPath [
"meta"
"platforms"
] [ ] value;
in
lib.elem system platforms);
lib.elem system platforms
);

/*
/*
*
Flattens a _tree_ of the shape that is produced by rakeLeaves.
An attrset with names in the spirit of the Reverse DNS Notation form
Expand All @@ -61,20 +69,19 @@ in
}
=> { "a.b.c" = <path>; }
```
*/
flattenTree = tree: let
op = sum: path: val: let
pathStr = builtins.concatStringsSep "." path; # dot-based reverse DNS notation
in
if builtins.isPath val
then
*/
flattenTree =
tree:
let
op =
sum: path: val:
let
pathStr = builtins.concatStringsSep "." path; # dot-based reverse DNS notation
in
if builtins.isPath val then
# builtins.trace "${toString val} is a path"
(sum
// {
"${pathStr}" = val;
})
else if builtins.isAttrs val
then
(sum // { "${pathStr}" = val; })
else if builtins.isAttrs val then
# builtins.trace "${builtins.toJSON val} is an attrset"
# recurse into that attribute set
(recurse sum path val)
Expand All @@ -83,15 +90,13 @@ in
# builtins.trace "${toString path} is something else"
sum;

recurse = sum: path: val:
builtins.foldl'
(sum: key: op sum (path ++ [key]) val.${key})
sum
(builtins.attrNames val);
recurse =
sum: path: val:
builtins.foldl' (sum: key: op sum (path ++ [ key ]) val.${key}) sum (builtins.attrNames val);
in
recurse {} [] tree;
recurse { } [ ] tree;

/*
/*
*
Recursively collect the nix files of _path_ into attrs.
Return an attribute set where all `.nix` files and directories with `default.nix` in them
Expand Down Expand Up @@ -120,34 +125,38 @@ in
};
}
```
*/

rakeLeaves = dirPath: let
seive = file: type:
# Only rake `.nix` files or directories
*/

rakeLeaves =
dirPath:
let
seive =
file: type:
# Only rake `.nix` files or directories
(type == "regular" && lib.hasSuffix ".nix" file) || (type == "directory");

collect = file: type: {
name = lib.removeSuffix ".nix" file;
value = let
path = dirPath + "/${file}";
in
if
(type == "regular")
|| (type == "directory" && builtins.pathExists (path + "/default.nix"))
then path
value =
let
path = dirPath + "/${file}";
in
if (type == "regular") || (type == "directory" && builtins.pathExists (path + "/default.nix")) then
path
# recurse on directories that don't contain a `default.nix`
else rakeLeaves path;
else
rakeLeaves path;
};

files = lib.filterAttrs seive (builtins.readDir dirPath);
in
lib.filterAttrs (_n: v: v != {}) (lib.mapAttrs' collect files);

importLeaves =
#
# Create an import stanza by recursing a directory to find all default.nix and <file.nix>
# files beneath withough manually having to list all the subsequent files.
#
path: builtins.attrValues (lib.mapAttrs (_: import) (rakeLeaves path));
})
lib.filterAttrs (_n: v: v != { }) (lib.mapAttrs' collect files);

importLeaves =
#
# Create an import stanza by recursing a directory to find all default.nix and <file.nix>
# files beneath withough manually having to list all the subsequent files.
#
path: builtins.attrValues (lib.mapAttrs (_: import) (rakeLeaves path));
}
)
5 changes: 3 additions & 2 deletions lib/ghaf-modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# SPDX-FileCopyrightText: 2023 TII (SSRC) and the Ghaf contributors
#
# SPDX-License-Identifier: Apache-2.0
{lib}: let
{ lib }:
let
inherit (builtins) readFile filter;
inherit (lib) filesystem hasInfix hasSuffix;

isDesiredFile = path: hasSuffix ".nix" path && hasInfix "options" (readFile path);
modulesDirectoryFiles = filesystem.listFilesRecursive ../modules;
in
filter isDesiredFile modulesDirectoryFiles
filter isDesiredFile modulesDirectoryFiles
Loading

0 comments on commit 1f2aed3

Please sign in to comment.