Commit Graph
1105 Commits
Author SHA1 Message Date
Felix Uhl 6651792c28 disko2: Validate config for type-safety in python 2024-11-17 21:37:39 +01:00
Felix Uhl ae7891e21f disko2: Fix all mypy type checking errors
Belongs to d382a3cccf, but I authored that
on another machine.

Making sure vscode uses mypy from the environment is very important now,
because some of these errors get triggered in different ways depending
on the version.
2024-11-17 19:39:07 +01:00
Felix Uhl a0e8f7f587 disko2: Add code generator for disko config type
There are still two issues: The type of "topology" in zpool is not
created, and gpt_partitions_options_hybrid_options for some reason
contains a `_create: "_create"` entry. This is an issue with the nix
evaluation, though, not with the code generator.

I'm fixing these issues manually to have some state I can start working
from.
2024-11-17 15:08:26 +01:00
Felix Uhl 08ec11ae1b lib: Fix jsonTypes evaluation
This will be very useful for generating documentation and python type
definitions.
2024-11-17 15:08:26 +01:00
Felix Uhl d382a3cccf tests: Make mypy a lot stricter
The default `strict = true` is too permissive for my liking, especially
how it allows using `Any` in many places and doesn't warn about them at
all.
2024-11-15 16:31:53 +01:00
Felix Uhl a5c646bd93 lib: Fix jsonTypes evaluation
This will be very useful for generating documentation and python type
definitions.
2024-11-13 00:08:21 +01:00
Felix Uhl 2bd9c4f8c7 dev,docs: Improve and document DX with Python 2024-11-10 18:48:35 +01:00
Felix Uhl 70efb0a658 lib: Evaluate partition's _index parameter
This is required to be able to generate sgdisk invocations that are
equivalent to what's currently generated in nix.
2024-11-10 17:39:39 +01:00
Felix Uhl 4f16850ca4 lib: Detect and show new keys in dict_diff 2024-11-10 17:31:44 +01:00
Felix Uhl b30e5ced5e disko2 dev: Print better error message 2024-11-08 21:45:09 +01:00
Felix Uhl c5d1a42af7 tests: Put tests with snapshots into directories
This makes the tests more readable and easier to browse.
Making sure the tests always run fine, no matter from which directory
they're started is a little detail we should either test for or
document.
2024-11-08 21:39:34 +01:00
Felix Uhl 6b360a2534 tests: Add simple tests for eval_config.py 2024-11-08 20:22:46 +01:00
Felix Uhl 963b49d314 lib: Add dict_diff
This allows to create plans only based on the things that changed in the
configuration.
2024-11-08 20:12:05 +01:00
Felix Uhl da8a997397 dev: Switch to ruff for python linting & formatting
It combines multiple tools and is much faster.
2024-11-08 20:12:05 +01:00
Felix Uhl 0d54c7ad3f disko2: Make generate write output to nix file 2024-11-08 20:12:05 +01:00
Felix Uhl fa44467f82 disko2: Refactor dev mode, add disko dev eval 2024-11-03 23:00:26 +01:00
Felix Uhl c5da562d0d dev: Move colors to constants 2024-11-03 22:53:12 +01:00
Felix Uhl a6944c6bea disko2: Make messages type-safe and modular
Using untyped dicts was not a safe way to pass arguments to error
message rendering. Also, having one giant match statement wouldn't scale
well. Using function pointers and kwargs, mypy can now properly check
whether all required arguments are passed to DiskoMessage().

As a bonus, it's now easy to use the "Go to definition" LSP command for
error codes, which wasn't possible before.
2024-11-03 22:35:06 +01:00
Felix Uhl 4db452e40a disko2: Fix entrypoints
An oversight from 389235b63f
2024-11-03 22:12:00 +01:00
Felix Uhl 0cd949092d disko2: Add test for generate_config 2024-11-03 20:59:56 +01:00
Felix Uhl fb5e63a3de dev: Add vscode settings for nixd and cSpell
Other people might use other tools, but having a known-good
configuration is useful.
2024-10-31 17:23:19 +01:00
Felix Uhl 737e045f53 tests: Move example tests to dedicated folder 2024-10-31 17:03:52 +01:00
Felix Uhl 389235b63f disko2: Create package
This requires a lot of restructuring. The .nix files have to be bundled
together with the python files, so they need to follow python's module
system structure.

I ran `nix-fast-build --no-link -j 2 --eval-workers 3 --flake .#checks`
and it succeeded, so I'm reasonably confident I changed everything as
required.
2024-10-30 23:54:41 +01:00
Felix Uhl 5da578139e disko2: Add dev subcommand 2024-10-30 20:24:00 +01:00
Felix Uhl e825c64c8d disko2: Implement rudimentary generate mode
Error handling could be done better, but I'm pretty happy with it
already.
The important part is aggregating all errors instead of failing on the
first issue we encounter.
2024-10-30 19:35:51 +01:00
Felix Uhl 8acd24950d disko2: Add evaluation for configs and flakes 2024-10-29 23:50:09 +01:00
Felix Uhl ed506048a4 dev: Add autoflake to remove unused imports automatically 2024-10-29 23:42:25 +01:00
Felix Uhl 88a85411ba disko2: Make Result generic over the value it contains
This will be essential for type safety later on.
2024-10-29 20:43:18 +01:00
Felix Uhl d4a944c327 disko2: Add --verbose,-v flag 2024-10-29 20:43:18 +01:00
Felix Uhl ffa1b89bb0 disko2: Add basic logging setup 2024-10-29 20:43:18 +01:00
Felix Uhl db29851652 dev: Add vscode launch config for disko2 2024-10-29 16:42:04 +01:00
Felix Uhl 8cf1486b17 dev: Add mypy type checker 2024-10-29 16:42:04 +01:00
Felix Uhl b752b835b6 disko2: Set up basic argument parsing 2024-10-28 22:55:47 +01:00
Felix Uhl b102aeb547 disko2: Set up dev environment for python 2024-10-28 22:44:33 +01:00
Felix Uhl 0e55423bf8 release: reset released flag 2024-10-28 18:08:12 +01:00
Felix Uhl ab58501b23 release: v1.9.0 v1.9.0 2024-10-28 18:08:12 +01:00
Paul Haerle 3163b2724c Merge pull request #851 from nix-community/fix-eval-error-unexpected-argument-customQemu
disk-image: Fix "unexpected argument 'customQemu'" eval error
2024-10-28 15:17:58 +01:00
Felix Uhl bba79f6b5e disk-image: Fix "unexpected argument 'customQemu'" eval error
Previously, an error like

    error: function 'anonymous lambda' called with unexpected argument 'customQemu'

    at /nix/store/lbqj1cndic4121whnx8xm0jgb1c8x4xx-source/pkgs/build-support/vm/default.nix:1:1:

was printed when trying to evaluate `config.system.build.vmWithDisko` or
`config.system.build.diskoImagesScript` with nixpkgs 24.05 (and below).

This argument was added in
https://github.com/NixOS/nixpkgs/commit/65c851cd7523c669b8fb25236b1c48283a2f43ec,
so technically the minimum version is 24.11.20240708.65c851c. However,
`versionAtLeast` only compares versions alphabetically, so the comparison's
result will be incorrect for other commits made on the same day.

Instead, we compare against 24.11.20240709, which is the next day.
This means this function returns false for some commits that DO support the
customQemu argument, but if it returns true, we can be 100% certain that this
is correct, and we can pass the customQemu argument to vmTools without an
evaluation error.

Fixes #850
2024-10-28 14:38:07 +01:00
iFreilichtandJörg Thalheim 89e458a3bb UX: be specific if disko-install failed or succeeded (#847)
UX: be specific if disko-install failed or succeeded

* Output success message to stdout

Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
2024-10-27 16:12:03 +00:00
DavHau 58cd832497 lvm_vg: fix size=100% leading to crash
lvcreate -l does not accept a '100%' parameter which currently leads to a crash. THis change automatically changes `100%` to `100%FREE` leading to the intended behavior.
2024-10-26 11:42:42 +00:00
phaer 09a776702b fix: avoid calling splitString ""...
because it breaks evaluation on darwin with at least nix 2.18.

Evaluating `lib.splitString "" "foo"` throws the following:
`error: invalid regular expression ''`.

We could avoid that by using lib.stringToCharacters, but as
we are mapping over it anyway, lib.stringAsChars seems to be
an even better fit.

I tested the examples in hexEscapeUdevSymlinks docstring manually
in a nix repl.
2024-10-23 19:46:38 +00:00
Felix Uhl 4be2aadf13 lib: use lib.escapeShellArg for concatenated paths 2024-10-22 09:10:08 +00:00
Felix Uhl ca47da60e5 disko: fix improper handling of whitespace
Fixes #130

This should fix pretty much all cases where spaces or other special
characters would break disko due to improper quoting. I searched for all
instances of '.label', '.device' and '.name', so I believe I caught
whatever I could.

In some cases I changed single quotes to double quotes for consistency.

I know we don't usually fix bugs in the legacy table type, but it was so
easy I couldn't resist.
2024-10-22 09:10:08 +00:00
Chris Scutcher 78d685c123 tests: Add failing test to demonstrate issues with whitespace in part names
Reproduces #130.

For new style table the generated script has a few problems for example;

```sh
    sgdisk \
      --new=2:0:+100M \
      --change-name=2:disk-vdb-name with spaces \
      --typecode=2:EF00 \
      /dev/vdb
```

and

```sh
mkfs.vfat \
         \
        /dev/disk/by-partlabel/disk-vdb-name with spaces
```

Legacy table style generates slightly different problems e.g.;

```sh
parted -s /dev/vdb -- mkpart name with spaces  1MiB 100MiB
```
2024-10-22 09:10:08 +00:00
Felix Uhl a6a3179ddf cli: stop using system dependencies in destroy step
re-applying 15aa78e9a5 because I
accidentally overwrote it in 15aa78e9a5.
2024-10-18 21:59:08 +02:00
Felix Uhl d7d57edb72 docs: Add docs for contributors
Fixes #334
2024-10-16 17:27:36 +00:00
Felix Uhl 15aa78e9a5 lib: Remove global with lib;
This is generally regarded as a code-smell. I did utilize `with lib;`
in some places where I felt it aided readability, but it's very clearly
scoped in those situations.

See https://github.com/nix-community/disko/pull/835#issuecomment-2416126497
2024-10-16 17:17:32 +00:00
Felix Uhl dcabccaad6 swap: fix partition type
Fixes #391
2024-10-16 17:05:43 +00:00
Felix Uhl c8760cee70 cli: stop using system dependencies in destroy step
Fixes #815
2024-10-16 09:22:47 +00:00
Felix Uhl 9ab6ae4e63 disko-install: make output deterministic
Fixes #827
2024-10-15 16:36:09 +00:00