add flake-parts module for clan

This commit is contained in:
Jörg Thalheim 2024-04-03 13:46:17 +02:00
parent f7077e3540
commit 3212410704
6 changed files with 107 additions and 54 deletions

View File

@ -1,17 +1,11 @@
{ self, ... }:
{
flake.clanInternals =
(self.lib.buildClan {
clanName = "testclan";
directory = ../..;
machines.test-backup = {
imports = [ self.nixosModules.test-backup ];
fileSystems."/".device = "/dev/null";
boot.loader.grub.device = "/dev/null";
};
}).clanInternals;
clan.machines.test-backup = {
imports = [ self.nixosModules.test-backup ];
fileSystems."/".device = "/dev/null";
boot.loader.grub.device = "/dev/null";
};
flake.nixosModules = {
test-backup =
{
pkgs,
@ -75,7 +69,6 @@
};
};
clanCore.facts.secretStore = "vm";
clanCore.clanDir = ../..;
environment.systemPackages = [
self.packages.${pkgs.system}.clan-cli

View File

@ -1,21 +1,12 @@
{ self, ... }:
let
clan = self.lib.buildClan {
clanName = "testclan";
directory = ../..;
machines = {
test_install_machine = {
clan.networking.targetHost = "test_install_machine";
imports = [ self.nixosModules.test_install_machine ];
};
};
};
in
{ self, lib, ... }:
{
flake.nixosConfigurations = {
inherit (clan.nixosConfigurations) test_install_machine;
clan.machines.test_install_machine = {
clan.networking.targetHost = "test_install_machine";
fileSystems."/".device = lib.mkDefault "/dev/null";
boot.loader.grub.device = lib.mkDefault "/dev/null";
imports = [ self.nixosModules.test_install_machine ];
};
flake.clanInternals = clan.clanInternals;
flake.nixosModules = {
test_install_machine =
{ lib, modulesPath, ... }:
@ -43,10 +34,10 @@ in
let
dependencies = [
self
self.nixosConfigurations.test_install_machine.config.system.build.toplevel
self.nixosConfigurations.test_install_machine.config.system.build.diskoScript
self.nixosConfigurations.test_install_machine.config.system.clan.deployment.file
pkgs.stdenv.drvPath
clan.clanInternals.machines.x86_64-linux.test_install_machine.config.system.build.toplevel
clan.clanInternals.machines.x86_64-linux.test_install_machine.config.system.build.diskoScript
clan.clanInternals.machines.x86_64-linux.test_install_machine.config.system.clan.deployment.file
pkgs.nixos-anywhere
] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
closureInfo = pkgs.closureInfo { rootPaths = dependencies; };

View File

@ -25,7 +25,7 @@
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } (
{ lib, ... }:
{ ... }:
{
systems = [
"x86_64-linux"
@ -35,6 +35,8 @@
imports = [
./checks/flake-module.nix
./clanModules/flake-module.nix
./flakeModules/flake-module.nix
./flakeModules/clan.nix
./devShell.nix
./docs/flake-module
./formatter.nix
@ -42,19 +44,6 @@
./nixosModules/flake-module.nix
./pkgs/flake-module.nix
./templates/flake-module.nix
{
options.flake = flake-parts.lib.mkSubmoduleOptions {
clanInternals = lib.mkOption {
type = lib.types.submodule {
options = {
all-machines-json = lib.mkOption { type = lib.types.attrsOf lib.types.str; };
machines = lib.mkOption { type = lib.types.attrsOf (lib.types.attrsOf lib.types.unspecified); };
machinesFunc = lib.mkOption { type = lib.types.attrsOf (lib.types.attrsOf lib.types.unspecified); };
};
};
};
};
}
];
}
);

73
flakeModules/clan.nix Normal file
View File

@ -0,0 +1,73 @@
{
config,
lib,
flake-parts-lib,
inputs,
self,
...
}:
let
inherit (lib) mkOption types;
buildClan = import ../lib/build-clan {
inherit lib;
clan-core = self;
inherit (inputs) nixpkgs;
};
cfg = config.clan;
in
{
options.clan = {
directory = mkOption {
type = types.path;
description = "The directory containing the clan subdirectory";
};
specialArgs = mkOption {
type = types.attrsOf types.str;
default = { };
description = "Extra arguments to pass to nixosSystem i.e. useful to make self available";
};
machines = mkOption {
type = types.attrsOf types.raw;
default = { };
description = "Allows to include machine-specific modules i.e. machines.\${name} = { ... }";
};
clanName = mkOption {
type = types.str;
description = "Needs to be (globally) unique, as this determines the folder name where the flake gets downloaded to.";
};
clanIcon = mkOption {
type = types.nullOr types.path;
default = null;
description = "A path to an icon to be used for the clan, should be the same for all machines";
};
pkgsForSystem = mkOption {
type = types.functionTo types.raw;
default = _system: null;
description = "A map from arch to pkgs, if specified this nixpkgs will be only imported once for each system.";
};
};
options.flake = flake-parts-lib.mkSubmoduleOptions {
clanInternals = lib.mkOption {
type = lib.types.submodule {
options = {
all-machines-json = lib.mkOption { type = lib.types.attrsOf lib.types.str; };
machines = lib.mkOption { type = lib.types.attrsOf (lib.types.attrsOf lib.types.unspecified); };
machinesFunc = lib.mkOption { type = lib.types.attrsOf (lib.types.attrsOf lib.types.unspecified); };
};
};
};
};
config = {
flake = buildClan {
inherit (cfg)
directory
specialArgs
machines
clanName
clanIcon
pkgsForSystem
;
};
};
}

View File

@ -0,0 +1,7 @@
{ config, ... }:
{
flake.flakeModules = {
clan = ./clan.nix;
default = config.flake.flakeModules.clan;
};
}

View File

@ -18,21 +18,21 @@ let
{ disko.memSize = 4096; } # FIXME: otherwise the image builder goes OOM
];
};
clan = self.lib.buildClan {
clanName = "clan-core";
directory = self;
machines.installer = installerModule;
};
in
{
flake.packages.x86_64-linux.install-iso = self.inputs.disko.lib.makeDiskImages {
nixosConfig = installer;
};
flake.nixosConfigurations = {
inherit (clan.nixosConfigurations) installer;
clan = {
clanName = "clan-core";
directory = self;
machines.installer = {
imports = [ installerModule ];
fileSystems."/".device = lib.mkDefault "/dev/null";
boot.loader.grub.device = lib.mkDefault "/dev/null";
};
};
flake.clanInternals = clan.clanInternals;
flake.apps.x86_64-linux.install-vm.program = installer.config.formats.vm.outPath;
flake.apps.x86_64-linux.install-vm-nogui.program = installer.config.formats.vm-nogui.outPath;
}