Files
lxc-bootstrap/flake.nix
2025-07-03 02:28:27 +00:00

92 lines
2.8 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;
pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
# Base LXC module that can be reused
baseLxcModule = { 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;
specialArgs = {
inherit pkgs;
};
modules = [
(inputs.nixpkgs + "/nixos/modules/virtualisation/proxmox-lxc.nix")
inputs.vscode-server.nixosModules.default
baseLxcModule
# Add extra packages to the base configuration
({ pkgs, ... }: {
environment.systemPackages = extraPackages;
})
] ++ extraModules;
};
in
{
# Export the function and modules for reuse
lib = {
inherit mkLxcSystem baseLxcModule;
# Helper to get the base modules list
baseLxcModules = [
(inputs.nixpkgs + "/nixos/modules/virtualisation/proxmox-lxc.nix")
inputs.vscode-server.nixosModules.default
baseLxcModule
];
};
# Re-export inputs for downstream flakes
inherit (inputs) inputs;
# Export nixosModules for use in other flakes
nixosModules = {
lxc-base = baseLxcModule;
# 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 { };
};
}