mirror of https://gitlab.crans.org/nounous/nixos
122 lines
3.5 KiB
Nix
122 lines
3.5 KiB
Nix
{
|
|
description = "Configuration NixOS du Crans";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
|
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
|
|
# Formatter
|
|
treefmt-nix = {
|
|
url = "github:numtide/treefmt-nix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
# Secret management
|
|
agenix = {
|
|
url = "github:ryantm/agenix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs =
|
|
inputs@{
|
|
self,
|
|
nixpkgs,
|
|
flake-parts,
|
|
agenix,
|
|
...
|
|
}:
|
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
|
imports = [ inputs.treefmt-nix.flakeModule ];
|
|
|
|
systems = [ "x86_64-linux" ];
|
|
|
|
flake = with nixpkgs.lib; {
|
|
nixosConfigurations =
|
|
let
|
|
baseModules = [
|
|
./modules
|
|
agenix.nixosModules.default
|
|
];
|
|
get_hosts_names = path:
|
|
attrNames (
|
|
attrsets.filterAttrs (name: type: type == "directory")
|
|
(readDir path)
|
|
) ;
|
|
hostVM = get_hosts_names ./hosts/vm;
|
|
hostPhysique = get_hosts_names ./hosts/physiques;
|
|
get_info =
|
|
path: lists:
|
|
filter (x: x != null)
|
|
(map (name:
|
|
let filePath = path + "/${name}/info.nix";
|
|
in
|
|
if builtins.pathExists filePath then
|
|
# let eval = evalModules {
|
|
# specialArgs = inputs;
|
|
# modules = [
|
|
# ./modules/crans
|
|
# {
|
|
# crans = import filePath;
|
|
# }
|
|
# # agenix.nixosModules.default
|
|
# ];
|
|
# };
|
|
# in
|
|
# eval.config
|
|
{
|
|
crans = import filePath;
|
|
}
|
|
else
|
|
warn "${toString filePath} not found" null
|
|
) lists
|
|
);
|
|
hosts_vm_info = get_info ./hosts/vm hostVM;
|
|
hosts_physique_info = get_info ./hosts/physiques hostPhysique;
|
|
|
|
listInfoToAttrs =
|
|
path: infos:
|
|
listToAttrs (
|
|
map (info:
|
|
{
|
|
name = info.crans.name;
|
|
value = info;
|
|
}
|
|
) infos)
|
|
;
|
|
attrsToNixosSystem = path: all_hosts: hosts:
|
|
mapAttrs (name: info:
|
|
nixosSystem {
|
|
specialArgs = { hosts = all_hosts; inherit inputs;};
|
|
modules = [(path + "/${name}")] ++ [info] ++ baseModules
|
|
;
|
|
}
|
|
) hosts;
|
|
attrs_vm_info = listInfoToAttrs ./hosts/vm hosts_vm_info;
|
|
attrs_physique_info = listInfoToAttrs ./hosts/physiques hosts_physique_info;
|
|
attrs_all_info = attrs_physique_info // attrs_vm_info;
|
|
in
|
|
(attrsToNixosSystem ./hosts/vm attrs_all_info attrs_vm_info)
|
|
//
|
|
{
|
|
cransIso = nixosSystem {
|
|
system = "x86_64-linux";
|
|
specialArgs = inputs;
|
|
modules = [
|
|
./hosts/iso
|
|
./modules/crans/locale.nix
|
|
];
|
|
};
|
|
};
|
|
};
|
|
|
|
perSystem =
|
|
{ config, pkgs, ... }:
|
|
{
|
|
devShells = {
|
|
default = pkgs.callPackage ./devshells/default.nix { inherit (inputs) agenix; };
|
|
};
|
|
};
|
|
};
|
|
}
|