Merge pull request 'Clan create fixes' (#1788) from inventory-fixes into main
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
{
|
||||
description = "clan.lol base operating system";
|
||||
|
||||
nixConfig.extra-substituters = [ "https://cache.clan.lol" ];
|
||||
nixConfig.extra-trusted-public-keys = [
|
||||
"cache.clan.lol-1:3KztgSAB5R1M+Dz7vzkBGzXdodizbgLXGXKXlcQLA28="
|
||||
];
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
|
||||
disko.url = "github:nix-community/disko";
|
||||
|
||||
@@ -18,9 +18,11 @@ minimal_template_url: str = "git+https://git.clan.lol/clan/clan-core#templates.m
|
||||
|
||||
@dataclass
|
||||
class CreateClanResponse:
|
||||
git_init: CmdOut
|
||||
flake_init: CmdOut
|
||||
git_init: CmdOut | None
|
||||
git_add: CmdOut
|
||||
git_config: CmdOut
|
||||
git_config_username: CmdOut | None
|
||||
git_config_email: CmdOut | None
|
||||
flake_update: CmdOut
|
||||
|
||||
|
||||
@@ -34,9 +36,13 @@ class CreateOptions:
|
||||
template_url: str = minimal_template_url
|
||||
|
||||
|
||||
def git_command(directory: Path, *args: str) -> list[str]:
|
||||
return nix_shell(["nixpkgs#git"], ["git", "-C", str(directory), *args])
|
||||
|
||||
|
||||
@API.register
|
||||
def create_clan(options: CreateOptions) -> CreateClanResponse:
|
||||
directory = Path(options.directory)
|
||||
directory = Path(options.directory).resolve()
|
||||
template_url = options.template_url
|
||||
if not directory.exists():
|
||||
directory.mkdir()
|
||||
@@ -52,7 +58,6 @@ def create_clan(options: CreateOptions) -> CreateClanResponse:
|
||||
description="Directory already exists and is not empty.",
|
||||
)
|
||||
|
||||
cmd_responses = {}
|
||||
command = nix_command(
|
||||
[
|
||||
"flake",
|
||||
@@ -61,27 +66,27 @@ def create_clan(options: CreateOptions) -> CreateClanResponse:
|
||||
template_url,
|
||||
]
|
||||
)
|
||||
out = run(command, cwd=directory)
|
||||
flake_init = run(command, cwd=directory)
|
||||
|
||||
## Begin: setup git
|
||||
command = nix_shell(["nixpkgs#git"], ["git", "init"])
|
||||
out = run(command, cwd=directory)
|
||||
cmd_responses["git init"] = out
|
||||
git_init = None
|
||||
if not directory.joinpath(".git").exists():
|
||||
git_init = run(git_command(directory, "init"))
|
||||
git_add = run(git_command(directory, "add", "."))
|
||||
|
||||
command = nix_shell(["nixpkgs#git"], ["git", "add", "."])
|
||||
out = run(command, cwd=directory)
|
||||
cmd_responses["git add"] = out
|
||||
# check if username is set
|
||||
has_username = run(git_command(directory, "config", "user.name"), check=False)
|
||||
git_config_username = None
|
||||
if has_username.returncode != 0:
|
||||
git_config_username = run(
|
||||
git_command(directory, "config", "user.name", "clan-tool")
|
||||
)
|
||||
|
||||
command = nix_shell(["nixpkgs#git"], ["git", "config", "user.name", "clan-tool"])
|
||||
out = run(command, cwd=directory)
|
||||
cmd_responses["git config"] = out
|
||||
|
||||
command = nix_shell(
|
||||
["nixpkgs#git"], ["git", "config", "user.email", "clan@example.com"]
|
||||
)
|
||||
out = run(command, cwd=directory)
|
||||
cmd_responses["git config"] = out
|
||||
## End: setup git
|
||||
has_username = run(git_command(directory, "config", "user.email"), check=False)
|
||||
git_config_email = None
|
||||
if has_username.returncode != 0:
|
||||
git_config_email = run(
|
||||
git_command(directory, "config", "user.email", "clan@example.com")
|
||||
)
|
||||
|
||||
# Write inventory.json file
|
||||
inventory = load_inventory(directory)
|
||||
@@ -90,15 +95,17 @@ def create_clan(options: CreateOptions) -> CreateClanResponse:
|
||||
# Persist creates a commit message for each change
|
||||
save_inventory(inventory, directory, "Init inventory")
|
||||
|
||||
command = ["nix", "flake", "update"]
|
||||
out = run(command, cwd=directory)
|
||||
cmd_responses["flake update"] = out
|
||||
flake_update = run(
|
||||
nix_shell(["nixpkgs#nix"], ["nix", "flake", "update"]), cwd=directory
|
||||
)
|
||||
|
||||
response = CreateClanResponse(
|
||||
git_init=cmd_responses["git init"],
|
||||
git_add=cmd_responses["git add"],
|
||||
git_config=cmd_responses["git config"],
|
||||
flake_update=cmd_responses["flake update"],
|
||||
flake_init=flake_init,
|
||||
git_init=git_init,
|
||||
git_add=git_add,
|
||||
git_config_username=git_config_username,
|
||||
git_config_email=git_config_email,
|
||||
flake_update=flake_update,
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
{
|
||||
python3,
|
||||
runCommand,
|
||||
setuptools,
|
||||
copyDesktopItems,
|
||||
pygobject3,
|
||||
wrapGAppsHook,
|
||||
gtk4,
|
||||
gnome,
|
||||
pygobject-stubs,
|
||||
gobject-introspection,
|
||||
adwaita-icon-theme,
|
||||
clan-cli,
|
||||
makeDesktopItem,
|
||||
copyDesktopItems,
|
||||
fontconfig,
|
||||
gobject-introspection,
|
||||
gtk4,
|
||||
libadwaita,
|
||||
webkitgtk_6_0,
|
||||
makeDesktopItem,
|
||||
pygobject-stubs,
|
||||
pygobject3,
|
||||
pytest, # Testing framework
|
||||
pytest-cov, # Generate coverage reports
|
||||
pytest-subprocess, # fake the real subprocess behavior to make your tests more independent.
|
||||
pytest-xdist, # Run tests in parallel on multiple cores
|
||||
pytest-timeout, # Add timeouts to your tests
|
||||
pytest-xdist, # Run tests in parallel on multiple cores
|
||||
python3,
|
||||
runCommand,
|
||||
setuptools,
|
||||
webkitgtk_6_0,
|
||||
webview-ui,
|
||||
fontconfig,
|
||||
wrapGAppsHook,
|
||||
}:
|
||||
let
|
||||
source = ./.;
|
||||
@@ -39,7 +39,7 @@ let
|
||||
gtk4
|
||||
libadwaita
|
||||
webkitgtk_6_0
|
||||
gnome.adwaita-icon-theme
|
||||
adwaita-icon-theme
|
||||
];
|
||||
|
||||
# Deps including python packages from the local project
|
||||
@@ -112,8 +112,8 @@ python3.pkgs.buildPythonApplication rec {
|
||||
mkdir -p .home/.local/share/fonts
|
||||
export HOME=.home
|
||||
|
||||
fc-cache --verbose
|
||||
# > fc-cache succeded
|
||||
fc-cache --verbose
|
||||
# > fc-cache succeded
|
||||
|
||||
echo "Loaded the following fonts ..."
|
||||
fc-list
|
||||
@@ -160,8 +160,8 @@ python3.pkgs.buildPythonApplication rec {
|
||||
mkdir -p .home/.local/share/fonts
|
||||
export HOME=.home
|
||||
|
||||
fc-cache --verbose
|
||||
# > fc-cache succeded
|
||||
fc-cache --verbose
|
||||
# > fc-cache succeded
|
||||
|
||||
echo "Loaded the following fonts ..."
|
||||
fc-list
|
||||
|
||||
@@ -49,7 +49,9 @@
|
||||
# This only works however if you have avahi running on your admin machine else use IP
|
||||
clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon";
|
||||
|
||||
# ssh root@flash-installer.local lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
||||
# You can get your disk id by running the following command on the installer:
|
||||
# Replace <IP> with the IP of the installer printed on the screen or by running the `ip addr` command.
|
||||
# ssh root@<IP> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
||||
disko.devices.disk.main = {
|
||||
device = "/dev/disk/by-id/__CHANGE_ME__";
|
||||
};
|
||||
@@ -80,7 +82,9 @@
|
||||
# This only works however if you have avahi running on your admin machine else use IP
|
||||
clan.core.networking.targetHost = pkgs.lib.mkDefault "root@sara";
|
||||
|
||||
# ssh root@flash-installer.local lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
||||
# You can get your disk id by running the following command on the installer:
|
||||
# Replace <IP> with the IP of the installer printed on the screen or by running the `ip addr` command.
|
||||
# ssh root@<IP> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
||||
disko.devices.disk.main = {
|
||||
device = "/dev/disk/by-id/__CHANGE_ME__";
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# Usage see: https://docs.clan.lol
|
||||
clan = clan-core.lib.buildClan {
|
||||
directory = self;
|
||||
meta.name = "__CHANGE_ME__"; # Ensure this is internet wide unique.
|
||||
meta.name = "__CHANGE_ME__"; # Ensure this is unique among all clans you want to use.
|
||||
|
||||
# Distributed services, uncomment to enable.
|
||||
# inventory = {
|
||||
@@ -45,7 +45,9 @@
|
||||
# This only works however if you have avahi running on your admin machine else use IP
|
||||
clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon";
|
||||
|
||||
# ssh root@flash-installer.local lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
||||
# You can get your disk id by running the following command on the installer:
|
||||
# Replace <IP> with the IP of the installer printed on the screen or by running the `ip addr` command.
|
||||
# ssh root@<IP> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
||||
disko.devices.disk.main.device = "/dev/disk/by-id/__CHANGE_ME__";
|
||||
|
||||
# IMPORTANT! Add your SSH key here
|
||||
@@ -74,7 +76,9 @@
|
||||
# This only works however if you have avahi running on your admin machine else use IP
|
||||
clan.core.networking.targetHost = pkgs.lib.mkDefault "root@sara";
|
||||
|
||||
# ssh root@flash-installer.local lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
||||
# You can get your disk id by running the following command on the installer:
|
||||
# Replace <IP> with the IP of the installer printed on the screen or by running the `ip addr` command.
|
||||
# ssh root@<IP> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
||||
disko.devices.disk.main.device = "/dev/disk/by-id/__CHANGE_ME__";
|
||||
|
||||
# IMPORTANT! Add your SSH key here
|
||||
|
||||
Reference in New Issue
Block a user