From d1959792d24780627e359497b7d9c0c45c267ac8 Mon Sep 17 00:00:00 2001 From: John Lancaster Date: Thu, 3 Jul 2025 02:28:27 +0000 Subject: [PATCH] started exports --- flake.nix | 87 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 16 deletions(-) diff --git a/flake.nix b/flake.nix index 44bb6d9..fd0c914 100644 --- a/flake.nix +++ b/flake.nix @@ -6,31 +6,86 @@ vscode-server.url = "github:nix-community/nixos-vscode-server"; }; - outputs = { self, ... }@args: + outputs = { self, ... }@inputs: let inherit (self) outputs; - nixosSystem = args.nixpkgs.lib.nixosSystem; - pkgs = args.nixpkgs.legacyPackages.x86_64-linux; - in - { - nixosConfigurations.lxc = nixosSystem { - system = "x86_64-linux"; + 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 = [ - (args.nixpkgs + "/nixos/modules/virtualisation/proxmox-lxc.nix") - args.vscode-server.nixosModules.default - # ./configuration.nix + (inputs.nixpkgs + "/nixos/modules/virtualisation/proxmox-lxc.nix") + inputs.vscode-server.nixosModules.default + baseLxcModule + # Add extra packages to the base configuration ({ pkgs, ... }: { - system.stateVersion = "24.11"; - nix.settings.experimental-features = [ "nix-command" "flakes" ]; - services.vscode-server.enable = true; - environment.systemPackages = with pkgs; [ - git - ]; + 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 { }; }; }