Skip to content

Commit

Permalink
parts: add an option for headless configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
moni-dz committed Nov 17, 2023
1 parent 9ab07fd commit 20909b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions hosts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
mistral = {
system = "x86_64-linux";
stateVersion = "23.05";
server = true;

modules = [
inputs.nix-minecraft.nixosModules.minecraft-servers
Expand Down
47 changes: 25 additions & 22 deletions modules/parts/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ let

nixosOpts = opts@{ config, name, ... }: {
options = {
server = lib.mkEnableOption "Host is a headless server configuration.";

system = lib.mkOption {
type = types.enum [ "aarch64-linux" "x86_64-linux" ];
description = "System architecture for the configuration.";
Expand All @@ -33,35 +35,36 @@ let
};
};

config._nixos = withSystem config.system (ctx:
inputs.nixpkgs.lib.nixosSystem {
modules = config.modules ++ [
config._nixos = withSystem config.system
(ctx:
inputs.nixpkgs.lib.nixosSystem {
modules = config.modules ++ lib.optionals !config.server [
# Shared configuration across all NixOS machines
../shared/nixos

] ++ [
({ pkgs, ... }: {
inherit (ctx) nix nixpkgs;
_module.args = ctx.extraModuleArgs;
networking.hostName = name;
system.stateVersion = config.stateVersion;
environment.systemPackages = ctx.basePackagesFor pkgs;
})
] ++ lib.optionals config.wsl [
inputs.nixos-wsl.nixosModules.wsl
inherit (ctx) nix nixpkgs;
_module.args = ctx.extraModuleArgs;
networking.hostName = name;
system.stateVersion = config.stateVersion;
environment.systemPackages = ctx.basePackagesFor pkgs;
})
] ++ lib.optionals config.wsl [
inputs.nixos-wsl.nixosModules.wsl

({ lib, pkgs, ... }: {
wsl.wslConf.network.hostname = name;
system.build.installBootLoader = lib.mkForce "${pkgs.coreutils}/bin/true";
})
];
}
);
({ lib, pkgs, ... }: {
wsl.wslConf.network.hostname = name;
system.build.installBootLoader = lib.mkForce "${pkgs.coreutils}/bin/true";
})
];
}
);
};
in
{
in
{
options.parts.nixosConfigurations = lib.mkOption {
type = types.attrsOf (types.submodule nixosOpts);
};

config.flake.nixosConfigurations = configurations;
}
}

0 comments on commit 20909b3

Please sign in to comment.