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 treefmt and reformat files #32

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
36 changes: 19 additions & 17 deletions config-processor-hardware.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,40 @@
# SPDX-License-Identifier: Apache-2.0
#
{
self,
lib,
ghafOS,
nixos-generators,
nixos-hardware,
nixpkgs,
microvm,
}: {
sysconf,
}:
let
updateAttrs = (import ./utils/updateAttrs.nix).updateAttrs;
}: {sysconf}: let
inherit ((import ./utils/updateAttrs.nix)) updateAttrs;

targetconf = if lib.hasAttr "extend" sysconf
then updateAttrs false (import (lib.path.append ./hardware sysconf.extend) ).sysconf sysconf
else sysconf;
targetconf =
if lib.hasAttr "extend" sysconf
then updateAttrs false (import (lib.path.append ./hardware sysconf.extend)).sysconf sysconf
else sysconf;

name = targetconf.name;
inherit (targetconf) name;
system = "x86_64-linux";
vms = targetconf.vms;
inherit (targetconf) vms;

importvm = vmconf: (import ./modules/virtualization/microvm/vm.nix {inherit ghafOS vmconf;});
enablevm = vm: {
virtualization.microvm.${vm.name} = {
enable = true;
extraModules = vm.extraModules;
inherit (vm) extraModules;
};
};
addSystemPackages = {pkgs, ...}: {environment.systemPackages = map (app: pkgs.${app}) targetconf.systemPackages;};
addCustomLaunchers = { ghaf.graphics.app-launchers.enabled-launchers = targetconf.launchers; };
addCustomLaunchers = {ghaf.graphics.app-launchers.enabled-launchers = targetconf.launchers;};

formatModule = nixos-generators.nixosModules.raw-efi;
target = variant: extraModules: let
hostConfiguration = lib.nixosSystem {
inherit system;
specialArgs = {inherit lib; inherit ghafOS;};
specialArgs = {
inherit lib;
inherit ghafOS;
};
modules =
[
microvm.nixosModules.host
Expand Down Expand Up @@ -80,7 +78,11 @@ let
++ (import "${ghafOS}/modules/module-list.nix")
++ (import ./modules/fmo-module-list.nix)
++ extraModules
++ (if lib.hasAttr "extraModules" targetconf then targetconf.extraModules else []);
++ (
if lib.hasAttr "extraModules" targetconf
then targetconf.extraModules
else []
);
};
in {
inherit hostConfiguration;
Expand Down
73 changes: 44 additions & 29 deletions config-processor-installers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,47 @@
lib,
ghafOS,
nixos-generators,
nixos-hardware,
nixpkgs,
microvm,
}: {
sysconf,
}:
let
updateAttrs = (import ./utils/updateAttrs.nix).updateAttrs;
}: {sysconf}: let
inherit ((import ./utils/updateAttrs.nix)) updateAttrs;

oss = sysconf.oss;
inherit (sysconf) oss;
oss_list_name = "installer_os_list";
oss_list_path = "/etc/${oss_list_name}";

installerconf = if lib.hasAttr "extend" sysconf
then updateAttrs false (import (lib.path.append ./installers sysconf.extend) ).sysconf sysconf
else sysconf;

installerconf =
if lib.hasAttr "extend" sysconf
then updateAttrs false (import (lib.path.append ./installers sysconf.extend)).sysconf sysconf
else sysconf;

installerApp = inst_app: let
installers = (builtins.removeAttrs inst_app ["name"]) //
{ oss_path = lib.mkDefault "${oss_list_path}"; };
in installers;

installers =
(builtins.removeAttrs inst_app ["name"])
// {oss_path = lib.mkDefault "${oss_list_path}";};
in
installers;

addSystemPackages = {pkgs, ...}: {environment.systemPackages = map (app: pkgs.${app}) installerconf.systemPackages;};

formatModule = nixos-generators.nixosModules.iso;
installer = variant: extraModules: let
system = "x86_64-linux";

pkgs = import nixpkgs {inherit system;};

installerImgCfg = lib.nixosSystem {
inherit system;
specialArgs = {inherit lib; inherit ghafOS;};
specialArgs = {
inherit lib;
inherit ghafOS;
};
modules =
[
(import "${ghafOS}/modules/host")
({modulesPath, lib, config, ...}: {
imports = [ (modulesPath + "/profiles/all-hardware.nix") ];
({
modulesPath,
config,
...
}: {
imports = [(modulesPath + "/profiles/all-hardware.nix")];

nixpkgs.hostPlatform.system = system;
nixpkgs.config.allowUnfree = true;
Expand All @@ -60,9 +62,12 @@ let
installer.includeOSS = {
enable = lib.mkDefault true;
oss_list_fname = lib.mkDefault "${oss_list_name}";
systems = map (os: rec {
name = "${os}-${variant}";
image = self.nixosConfigurations.${name};}) oss;
systems =
map (os: rec {
name = "${os}-${variant}";
image = self.nixosConfigurations.${name};
})
oss;
};
}

Expand All @@ -74,13 +79,17 @@ let
addSystemPackages

{
isoImage.squashfsCompression = "lz4";
isoImage.squashfsCompression = "lz4";
}
]
++ (import ./modules/fmo-module-list.nix)
++ (import "${ghafOS}/modules/module-list.nix")
++ extraModules
++ (if lib.hasAttr "extraModules" installerconf then installerconf.extraModules else []);
++ (
if lib.hasAttr "extraModules" installerconf
then installerconf.extraModules
else []
);
};
in {
name = "${installerconf.name}-${variant}";
Expand All @@ -93,7 +102,13 @@ let
(installer "release" [])
];
in {
packages = lib.foldr lib.recursiveUpdate {} (map ({name, system, installerImgDrv, ...}: {
${system}.${name} = installerImgDrv;
}) targets);
packages = lib.foldr lib.recursiveUpdate {} (map ({
name,
system,
installerImgDrv,
...
}: {
${system}.${name} = installerImgDrv;
})
targets);
}
24 changes: 23 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 44 additions & 34 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,25 @@

inputs = rec {
ghafOS.url = "github:tiiuae/ghaf";

# Format all the things with treefmt.
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "ghafOS/nixpkgs";
};
};

outputs = {
self,
ghafOS,
treefmt-nix,
...
}: let
# Retrieve inputs from Ghaf
nixpkgs = ghafOS.inputs.nixpkgs;
flake-utils = ghafOS.inputs.flake-utils;
nixos-generators = ghafOS.inputs.nixos-generators;
nixos-hardware = ghafOS.inputs.nixos-hardware;
microvm = ghafOS.inputs.microvm;
inherit (ghafOS.inputs) nixpkgs;
inherit (ghafOS.inputs) flake-utils;
inherit (ghafOS.inputs) nixos-generators;
inherit (ghafOS.inputs) microvm;

systems = with flake-utils.lib.system; [
x86_64-linux
Expand All @@ -40,38 +47,41 @@
};
});

generateHwConfig = import ./config-processor-hardware.nix {inherit nixpkgs ghafOS self nixos-hardware nixos-generators lib microvm;};
generateInstConfig = import ./config-processor-installers.nix {inherit nixpkgs ghafOS self nixos-hardware nixos-generators lib microvm;};
generateHwConfig = import ./config-processor-hardware.nix {inherit ghafOS nixos-generators lib microvm;};
generateInstConfig = import ./config-processor-installers.nix {inherit nixpkgs ghafOS self nixos-generators lib;};
in
# Combine list of attribute sets together
lib.foldr lib.recursiveUpdate {} ([
(flake-utils.lib.eachSystem systems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
hydraJobs = {
packages = {
x86_64-linux = {
fmo-os-installer-public-debug = self.packages.x86_64-linux.fmo-os-installer-public-debug;
fmo-os-installer-public-release = self.packages.x86_64-linux.fmo-os-installer-public-release;
fmo-os-rugged-laptop-7330-public-debug = self.packages.x86_64-linux.fmo-os-rugged-laptop-7330-public-debug;
fmo-os-rugged-laptop-7330-public-release = self.packages.x86_64-linux.fmo-os-rugged-laptop-7330-public-release;
fmo-os-rugged-tablet-7230-public-debug = self.packages.x86_64-linux.fmo-os-rugged-tablet-7230-public-debug;
fmo-os-rugged-tablet-7230-public-release = self.packages.x86_64-linux.fmo-os-rugged-tablet-7230-public-release;
(flake-utils.lib.eachSystem systems (system: let
pkgs = nixpkgs.legacyPackages.${system};

# Evaluate treefmt config for each system
treefmt = import ./treefmt.nix {inherit self lib pkgs system treefmt-nix;};
in {
formatter = treefmt.config.build.wrapper;

hydraJobs = {
packages = {
x86_64-linux = {
inherit (self.packages.x86_64-linux) fmo-os-installer-public-debug;
inherit (self.packages.x86_64-linux) fmo-os-installer-public-release;
inherit (self.packages.x86_64-linux) fmo-os-rugged-laptop-7330-public-debug;
inherit (self.packages.x86_64-linux) fmo-os-rugged-laptop-7330-public-release;
inherit (self.packages.x86_64-linux) fmo-os-rugged-tablet-7230-public-debug;
inherit (self.packages.x86_64-linux) fmo-os-rugged-tablet-7230-public-release;
};
};
};
};

formatter = pkgs.alejandra;
}))
]
++ map generateHwConfig [
(import ./hardware/fmo-os-rugged-laptop-7330.nix)
(import ./hardware/fmo-os-rugged-laptop-7330-public.nix)
(import ./hardware/fmo-os-rugged-tablet-7230.nix)
(import ./hardware/fmo-os-rugged-tablet-7230-public.nix)
]
++ map generateInstConfig [
(import ./installers/fmo-os-installer.nix)
(import ./installers/fmo-os-installer-public.nix)
]);
}))
]
++ map generateHwConfig [
(import ./hardware/fmo-os-rugged-laptop-7330.nix)
(import ./hardware/fmo-os-rugged-laptop-7330-public.nix)
(import ./hardware/fmo-os-rugged-tablet-7230.nix)
(import ./hardware/fmo-os-rugged-tablet-7230-public.nix)
]
++ map generateInstConfig [
(import ./installers/fmo-os-installer.nix)
(import ./installers/fmo-os-installer-public.nix)
]);
}
Loading
Loading