Files
lxc-bootstrap/flake.nix
John Lancaster fbc3741fca consolidated
2025-07-03 04:25:10 +00:00

80 lines
2.5 KiB
Nix

{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
vscode-server.url = "github:nix-community/nixos-vscode-server";
};
outputs = { self, ... }@inputs:
let
inherit (self) outputs;
nixosSystem = inputs.nixpkgs.lib.nixosSystem;
# Define the base modules list once
baseLxcModules = [
(inputs.nixpkgs + "/nixos/modules/virtualisation/proxmox-lxc.nix")
inputs.vscode-server.nixosModules.default
({ pkgs, ... }: {
system.stateVersion = "24.11";
nix.settings.experimental-features = [ "nix-command" "flakes" ];
services.vscode-server.enable = true;
environment.systemPackages = with pkgs; [
git
];
})
];
# Function to create LXC systems with custom modules
mkLxcSystem = { system ? "x86_64-linux", extraModules ? [], extraPackages ? [] }: nixosSystem {
inherit system;
modules = baseLxcModules ++ extraModules ++ [
# Add extra packages to the base configuration
({ pkgs, ... }: {
environment.systemPackages = extraPackages;
})
];
};
in
{
# Export the function and modules for reuse
lib = { inherit mkLxcSystem baseLxcModules; };
# Re-export inputs for downstream flakes
inherit (inputs) inputs;
# Export nixosModules for use in other flakes
nixosModules = {
# Alternative module with more options
lxc-configurable = { config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.lxc-bootstrap;
in {
options.services.lxc-bootstrap = {
enable = mkEnableOption "LXC bootstrap configuration";
extraPackages = mkOption {
type = types.listOf types.package;
default = [];
description = "Extra packages to install";
};
enableVscodeServer = mkOption {
type = types.bool;
default = true;
description = "Whether to enable VSCode server";
};
};
config = mkIf cfg.enable {
system.stateVersion = "24.11";
nix.settings.experimental-features = [ "nix-command" "flakes" ];
services.vscode-server.enable = cfg.enableVscodeServer;
environment.systemPackages = with pkgs; [ git ] ++ cfg.extraPackages;
};
};
};
nixosConfigurations.lxc = mkLxcSystem { };
};
}