From a5e5f2f1eaeaa33b2a4d965d0c3bba517ead4a38 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 8 Mar 2026 23:41:08 -0500 Subject: [PATCH] started lxc nixos module --- README.md | 9 +++-- flake.lock | 69 +++++++++++++++++++++++++++++++++++++- modules/nixos/lxc.nix | 78 +++++++------------------------------------ 3 files changed, 87 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 28e2c31..17dbeba 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,6 @@ This uses `inputs.flake-parts.lib.mkFlake` to create the flake. The modules are automatically imported from the `./modules` using [import-tree](https://import-tree.oeiuwq.com/). - ### [Home Manager](https://flake.parts/options/home-manager.html) Uses the home-manager module of flake-parts, which is imported in `modules/home-manager/flake-parts.nix` @@ -47,4 +46,10 @@ Show exported home configurations: ```shell nix eval --apply builtins.attrNames .#homeConfigurations -``` \ No newline at end of file +``` + +### Remote Deploy + +```shell +nixos-rebuild switch --flake .#lxc --target-host root@fded:fb16:653e:25da:be24:11ff:fea0:753f +``` diff --git a/flake.lock b/flake.lock index 7e89b0e..2ec9ec8 100644 --- a/flake.lock +++ b/flake.lock @@ -53,6 +53,24 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": "nixpkgs" @@ -136,6 +154,20 @@ "url": "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz" } }, + "nixpkgs_3": { + "locked": { + "lastModified": 1682134069, + "narHash": "sha256-TnI/ZXSmRxQDt2sjRYK/8j8iha4B4zP2cnQCZZ3vp7k=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fd901ef4bf93499374c5af385b2943f5801c0833", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, "root": { "inputs": { "flake-file": "flake-file", @@ -147,7 +179,8 @@ "nixpkgs-lib": [ "nixpkgs" ], - "sops-nix": "sops-nix" + "sops-nix": "sops-nix", + "vscode-server": "vscode-server" } }, "sops-nix": { @@ -184,6 +217,40 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "vscode-server": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1770124655, + "narHash": "sha256-yHmd2B13EtBUPLJ+x0EaBwNkQr9LTne1arLVxT6hSnY=", + "owner": "nix-community", + "repo": "nixos-vscode-server", + "rev": "92ce71c3ba5a94f854e02d57b14af4997ab54ef0", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixos-vscode-server", + "type": "github" + } } }, "root": "root", diff --git a/modules/nixos/lxc.nix b/modules/nixos/lxc.nix index 3ac4fb6..9bfc4d8 100644 --- a/modules/nixos/lxc.nix +++ b/modules/nixos/lxc.nix @@ -1,73 +1,19 @@ { inputs, ... }: { - flake-file.inputs = { - vscode-server.url = "github:nix-community/nixos-vscode-server"; + flake.modules.nixos.lxc = { pkgs, lib, ...}: { + imports = [ + ({ modulesPath, ... }: { imports = [ "${modulesPath}/virtualisation/proxmox-lxc.nix" ]; }) + ]; + nixpkgs.hostPlatform = lib.mkForce "x86_64-linux"; + system.stateVersion = "25.11"; + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + environment.systemPackages = with pkgs; [ git zsh ]; }; - flake.lib.lxc = - let - inherit (inputs) nixpkgs vscode-server; - - baseLxcModules = [ - (nixpkgs + "/nixos/modules/virtualisation/proxmox-lxc.nix") - 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 ]; - }) - ]; - - mkLxcSystem = { system ? "x86_64-linux", extraModules ? [], extraPackages ? [] }: - nixpkgs.lib.nixosSystem { - inherit system; - modules = baseLxcModules ++ extraModules ++ [ - ({ pkgs, ... }: { - environment.systemPackages = extraPackages; - }) - ]; - }; - in - { inherit baseLxcModules mkLxcSystem; }; - - flake.nixosModules.lxc-bootstrap = { 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; - }; - }; - - flake.modules.nixos.lxc-base = { pkgs, ... }: { - imports = [ - inputs.vscode-server.nixosModules.default - (inputs.nixpkgs + "/nixos/modules/virtualisation/proxmox-lxc.nix") + # Generic bootstrapping lxc, use a specific host file for more + flake.nixosConfigurations.lxc = inputs.nixpkgs.lib.nixosSystem { + modules = [ + inputs.self.modules.nixos.lxc ]; - system.stateVersion = "24.11"; - nix.settings.experimental-features = [ "nix-command" "flakes" ]; - services.vscode-server.enable = true; - environment.systemPackages = with pkgs; [ git ]; }; }