Compare commits

..

33 Commits

Author SHA1 Message Date
a-kenji
66aa97ad8f wip 2024-05-28 14:53:57 +02:00
clan-bot
c252f11c1f Merge pull request 'docs/secrets: improve chapter assigning access' (#1474) from DavHau-dave into main 2024-05-28 11:11:46 +00:00
DavHau
f1f040397d docs/secrets: improve chapter assigning access
Since we already walk the user through creating a secret in an earlier step, it makes more sense explain first how to add machines/users to an existing secret instead of creating  a new one
2024-05-28 13:08:19 +02:00
clan-bot
418e9937cb Merge pull request 'clan: add descriptions for reference documentation' (#1473) from a-kenji-cli/doc into main 2024-05-28 09:40:50 +00:00
a-kenji
c34664429c clan: add descriptions for reference documentation 2024-05-28 11:37:32 +02:00
clan-bot
6fe5928297 Merge pull request 'clan: add run_no_stdout function suppressing stdout' (#1472) from a-kenji-run_no_stdout into main 2024-05-28 09:17:14 +00:00
a-kenji
eee99730d1 clan: add run_no_stdout function suppressing stdout
Add the `run_no_stdout` function suppressing stdout by default.This
keeps the noise down on most commands, while still
stayingdebuggable.Stdout will be active when the `--debug` flag is
passed to the cli.

Fixes #1443
2024-05-28 11:13:55 +02:00
clan-bot
9394760e3b Merge pull request 'editor: improve nixpkgs option completions' (#1470) from a-kenji-improve/editor into main 2024-05-28 07:38:09 +00:00
a-kenji
a0b0e1a0ac editor: improve nixpkgs option completions 2024-05-28 09:34:57 +02:00
clan-bot
dbaa26ccaa Merge pull request 'clan: machines --help add examples to help output' (#1468) from a-kenji-clan/cli/machines-examples into main 2024-05-27 19:04:30 +00:00
a-kenji
d1591d4485 clan: machines --help add examples to help output 2024-05-27 21:01:05 +02:00
clan-bot
c68a8306ba Merge pull request 'clan: duplicate description field for generation of the reference documentation' (#1467) from a-kenji-clan/cli/add-description into main 2024-05-27 18:32:54 +00:00
a-kenji
ec9f605004 clan: duplicate description field for generation of the reference documentation 2024-05-27 20:29:34 +02:00
clan-bot
e60efea1f7 Merge pull request 'clan: ssh --help add examples' (#1466) from a-kenji-clan/help/ssh into main 2024-05-27 18:18:08 +00:00
a-kenji
efacb7f184 clan: ssh --help add examples
Add examples to the output of `clan ssh --help`.
2024-05-27 20:14:37 +02:00
clan-bot
67275aac63 Merge pull request 'clan: rename cLan to clan' (#1465) from a-kenji-rename-clan into main 2024-05-27 17:56:32 +00:00
a-kenji
a704a05b15 clan: rename cLan to clan 2024-05-27 19:52:51 +02:00
Mic92
01aafc520d Merge pull request 'consistent rename cLAN -> Clan' (#1464) from rename into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/1464
2024-05-27 13:58:32 +00:00
Jörg Thalheim
c0a54f539a consistent rename cLAN -> Clan 2024-05-27 13:58:32 +00:00
clan-bot
1df4e361f7 Merge pull request 'clan: add examples and description to most help' (#1463) from a-kenji-clan/examples into main 2024-05-27 12:37:22 +00:00
a-kenji
e8bd5ad24b clan: add examples and description to most help
Add examples and description to most toplevel help outputs.
2024-05-27 14:33:58 +02:00
clan-bot
775f993ecc Merge pull request 'clan-cli: Fix nix develop not working in template because of symlink' (#1462) from Qubasa-main into main 2024-05-27 12:05:17 +00:00
Qubasa
0e1478edcd clan-cli: Fix nix develop not working in template because of symlink 2024-05-27 14:00:31 +02:00
clan-bot
bfc1203a8a Merge pull request 'init: vscode .#editor' (#1461) from Qubasa-init/editors into main 2024-05-27 12:00:26 +00:00
Qubasa
2bd8b144b9 init: vscode .#editor 2024-05-27 13:52:54 +02:00
clan-bot
b52b2221b0 Merge pull request 'drop offline in nix shell' (#1459) from fix-mass-rebuilds into main 2024-05-27 11:43:32 +00:00
Jörg Thalheim
64adf17368 drop offline in nix shell
Otherwise we become gentoo!
2024-05-27 13:40:11 +02:00
clan-bot
509d8c1dae Merge pull request 'make git-hooks opt-in' (#1453) from git-hooks into main 2024-05-27 10:34:07 +00:00
clan-bot
295de17640 Merge pull request 'docs: secrets: list the main steps of the guide' (#1456) from DavHau-dave into main 2024-05-27 10:05:55 +00:00
DavHau
b158c2706f docs: secrets: list the main steps of the guide
... so the user has a routh idea about the mein steps
2024-05-27 12:02:29 +02:00
clan-bot
750979c988 Merge pull request 'A Kenji Clan/Cli/Fix Naming' (#1455) from a-kenji-clan/cli/fix-naming into main 2024-05-27 09:54:36 +00:00
a-kenji
6d7849a03c clan: fix description of cli tool 2024-05-27 11:51:25 +02:00
Jörg Thalheim
f46fd3ace6 make git-hooks opt-in
pre-commit hook break git commits and are disruptive.
Therefore people that want to enable this feature, should enable it locally instead.
I.e. treefmt will also check untracked files that are not meant for the current commit.
2024-05-27 11:08:17 +02:00
27 changed files with 300 additions and 83 deletions

View File

@@ -1,4 +1,4 @@
# Contributing to cLAN
# Contributing to Clan
## Live-reloading documentation

View File

@@ -1,6 +1,6 @@
# Clan Core Repository
Welcome to the Clan Core Repository, the heart of the [clan.lol](https://clan.lol/) project! This monorepo is the foundation of Clan, a revolutionary open-source project aimed at restoring fun, freedom, and functionality to computing. Here, you'll find all the essential packages, NixOS modules, CLI tools, and tests needed to contribute to and work with the cLAN project. Clan leverages the Nix system to ensure reliability, security, and seamless management of digital environments, putting the power back into the hands of users.
Welcome to the Clan Core Repository, the heart of the [clan.lol](https://clan.lol/) project! This monorepo is the foundation of Clan, a revolutionary open-source project aimed at restoring fun, freedom, and functionality to computing. Here, you'll find all the essential packages, NixOS modules, CLI tools, and tests needed to contribute to and work with the Clan project. Clan leverages the Nix system to ensure reliability, security, and seamless management of digital environments, putting the power back into the hands of users.
## Why Clan?

View File

@@ -1,4 +1,4 @@
{ inputs, ... }:
{ ... }:
{
perSystem =
{
@@ -9,7 +9,6 @@
}:
let
writers = pkgs.callPackage ./pkgs/builders/script-writers.nix { };
inherit (pkgs.callPackage inputs.git-hooks { }) lib;
ansiEscapes = {
reset = ''\033[0m'';
@@ -22,11 +21,6 @@
select-shell = writers.writePython3Bin "select-shell" {
flakeIgnore = [ "E501" ];
} ./pkgs/scripts/select-shell.py;
# run treefmt before each commit
install-pre-commit-hook =
with lib.git-hooks;
pre-commit (wrap.abort-on-change config.treefmt.build.wrapper);
in
{
devShells.default = pkgs.mkShell {
@@ -41,8 +35,6 @@
config.treefmt.build.wrapper
];
shellHook = ''
${install-pre-commit-hook}
echo -e "${ansiEscapes.green}switch to another dev-shell using: select-shell${ansiEscapes.reset}"
'';
};

View File

@@ -20,11 +20,11 @@ There are several reasons for choosing to self-host. These can include:
Alice wants to self-host a mumble server for her family.
- She visits to the cLAN website, and follows the instructions on how to install cLAN-OS on her server.
- Alice logs into a terminal on her server via SSH (alternatively uses cLAN GUI app)
- Using the cLAN CLI or GUI tool, alice creates a new private network for her family (VPN)
- Alice now browses a list of curated cLAN modules and finds a module for mumble.
- She adds this module to her network using the cLAN tool.
- She visits to the Clan website, and follows the instructions on how to install Clan-OS on her server.
- Alice logs into a terminal on her server via SSH (alternatively uses Clan GUI app)
- Using the Clan CLI or GUI tool, alice creates a new private network for her family (VPN)
- Alice now browses a list of curated Clan modules and finds a module for mumble.
- She adds this module to her network using the Clan tool.
- After that, she uses the clan tool to invite her family members to her network
- Other family members join the private network via the invitation.
- By accepting the invitation, other members automatically install all required software to interact with the network on their machine.
@@ -33,7 +33,7 @@ Alice wants to self-host a mumble server for her family.
Alice wants to add a photos app to her private network
- She uses the clan CLI or GUI tool to manage her existing private cLAN family network
- She uses the clan CLI or GUI tool to manage her existing private Clan family network
- She discovers a module for photoprism, and adds it to her server using the tool
- Other members who are already part of her network, will receive a notification that an update is required to their environment
- After accepting, all new software and services to interact with the new photoprism service will be installed automatically.

View File

@@ -1,4 +1,4 @@
# Joining a cLAN network
# Joining a Clan network
## General Description
@@ -8,13 +8,13 @@ Joining a self-hosted infrastructure involves connecting to a network, server, o
### Story 1: Joining a private network
Alice' son Bob has never heard of cLAN, but receives an invitation URL from Alice who already set up private cLAN network for her family.
Alice' son Bob has never heard of Clan, but receives an invitation URL from Alice who already set up private Clan network for her family.
Bob opens the invitation link and lands on the cLAN website. He quickly learns about what cLAN is and can see that the invitation is for a private network of his family that hosts a number of services, like a private voice chat and a photo sharing platform.
Bob opens the invitation link and lands on the Clan website. He quickly learns about what Clan is and can see that the invitation is for a private network of his family that hosts a number of services, like a private voice chat and a photo sharing platform.
Bob decides to join the network and follows the instructions to install the cLAN tool on his computer.
Bob decides to join the network and follows the instructions to install the Clan tool on his computer.
Feeding the invitation link to the cLAN tool, bob registers his machine with the network.
Feeding the invitation link to the Clan tool, bob registers his machine with the network.
All programs required to interact with the network will be installed and configured automatically and securely.
@@ -22,7 +22,7 @@ Optionally, bob can customize the configuration of these programs through a simp
### Story 2: Receiving breaking changes
The cLAN family network which Bob is part of received an update.
The Clan family network which Bob is part of received an update.
The existing photo sharing service has been removed and replaced with another alternative service. The new photo sharing service requires a different client app to view and upload photos.
@@ -30,7 +30,7 @@ Bob accepts the update. Now his environment will be updated. The old client soft
Because Bob has customized the previous photo viewing app, he is notified that this customization is no longer valid, as the software has been removed (deprecation message).l
Optionally, Bob can now customize the new photo viewing software through his cLAN configuration app or via a config file.
Optionally, Bob can now customize the new photo viewing software through his Clan configuration app or via a config file.
## Challenges

View File

@@ -1,10 +1,10 @@
# cLAN module maintaining
# Clan module maintaining
## General Description
cLAN modules are pieces of software that can be used by admins to build a private or public infrastructure.
Clan modules are pieces of software that can be used by admins to build a private or public infrastructure.
cLAN modules should have the following properties:
Clan modules should have the following properties:
1. Documented: It should be clear what the module does and how to use it.
1. Self contained: A module should be usable as is. If it requires any other software or settings, those should be delivered with the module itself.

View File

@@ -4,10 +4,15 @@ Clan enables encryption of secrets (such as passwords & keys) ensuring security
Clan utilizes the [sops](https://github.com/getsops/sops) format and integrates with [sops-nix](https://github.com/Mic92/sops-nix) on NixOS machines.
This guide will walk you through:
### Create Your Master Keypair
- **Creating a Keypair for Your User**: Learn how to generate a keypair for $USER to securely control all secrets.
- **Creating Your First Secret**: Step-by-step instructions on creating your initial secret.
- **Assigning Machine Access to the Secret**: Understand how to grant a machine access to the newly created secret.
To get started, you'll need to create **Your master keypair**.
## Create Your Admin Keypair
To get started, you'll need to create **Your admin keypair**.
!!! info
Don't worry — if you've already made one before, this step won't change or overwrite it.
@@ -27,7 +32,7 @@ Also add your age public key to the repository with 'clan secrets users add YOUR
!!! warning
Make sure to keep a safe backup of the private key you've just created.
If it's lost, you won't be able to get to your secrets anymore because they all need the master key to be unlocked.
If it's lost, you won't be able to get to your secrets anymore because they all need the admin key to be unlocked.
!!! note
It's safe to add any secrets created by the clan CLI and placed in your repository to version control systems like `git`.
@@ -35,7 +40,7 @@ Also add your age public key to the repository with 'clan secrets users add YOUR
### Add Your Public Key
```bash
clan secrets users add <your_username> <your_public_key>
clan secrets users add $USER <your_public_key>
```
It's best to choose the same username as on your Setup/Admin Machine that you use to control the deployment with.
@@ -101,17 +106,20 @@ In your nixos configuration you can get a path to secrets like this `config.sops
### Assigning Access
By default, secrets are encrypted for your key. To specify which users and machines can access a secret:
When using `clan secrets set <secret>` without arguments, secrets are encrypted for the key of the user named like your current $USER.
```bash
clan secrets set --machine <machine1> --machine <machine2> --user <user1> --user <user2> <secret_name>
```
You can also just add machines/users to existing secrets:
To add machines/users to an existing secret use:
```bash
clan secrets machines add-secret <machine_name> <secret_name>
```
Alternatively specify users and machines while creating a secret:
```bash
clan secrets set --machine <machine1> --machine <machine2> --user <user1> --user <user2> <secret_name>
```
## Advanced
In this section we go into more advanced secret management topics.
@@ -183,11 +191,9 @@ Since our clan secret module will auto-import secrets that are encrypted for a p
you can now remove `sops.secrets.<secrets> = { };` unless you need to specify more options for the secret like owner/group of the secret file.
## Indepth Explanation
The secrets system conceptually knows two different entities:
- **Machine**: consumes secrets

25
eval-options.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# nix eval \
# --json \
# --impure \
# --expr \
# "(let pkgs = import <nixpkgs> { }; in (pkgs.lib.evalModules { modules = (import <nixpkgs/nixos/modules/module-list.nix>) ++ [ ({...}: { nixpkgs.hostPlatform = builtins.currentSystem;} ) ] ; })).options"
# nix eval \
# --json \
# --impure \
# --expr \
# "(let pkgs = import <nixpkgs> { }; in (pkgs.lib.evalModules { modules = (import <nixpkgs/nixos/modules/module-list.nix>) ++ [(import <nixpkgs/nixos/modules/misc/assertions.nix>)] ++ [ (builtins.getFlake https://git.clan.lol/clan/clan-core/archive/main.tar.gz).clanModules (builtins.getFlake https://git.clan.lol/clan/clan-core/archive/main.tar.gz).nixosModules.clanCore ({...}: { nixpkgs.hostPlatform = builtins.currentSystem;} ) ] ; })).options"
# nix eval \
# --json \
# --impure \
# --expr \
# "(let pkgs = import <nixpkgs> { }; allNixosModules = (import <nixpkgs/nixos/modules/module-list.nix>) ++ [(import <nixpkgs/nixos/modules/misc/assertions.nix>) { nixpkgs.hostPlatform = \"x86_64-linux\"; }]; in (pkgs.lib.evalModules { modules = allNixosModules ++ [ (builtins.getFlake https://git.clan.lol/clan/clan-core/archive/main.tar.gz).clanModules (builtins.getFlake https://git.clan.lol/clan/clan-core/archive/main.tar.gz).nixosModules.clanCore ({...}: { nixpkgs.hostPlatform = builtins.currentSystem;} ) ] ; })).options"
#
#
nix eval \
--json \
--impure \
--file \
./options.nix

17
flake.lock generated
View File

@@ -40,22 +40,6 @@
"type": "github"
}
},
"git-hooks": {
"flake": false,
"locked": {
"lastModified": 1716413087,
"narHash": "sha256-nSTIB7JeJGBGsvtqlyfhUByh/isyK1nfOq2YMxUOFJQ=",
"owner": "fricklerhandwerk",
"repo": "git-hooks",
"rev": "99a78fcf7dc03ba7b1d5c00af109c1e28ced3490",
"type": "github"
},
"original": {
"owner": "fricklerhandwerk",
"repo": "git-hooks",
"type": "github"
}
},
"nixlib": {
"locked": {
"lastModified": 1712450863,
@@ -149,7 +133,6 @@
"inputs": {
"disko": "disko",
"flake-parts": "flake-parts",
"git-hooks": "git-hooks",
"nixos-generators": "nixos-generators",
"nixos-images": "nixos-images",
"nixpkgs": "nixpkgs",

View File

@@ -21,8 +21,6 @@
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
git-hooks.url = "github:fricklerhandwerk/git-hooks";
git-hooks.flake = false;
};
outputs =

17
options.nix Normal file
View File

@@ -0,0 +1,17 @@
let
flake = builtins.getFlake "https://git.clan.lol/clan/clan-core/archive/main.tar.gz";
nixpkgs = flake.inputs.nixpkgs;
pkgs = flake.inputs.nixpkgs.legacyPackages.${builtins.currentSystem};
clanCore = flake.outputs.nixosModules.clanCore;
clanModules = flake.outputs.clanModules;
allNixosModules = (import "${nixpkgs}/nixos/modules/module-list.nix") ++ [
"${nixpkgs}/nixos/modules/misc/assertions.nix"
{ nixpkgs.hostPlatform = "x86_64-linux"; }
];
clanCoreNixosModules = [
clanCore
{ clanCore.clanDir = ./.; }
] ++ allNixosModules ++ (builtins.attrValues clanModules);
clanCoreNixos = pkgs.nixos { imports = clanCoreNixosModules; };
in
clanCoreNixos.options

View File

@@ -54,7 +54,7 @@ class AppendOptionAction(argparse.Action):
def create_parser(prog: str | None = None) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog=prog,
description="cLAN tool",
description="The clan cli tool.",
epilog=(
"""
Online reference for the clan cli tool: https://docs.clan.lol/reference/cli/
@@ -126,6 +126,7 @@ For more detailed information, visit: https://docs.clan.lol/getting-started/back
parser_flake = subparsers.add_parser(
"flakes",
help="create a clan flake inside the current directory",
description="create a clan flake inside the current directory",
epilog=(
"""
Examples:
@@ -143,6 +144,7 @@ For more detailed information, visit: https://docs.clan.lol/getting-started
parser_config = subparsers.add_parser(
"config",
help="set nixos configuration",
description="set nixos configuration",
epilog=(
"""
"""
@@ -151,12 +153,32 @@ For more detailed information, visit: https://docs.clan.lol/getting-started
)
config.register_parser(parser_config)
parser_ssh = subparsers.add_parser("ssh", help="ssh to a remote machine")
parser_ssh = subparsers.add_parser(
"ssh",
help="ssh to a remote machine",
description="ssh to a remote machine",
epilog=(
"""
This subcommand allows seamless ssh access to the nixos-image builders.
Examples:
$ clan ssh [ssh_args ...] --json [JSON]
Will ssh in to the machine based on the deployment information contained in
the json string. [JSON] can either be a json formatted string itself, or point
towards a file containing the deployment information
For more detailed information, visit: https://docs.clan.lol/getting-started/deploy
"""
),
formatter_class=argparse.RawTextHelpFormatter,
)
ssh_cli.register_parser(parser_ssh)
parser_secrets = subparsers.add_parser(
"secrets",
help="manage secrets",
description="manage secrets",
epilog=(
"""
This subcommand provides an interface to secret facts.
@@ -180,6 +202,7 @@ For more detailed information, visit: https://docs.clan.lol/getting-started/secr
parser_facts = subparsers.add_parser(
"facts",
help="manage facts",
description="manage facts",
epilog=(
"""
@@ -216,6 +239,7 @@ For more detailed information, visit: https://docs.clan.lol/getting-started/secr
parser_machine = subparsers.add_parser(
"machines",
help="manage machines and their configuration",
description="manage machines and their configuration",
epilog=(
"""
This subcommand provides an interface to machines managed by clan.
@@ -239,14 +263,22 @@ For more detailed information, visit: https://docs.clan.lol/getting-started/depl
)
machines.register_parser(parser_machine)
parser_vms = subparsers.add_parser("vms", help="manage virtual machines")
parser_vms = subparsers.add_parser(
"vms", help="manage virtual machines", description="manage virtual machines"
)
vms.register_parser(parser_vms)
parser_history = subparsers.add_parser("history", help="manage history")
parser_history = subparsers.add_parser(
"history",
help="manage history",
description="manage history",
)
history.register_parser(parser_history)
parser_flash = subparsers.add_parser(
"flash", help="flash machines to usb sticks or into isos"
"flash",
help="flash machines to usb sticks or into isos",
description="flash machines to usb sticks or into isos",
)
flash.register_parser(parser_flash)

View File

@@ -140,3 +140,23 @@ def run(
raise ClanCmdError(cmd_out)
return cmd_out
def run_no_stdout(
cmd: list[str],
*,
env: dict[str, str] | None = None,
cwd: Path = Path.cwd(),
log: Log = Log.STDERR,
check: bool = True,
error_msg: str | None = None,
) -> CmdOut:
"""
Like run, but automatically suppresses stdout, if not in DEBUG log level.
If in DEBUG log level the stdout of commands will be shown.
"""
if logging.getLogger(__name__.split(".")[0]).isEnabledFor(logging.DEBUG):
return run(cmd, env=env, log=log, check=check, error_msg=error_msg)
else:
log = Log.NONE
return run(cmd, env=env, log=log, check=check, error_msg=error_msg)

View File

@@ -53,7 +53,7 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig:
gcroot_icon: Path = machine_gcroot(flake_url=str(flake_url)) / vm.machine_name
nix_add_to_gcroots(vm.machine_icon, gcroot_icon)
# Get the cLAN name
# Get the Clan name
cmd = nix_eval(
[
f'{flake_url}#clanInternals.machines."{system}"."{machine_name}".config.clanCore.clanName'
@@ -70,7 +70,7 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig:
)
res = run_cmd(cmd)
# If the icon is null, no icon is set for this cLAN
# If the icon is null, no icon is set for this Clan
if res == "null":
icon_path = None
else:
@@ -113,7 +113,7 @@ def inspect_command(args: argparse.Namespace) -> None:
res = inspect_flake(
flake_url=inspect_options.flake, machine_name=inspect_options.machine
)
print("cLAN name:", res.clan_name)
print("Clan name:", res.clan_name)
print("Icon:", res.icon)
print("Description:", res.description)
print("Last updated:", res.last_updated)

View File

@@ -17,7 +17,26 @@ def register_parser(parser: argparse.ArgumentParser) -> None:
required=True,
)
update_parser = subparser.add_parser("update", help="Update a machine")
update_parser = subparser.add_parser(
"update",
help="Update a machine",
epilog=(
"""
This subcommand provides an interface to update machines managed by clan.
Examples:
$ clan machines update [MACHINES]
Will update the specified machine [MACHINE], if [MACHINE] is omitted, the command
will attempt to update every configured machine.
To exclude machines being updated `clan.deployment.requireExplicitUpdate = true;`
can be set in the machine config.
For more detailed information, visit: https://docs.clan.lol/getting-started/deploy
"""
),
formatter_class=argparse.RawTextHelpFormatter,
)
register_update_parser(update_parser)
create_parser = subparser.add_parser("create", help="Create a machine")
@@ -26,7 +45,21 @@ def register_parser(parser: argparse.ArgumentParser) -> None:
delete_parser = subparser.add_parser("delete", help="Delete a machine")
register_delete_parser(delete_parser)
list_parser = subparser.add_parser("list", help="List machines")
list_parser = subparser.add_parser(
"list",
help="List machines",
epilog=(
"""
This subcommand lists all machines managed by this clan.
Examples:
$ clan machines list
Lists all the machines and their descriptions.
"""
),
formatter_class=argparse.RawTextHelpFormatter,
)
register_list_parser(list_parser)
install_parser = subparser.add_parser(
@@ -37,5 +70,23 @@ def register_parser(parser: argparse.ArgumentParser) -> None:
The target must be a Linux based system reachable via SSH.
Installing a machine means overwriting the target's disk.
""",
epilog=(
"""
This subcommand provides an interface to install machines managed by clan.
Examples:
$ clan machines install [MACHINE] [TARGET_HOST]
Will install the specified machine [MACHINE], to the specified [TARGET_HOST].
$ clan machines install [MACHINE] --json [JSON]
Will install the specified machine [MACHINE] to the host exposed by
the deployment information of the [JSON] deployment string.
For information on how to set up the installer see: https://docs.clan.lol/getting-started/installer/
For more detailed information, visit: https://docs.clan.lol/getting-started/deploy
"""
),
formatter_class=argparse.RawTextHelpFormatter,
)
register_install_parser(install_parser)

View File

@@ -6,7 +6,7 @@ from pathlib import Path
from clan_cli.api import API
from ..cmd import Log, run
from ..cmd import run_no_stdout
from ..nix import nix_config, nix_eval
log = logging.getLogger(__name__)
@@ -34,10 +34,7 @@ def list_machines(flake_url: str | Path, debug: bool) -> dict[str, MachineInfo]:
]
)
if not debug:
proc = run(cmd, log=Log.NONE)
else:
proc = run(cmd)
proc = run_no_stdout(cmd)
res = proc.stdout.strip()
machines_dict = json.loads(res)

View File

@@ -10,7 +10,7 @@ from clan_cli.clan_uri import ClanURI, MachineData
from clan_cli.dirs import vm_state_dir
from clan_cli.qemu.qmp import QEMUMonitorProtocol
from ..cmd import run
from ..cmd import run_no_stdout
from ..errors import ClanError
from ..nix import nix_build, nix_config, nix_eval, nix_metadata
from ..ssh import Host, parse_deployment_address
@@ -197,7 +197,7 @@ class Machine:
config_json.flush()
file_info = json.loads(
run(
run_no_stdout(
nix_eval(
[
"--impure",
@@ -247,10 +247,10 @@ class Machine:
]
if method == "eval":
output = run(nix_eval(args)).stdout.strip()
output = run_no_stdout(nix_eval(args)).stdout.strip()
return output
elif method == "build":
outpath = run(nix_build(args)).stdout.strip()
outpath = run_no_stdout(nix_build(args)).stdout.strip()
return Path(outpath)
else:
raise ValueError(f"Unknown method {method}")

View File

@@ -106,7 +106,7 @@ def nix_shell(packages: list[str], cmd: list[str]) -> list[str]:
if os.environ.get("IN_NIX_SANDBOX"):
return cmd
return [
*nix_command(["shell", "--offline", "--inputs-from", f"{nixpkgs_flake()!s}"]),
*nix_command(["shell", "--inputs-from", f"{nixpkgs_flake()!s}"]),
*packages,
"-c",
*cmd,

View File

@@ -83,7 +83,7 @@ let
cp -r ${./.} $out
chmod -R +w $out
rm $out/clan_cli/config/jsonschema
ln -s ${nixpkgs'} $out/clan_cli/nixpkgs
ln -sf ${nixpkgs'} $out/clan_cli/nixpkgs
cp -r ${../../lib/jsonschema} $out/clan_cli/config/jsonschema
'';
@@ -101,7 +101,7 @@ let
outputs = _inputs: { };
}
EOF
ln -s ${nixpkgs} $out/path
ln -sf ${nixpkgs} $out/path
nix flake update $out \
--store ./. \
--extra-experimental-features 'nix-command flakes'

View File

@@ -26,7 +26,7 @@ log = logging.getLogger(__name__)
class MainWindow(Adw.ApplicationWindow):
def __init__(self, config: ClanConfig) -> None:
super().__init__()
self.set_title("cLAN Manager")
self.set_title("Clan Manager")
self.set_default_size(980, 850)
overlay = ToastOverlay.use().overlay

View File

@@ -27,7 +27,7 @@ let
name = "org.clan.vm-manager";
exec = "clan-vm-manager %u";
icon = ./clan_vm_manager/assets/clan_white.png;
desktopName = "cLAN Manager";
desktopName = "Clan Manager";
startupWMClass = "clan";
mimeTypes = [ "x-scheme-handler/clan" ];
};

View File

@@ -0,0 +1,40 @@
{
lib,
coreutils,
nil,
nixd,
nixpkgs-fmt,
direnv,
vscode-extensions,
vscode-with-extensions,
vscodium,
writeShellApplication,
}:
let
codium = vscode-with-extensions.override {
vscode = vscodium;
vscodeExtensions = [
vscode-extensions.jnoortheen.nix-ide
vscode-extensions.mkhl.direnv
];
};
in
writeShellApplication {
name = "clan-edit-codium";
runtimeInputs = [
coreutils
nil
nixd
nixpkgs-fmt
direnv
];
text = ''
set -eux
DATA_DIR="''${XDG_CACHE_HOME:-$HOME/.cache}/clan-edit-codium"
SETTINGS="$DATA_DIR"/User/settings.json
${coreutils}/bin/mkdir -p "$DATA_DIR/User"
cat ${./settings.json} > "$SETTINGS"
exec ${lib.getExe codium} --user-data-dir "$DATA_DIR" "$@"
'';
}

4
pkgs/editor/default.nix Normal file
View File

@@ -0,0 +1,4 @@
{ pkgs }:
{
clan-edit-codium = pkgs.callPackage ./clan-edit-codium.nix;
}

23
pkgs/editor/settings.json Normal file
View File

@@ -0,0 +1,23 @@
{
"security.workspace.trust.enabled": false,
"nix.enableLanguageServer": true,
"nix.serverPath": "nixd",
"nix.formatterPath": "nixpkgs-fmt",
"nix.serverSettings": {
"nixd": {
"formatting": {
"command": "nixpkgs-fmt"
},
"options": {
"nixos": {
"expr": "(let pkgs = import <nixpkgs> { }; in (pkgs.lib.evalModules { modules
= (import <nixpkgs/nixos/modules/module-list.nix>) ++ [ ({...}: {
nixpkgs.hostPlatform = builtins.currentSystem;} ) ] ; })).options"
},
"home-manager": {
"expr": "(builtins.getFlake \"github:nix-community/home-manager\").homeConfigurations.<name>.options"
}
}
}
}
}

View File

@@ -25,6 +25,7 @@
moonlight-sunshine-accept = pkgs.callPackage ./moonlight-sunshine-accept { };
merge-after-ci = pkgs.callPackage ./merge-after-ci { inherit (config.packages) tea-create-pr; };
pending-reviews = pkgs.callPackage ./pending-reviews { };
editor = pkgs.callPackage ./editor/clan-edit-codium.nix { };
}
// lib.optionalAttrs pkgs.stdenv.isLinux {
wayland-proxy-virtwl = pkgs.callPackage ./wayland-proxy-virtwl { };

28
scripts/pre-commit Executable file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# To install:
# ln -sf ../../scripts/pre-commit .git/hooks/pre-commit
set -o errexit
set -o nounset
set -o pipefail
readarray staged < <(git diff --name-only --cached)
[[ ${#staged[@]} = 0 ]] && exit
unstash() {
local ret=$?
set +e
git stash pop -q
exit "$ret"
}
git stash push --quiet --keep-index --message "pre-commit"
trap unstash EXIT
nix fmt
{
changed=$(git diff --name-only --exit-code);
status=$?;
} || true
if [[ $status -ne 0 ]]; then
exec 1>&2
echo Files changed by pre-commit hook:
echo "$changed"
exit $status
fi

View File

@@ -85,9 +85,9 @@
};
in
{
# all machines managed by cLAN
# all machines managed by Clan
inherit (clan) nixosConfigurations clanInternals;
# add the cLAN cli tool to the dev shell
# add the Clan cli tool to the dev shell
devShells.${system}.default = pkgs.mkShell {
packages = [ clan-core.packages.${system}.clan-cli ];
};