Commit Graph

58 Commits

Author SHA1 Message Date
Jörg Thalheim
b38b10c9a6 automatic ruff fixes 2025-08-26 11:07:57 +02:00
Jörg Thalheim
cbb789bc69 PLW1508: fix 2025-08-25 15:17:06 +02:00
Mic92
8134ffd787 Merge pull request 'ruff-4-perf-fixes' (#4935) from ruff-4-perf-fixes into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4935
2025-08-25 13:12:14 +00:00
Jörg Thalheim
c65bb0b1ce PERF401: fix 2025-08-25 15:06:32 +02:00
Jörg Thalheim
ef5ab0c2f4 D404: fix 2025-08-25 14:56:48 +02:00
Jörg Thalheim
2199f4efd5 S324: ignore 2025-08-25 14:07:59 +02:00
Jörg Thalheim
dc5485d9f1 ruff: replace asserts outside of tests with Exceptions 2025-08-25 13:06:04 +02:00
Jörg Thalheim
0ec2c32ff8 ruff: apply automatic unsafe fixes 2025-08-25 11:34:41 +02:00
Jörg Thalheim
ea2d6aab65 ruff: apply automatic fixes 2025-08-25 11:34:41 +02:00
lassulus
4dc90b3d39 clan_lib flake: fix handling of maybes and empty sets 2025-08-22 23:44:14 +02:00
Qubasa
2934269279 clan-lib: Make Flake throw more concrete errors if the flake path is invalid or non existend
treefmt
2025-08-21 23:53:26 +02:00
Qubasa
606aae7212 flake.py: Error messages are now always ClanSelectErrors. Improved error messages
flake.py: Fix unbound variable

flake.py: Fix test_create.py test
2025-08-15 13:46:12 +07:00
Qubasa
3c1c6c1942 flake.py: Add a custom error message for missing clan export
test_clan_create_api: Fix check for SelectCmdError
2025-08-12 14:41:26 +07:00
Qubasa
0904c9da60 flake.py: Don't hide error messages 2025-08-12 14:18:19 +07:00
lassulus
0119fc06ca clan-cli select: show if select is cached or not 2025-08-02 21:26:39 +02:00
lassulus
5361261bd5 clan select: better error 2025-08-02 17:59:12 +02:00
lassulus
86e7bcc389 clan select: simplify select logging 2025-08-02 17:19:35 +02:00
lassulus
9e85c64139 clan-cli flake: show cache file location 2025-07-24 22:24:34 +02:00
Qubasa
7146c97362 clan_lib: Fix flake.select logging, now we log the first time select queries a path for the first time, it doesn't matter if it is cached or not. 2025-07-24 18:27:40 +07:00
Qubasa
b74aa31b87 clan-lib: Fix missing logging for flake.select execution 2025-07-24 17:29:09 +07:00
Jörg Thalheim
bd1451ce18 fix: handle arbitrary store paths references in flake cache
Previously, paths like /nix/store/hash-file.nix:123 were incorrectly
treated as pure store paths and wrapped in {"outPath": ...}, breaking
the cache. This fix:

- Adds helper functions to properly detect and handle store references
- Distinguishes between pure store paths and paths with metadata (line numbers)
- Supports multiple store references in a single string
- Handles custom NIX_STORE_DIR correctly
- Ensures existence checks work for all store references

Also fixes test_cache_gc to delete NIX_REMOTE for proper local store testing.
2025-07-22 17:13:04 +02:00
a-kenji
d4cb206e3e pkgs/cli: Add require_flake clan validation logic
Add a `require_flake` function that checks, if no argument is passed, if
we are in a clan directory.
If not will throw a helpful error.

Before `clan show`:

```
Traceback (most recent call last):
  File "/nix/store/8kb3l3yvz6svygnxdlrw5lmd3h3chc8a-clan-cli/bin/.clan-wrapped", line 9, in <module>
    sys.exit(main())
             ~~~~^^
  File "/nix/store/8kb3l3yvz6svygnxdlrw5lmd3h3chc8a-clan-cli/lib/python3.13/site-packages/clan_cli/cli.py", line 493, in main
    args.func(args)
    ~~~~~~~~~^^^^^^
  File "/nix/store/8kb3l3yvz6svygnxdlrw5lmd3h3chc8a-clan-cli/lib/python3.13/site-packages/clan_cli/clan/show.py", line 12, in show_command
    meta = get_clan_details(flake)
  File "/nix/store/8kb3l3yvz6svygnxdlrw5lmd3h3chc8a-clan-cli/lib/python3.13/site-packages/clan_lib/clan/get.py", line 22, in get_clan_details
    if flake.is_local and not flake.path.exists():
       ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'is_local'
```

with `require_flake`:

```
No clan flake found in the current directory or its parents - Use the --flake flag to specify a clan flake path or URL
```
2025-07-15 12:01:20 +02:00
Qubasa
36282b92bc clan-cli: improve log messages further
nix fmt
2025-07-14 12:02:03 +07:00
Qubasa
0cf35480a2 clan-cli: Filter out flake select traces to improve debug log visibility 2025-07-14 11:51:35 +07:00
Qubasa
f854c39292 clan-cli: Fix regression in ruff linter, where linter rules got overriden by local pyproject.toml
clan-app: Fix ruff regression where linter rules got overriden by local pyproject.toml
2025-07-08 17:23:32 +07:00
DavHau
ed0b86385b Refactor StoreBase to take machine name string instead of Machine object
- Updated StoreBase.__init__ to accept machine: str and flake: Flake
- Modified all StoreBase subclasses (in_repo, vm, fs, sops, password_store) to match new signature
- Added select_machine method to Flake class for machine-specific attribute selection
- Updated Machine.select to use the new Flake.select_machine method
- Fixed all test cases to pass machine name and flake to store constructors
- Maintained backward compatibility by keeping the same external API

This reduces coupling between the store system and the Machine class,
making the architecture more modular and flexible.
2025-07-07 10:24:11 +00:00
Johannes Kirschbauer
072654abd6 Templates: fix invalid mock flake 2025-07-06 16:43:38 +02:00
lassulus
d3cd481600 fix(flake): handle file paths with line numbers in cache existence check
The is_cached method now correctly handles store paths that have line
numbers appended (e.g., /nix/store/file.nix:123:456). Previously, these
paths would fail the existence check because the exact path with line
numbers doesn't exist as a file.

The fix adds a helper method that:
- First checks if the exact path exists
- If not, and the path contains colons, validates that the suffix
  consists only of numbers (line:column format)
- If valid, strips the line numbers and checks the base file path

This ensures that cached references to specific file locations are
properly validated while avoiding false positives with files that
have colons in their names.
2025-07-06 12:44:15 +02:00
lassulus
aaa27a0d0e clan_cli: better select debug output 2025-07-06 01:17:55 +02:00
lassulus
af33f122b0 clan_cli flake: remove apply from select, as it will break stuff in horrible ways
Since apply changes the structure of the retuned value, the cache will
be confused about the structure and in subsequent request will use this
wrong structure.

For example: we would use builtins.attrNames on inputs, the flake will
forever think that inputs is a list of strings and will report errors
whenever we try to fetch subkeys from it
2025-07-06 01:17:55 +02:00
lassulus
30bc8cb5d3 flake: prevent outPath in multiselect to avoid serialization issues
When using multiselect with outPath like {outPath,?meta}, nix evaluation
collapses the attrset to just the outPath string, breaking further selection.
Add validation during selector parsing to catch this and provide a clear error.
2025-07-03 18:53:36 +02:00
Jörg Thalheim
8fc67d00e3 select: drop unused --impure flag 2025-06-27 19:30:45 +02:00
Jörg Thalheim
6e8581189e select: use nix_options copy 2025-06-27 19:30:45 +02:00
Jörg Thalheim
ad69b0a567 select: drop unused nixpkgs fallback 2025-06-27 19:30:45 +02:00
Jörg Thalheim
1e6ceac2bd don't keep appending --impure to nix_options when running tests 2025-06-27 18:54:13 +02:00
Jörg Thalheim
6ae6f48586 select: disable remote building and substitution
this should make things faster since the derivation itself is trivial.
2025-06-27 13:37:16 +02:00
Qubasa
cd1d49b603 clan-lib: Move nix_options from Machine class to Flake class 2025-06-24 19:03:20 +02:00
pinpox
d88ac429cb Make machine ID a option 2025-06-24 10:42:03 +02:00
DavHau
020c74de92 vars-check: enable debug logging for cache misses 2025-06-18 14:22:57 +00:00
Jörg Thalheim
097024e8a9 fix: correctly check existence of CLAN_TEST_STORE paths in cache
The flake cache was only checking existence for paths starting with
NIX_STORE_DIR (defaulting to /nix/store), but not for paths in the
test store when CLAN_TEST_STORE is set. This caused the cache to
return stale references to paths that had been garbage collected.

This fix updates the is_cached method to also check for paths in 
the test store, preventing cache misses during tests.
2025-06-17 17:21:06 +02:00
Johannes Kirschbauer
32b5b7dc93 feat(flake): add function to get input names 2025-06-11 20:21:29 +02:00
Johannes Kirschbauer
6b684c45c3 feat(flake/select): add apply argument 2025-06-11 20:21:29 +02:00
Johannes Kirschbauer
a98b2fb60c Chore(complete_machines): simplify by using inventoryStore 2025-06-10 19:15:07 +02:00
Johannes Kirschbauer
7d3b5ecec9 Chore(flake.py): remove unused uncached_nix_eval_with_args 2025-06-10 19:15:07 +02:00
hsjobeki
931f0b00d0 Merge pull request 'chore(api/create_clan): remove unused reponse class' (#3907) from api-narrowing into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3907
2025-06-09 19:00:27 +00:00
Johannes Kirschbauer
ca8a228fba chore(flake): move 'inputs-from' into templates handling 2025-06-09 20:40:20 +02:00
lassulus
4d07e90930 select: fix error message showing nonsense 2025-06-06 10:12:15 +02:00
lassulus
e96099d588 select: fix non escaped ' 2025-06-06 10:12:15 +02:00
lassulus
ed89352ea1 clan-cli: clan_cli.dirs -> clan_lib.dirs 2025-05-20 12:08:30 +02:00
lassulus
9a0c6f55bd clan-cli: clan_cli.cmd -> clan_lib.cmd 2025-05-19 19:07:24 +02:00