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";
|
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 = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
|
||||||
disko.url = "github:nix-community/disko";
|
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
|
@dataclass
|
||||||
class CreateClanResponse:
|
class CreateClanResponse:
|
||||||
git_init: CmdOut
|
flake_init: CmdOut
|
||||||
|
git_init: CmdOut | None
|
||||||
git_add: CmdOut
|
git_add: CmdOut
|
||||||
git_config: CmdOut
|
git_config_username: CmdOut | None
|
||||||
|
git_config_email: CmdOut | None
|
||||||
flake_update: CmdOut
|
flake_update: CmdOut
|
||||||
|
|
||||||
|
|
||||||
@@ -34,9 +36,13 @@ class CreateOptions:
|
|||||||
template_url: str = minimal_template_url
|
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
|
@API.register
|
||||||
def create_clan(options: CreateOptions) -> CreateClanResponse:
|
def create_clan(options: CreateOptions) -> CreateClanResponse:
|
||||||
directory = Path(options.directory)
|
directory = Path(options.directory).resolve()
|
||||||
template_url = options.template_url
|
template_url = options.template_url
|
||||||
if not directory.exists():
|
if not directory.exists():
|
||||||
directory.mkdir()
|
directory.mkdir()
|
||||||
@@ -52,7 +58,6 @@ def create_clan(options: CreateOptions) -> CreateClanResponse:
|
|||||||
description="Directory already exists and is not empty.",
|
description="Directory already exists and is not empty.",
|
||||||
)
|
)
|
||||||
|
|
||||||
cmd_responses = {}
|
|
||||||
command = nix_command(
|
command = nix_command(
|
||||||
[
|
[
|
||||||
"flake",
|
"flake",
|
||||||
@@ -61,27 +66,27 @@ def create_clan(options: CreateOptions) -> CreateClanResponse:
|
|||||||
template_url,
|
template_url,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
out = run(command, cwd=directory)
|
flake_init = run(command, cwd=directory)
|
||||||
|
|
||||||
## Begin: setup git
|
git_init = None
|
||||||
command = nix_shell(["nixpkgs#git"], ["git", "init"])
|
if not directory.joinpath(".git").exists():
|
||||||
out = run(command, cwd=directory)
|
git_init = run(git_command(directory, "init"))
|
||||||
cmd_responses["git init"] = out
|
git_add = run(git_command(directory, "add", "."))
|
||||||
|
|
||||||
command = nix_shell(["nixpkgs#git"], ["git", "add", "."])
|
# check if username is set
|
||||||
out = run(command, cwd=directory)
|
has_username = run(git_command(directory, "config", "user.name"), check=False)
|
||||||
cmd_responses["git add"] = out
|
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"])
|
has_username = run(git_command(directory, "config", "user.email"), check=False)
|
||||||
out = run(command, cwd=directory)
|
git_config_email = None
|
||||||
cmd_responses["git config"] = out
|
if has_username.returncode != 0:
|
||||||
|
git_config_email = run(
|
||||||
command = nix_shell(
|
git_command(directory, "config", "user.email", "clan@example.com")
|
||||||
["nixpkgs#git"], ["git", "config", "user.email", "clan@example.com"]
|
)
|
||||||
)
|
|
||||||
out = run(command, cwd=directory)
|
|
||||||
cmd_responses["git config"] = out
|
|
||||||
## End: setup git
|
|
||||||
|
|
||||||
# Write inventory.json file
|
# Write inventory.json file
|
||||||
inventory = load_inventory(directory)
|
inventory = load_inventory(directory)
|
||||||
@@ -90,15 +95,17 @@ def create_clan(options: CreateOptions) -> CreateClanResponse:
|
|||||||
# Persist creates a commit message for each change
|
# Persist creates a commit message for each change
|
||||||
save_inventory(inventory, directory, "Init inventory")
|
save_inventory(inventory, directory, "Init inventory")
|
||||||
|
|
||||||
command = ["nix", "flake", "update"]
|
flake_update = run(
|
||||||
out = run(command, cwd=directory)
|
nix_shell(["nixpkgs#nix"], ["nix", "flake", "update"]), cwd=directory
|
||||||
cmd_responses["flake update"] = out
|
)
|
||||||
|
|
||||||
response = CreateClanResponse(
|
response = CreateClanResponse(
|
||||||
git_init=cmd_responses["git init"],
|
flake_init=flake_init,
|
||||||
git_add=cmd_responses["git add"],
|
git_init=git_init,
|
||||||
git_config=cmd_responses["git config"],
|
git_add=git_add,
|
||||||
flake_update=cmd_responses["flake update"],
|
git_config_username=git_config_username,
|
||||||
|
git_config_email=git_config_email,
|
||||||
|
flake_update=flake_update,
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
{
|
{
|
||||||
python3,
|
adwaita-icon-theme,
|
||||||
runCommand,
|
|
||||||
setuptools,
|
|
||||||
copyDesktopItems,
|
|
||||||
pygobject3,
|
|
||||||
wrapGAppsHook,
|
|
||||||
gtk4,
|
|
||||||
gnome,
|
|
||||||
pygobject-stubs,
|
|
||||||
gobject-introspection,
|
|
||||||
clan-cli,
|
clan-cli,
|
||||||
makeDesktopItem,
|
copyDesktopItems,
|
||||||
|
fontconfig,
|
||||||
|
gobject-introspection,
|
||||||
|
gtk4,
|
||||||
libadwaita,
|
libadwaita,
|
||||||
webkitgtk_6_0,
|
makeDesktopItem,
|
||||||
|
pygobject-stubs,
|
||||||
|
pygobject3,
|
||||||
pytest, # Testing framework
|
pytest, # Testing framework
|
||||||
pytest-cov, # Generate coverage reports
|
pytest-cov, # Generate coverage reports
|
||||||
pytest-subprocess, # fake the real subprocess behavior to make your tests more independent.
|
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-timeout, # Add timeouts to your tests
|
||||||
|
pytest-xdist, # Run tests in parallel on multiple cores
|
||||||
|
python3,
|
||||||
|
runCommand,
|
||||||
|
setuptools,
|
||||||
|
webkitgtk_6_0,
|
||||||
webview-ui,
|
webview-ui,
|
||||||
fontconfig,
|
wrapGAppsHook,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
source = ./.;
|
source = ./.;
|
||||||
@@ -39,7 +39,7 @@ let
|
|||||||
gtk4
|
gtk4
|
||||||
libadwaita
|
libadwaita
|
||||||
webkitgtk_6_0
|
webkitgtk_6_0
|
||||||
gnome.adwaita-icon-theme
|
adwaita-icon-theme
|
||||||
];
|
];
|
||||||
|
|
||||||
# Deps including python packages from the local project
|
# Deps including python packages from the local project
|
||||||
@@ -112,8 +112,8 @@ python3.pkgs.buildPythonApplication rec {
|
|||||||
mkdir -p .home/.local/share/fonts
|
mkdir -p .home/.local/share/fonts
|
||||||
export HOME=.home
|
export HOME=.home
|
||||||
|
|
||||||
fc-cache --verbose
|
fc-cache --verbose
|
||||||
# > fc-cache succeded
|
# > fc-cache succeded
|
||||||
|
|
||||||
echo "Loaded the following fonts ..."
|
echo "Loaded the following fonts ..."
|
||||||
fc-list
|
fc-list
|
||||||
@@ -160,8 +160,8 @@ python3.pkgs.buildPythonApplication rec {
|
|||||||
mkdir -p .home/.local/share/fonts
|
mkdir -p .home/.local/share/fonts
|
||||||
export HOME=.home
|
export HOME=.home
|
||||||
|
|
||||||
fc-cache --verbose
|
fc-cache --verbose
|
||||||
# > fc-cache succeded
|
# > fc-cache succeded
|
||||||
|
|
||||||
echo "Loaded the following fonts ..."
|
echo "Loaded the following fonts ..."
|
||||||
fc-list
|
fc-list
|
||||||
|
|||||||
@@ -49,7 +49,9 @@
|
|||||||
# This only works however if you have avahi running on your admin machine else use IP
|
# 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";
|
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 = {
|
disko.devices.disk.main = {
|
||||||
device = "/dev/disk/by-id/__CHANGE_ME__";
|
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
|
# 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";
|
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 = {
|
disko.devices.disk.main = {
|
||||||
device = "/dev/disk/by-id/__CHANGE_ME__";
|
device = "/dev/disk/by-id/__CHANGE_ME__";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
# Usage see: https://docs.clan.lol
|
# Usage see: https://docs.clan.lol
|
||||||
clan = clan-core.lib.buildClan {
|
clan = clan-core.lib.buildClan {
|
||||||
directory = self;
|
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.
|
# Distributed services, uncomment to enable.
|
||||||
# inventory = {
|
# inventory = {
|
||||||
@@ -45,7 +45,9 @@
|
|||||||
# This only works however if you have avahi running on your admin machine else use IP
|
# 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";
|
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__";
|
disko.devices.disk.main.device = "/dev/disk/by-id/__CHANGE_ME__";
|
||||||
|
|
||||||
# IMPORTANT! Add your SSH key here
|
# 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
|
# 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";
|
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__";
|
disko.devices.disk.main.device = "/dev/disk/by-id/__CHANGE_ME__";
|
||||||
|
|
||||||
# IMPORTANT! Add your SSH key here
|
# IMPORTANT! Add your SSH key here
|
||||||
|
|||||||
Reference in New Issue
Block a user