Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: port from zig to go #50

Draft
wants to merge 99 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
8bc187b
feat: say hello to golang, farewell zig
water-sucks Dec 21, 2024
97324da
build: add compile-time variables and use makefile
water-sucks Dec 29, 2024
dd5fde2
feat: use cobra instead of urfave/cli
water-sucks Jan 1, 2025
33216a0
feat: add aliases cmd
water-sucks Jan 1, 2025
5215491
feat: add apply cmd
water-sucks Jan 1, 2025
de42ed1
feat: add enter cmd
water-sucks Jan 1, 2025
9f54d26
feat: add features cmd
water-sucks Jan 1, 2025
ab8e59b
refactor: put subcommands into separate packages
water-sucks Jan 1, 2025
ac6e994
refactor: use separate package for storing option types
water-sucks Jan 1, 2025
2cefb37
fix: use reference for setting help text
water-sucks Jan 1, 2025
24ad22b
feat: add generation cmd and subcommands
water-sucks Jan 1, 2025
50e0f7c
feat: add info cmd
water-sucks Jan 1, 2025
afdbc49
feat: add init cmd
water-sucks Jan 1, 2025
21bfdf4
fix(apply): only show flake arg in help when flake=true
water-sucks Jan 1, 2025
87124f8
feat: add install cmd
water-sucks Jan 2, 2025
2192f44
feat: add manual cmd
water-sucks Jan 3, 2025
b87e356
feat: add option cmd
water-sucks Jan 3, 2025
5fb07b6
feat: add repl cmd
water-sucks Jan 3, 2025
4f997c8
feat(delete): parse systemd.time(7) strings
water-sucks Jan 4, 2025
cbdff51
fix: make root cmd flags persistent, hide globals from help
water-sucks Jan 6, 2025
49166e5
feat: add minimal logger to command context
water-sucks Jan 6, 2025
a6064ea
feat: create/parse config struct, add to cmd context
water-sucks Jan 7, 2025
c2c76f2
feat: wire up --config flag to set config values dynamically
water-sucks Jan 7, 2025
d0de0da
fix(build): remove shorthands for persistent flags, update hash
water-sucks Jan 8, 2025
67137c4
feat: add completion for --config flag
water-sucks Jan 8, 2025
3a799bf
fix(config): handle color settings properly
water-sucks Jan 8, 2025
1373e66
feat(config): add descriptions for --config flag completion
water-sucks Jan 9, 2025
c4db68b
docs: add progress, some notes about rewrite
water-sucks Jan 9, 2025
df03e77
ci: update build/test action to use makefile
water-sucks Jan 9, 2025
01ac001
fix(nix): use clean rev for package if it exists
water-sucks Jan 9, 2025
5c1b2df
feat(features): print out actual features
water-sucks Jan 9, 2025
8419fb6
feat(aliases): print out actual aliases
water-sucks Jan 9, 2025
077db8f
fix(apply): respect apply.imply_impure_with_tag
water-sucks Jan 9, 2025
865310d
feat(completion): add alias command-line completion support
water-sucks Jan 12, 2025
91d16d3
feat(aliases): display in main --help as a command group, remove subc…
water-sucks Jan 12, 2025
d5d5f41
feat(features): add detected nix version to features
water-sucks Jan 12, 2025
af52004
fix: force-exit when a error is returned to prevent duplicate messages
water-sucks Jan 13, 2025
e47a11d
feat(apply): re-exec as root if needed
water-sucks Jan 13, 2025
008aae0
fix(log): make log colors more consistent
water-sucks Jan 13, 2025
1c475e7
feat(apply): find config dir and switch to it
water-sucks Jan 16, 2025
eaefb35
feat(apply): check if nix-output-monitor if available
water-sucks Jan 16, 2025
5af1fb4
refactor: move configuration utils to package
water-sucks Jan 17, 2025
cd670c0
feat: add nix options command-line arguments serializer
water-sucks Jan 17, 2025
0e2db3e
feat(apply): build configurations
water-sucks Jan 17, 2025
a63d8b9
feat(apply): show diff between generations
water-sucks Jan 18, 2025
9700412
feat(apply): perform NixOS check
water-sucks Jan 18, 2025
371984e
feat(apply): ask for confirmation before activating
water-sucks Jan 18, 2025
79d7f4f
feat(apply): upgrade channels if required
water-sucks Jan 18, 2025
a7e418e
fix: disable cgo
water-sucks Jan 18, 2025
963603e
fix(config): remove pointer indirection
water-sucks Jan 18, 2025
9d465ac
fix(apply): use correct attribute for legacy system toplevel
water-sucks Jan 18, 2025
fd75c52
fix(apply): add log step for channel update
water-sucks Jan 18, 2025
8ff8d55
feat(apply): set nix-env profile and run switch-to-configuration.pl
water-sucks Jan 19, 2025
879d052
feat(apply): find latest git commit message
water-sucks Jan 19, 2025
c1d196a
fix(apply): use correct output location for relative output location
water-sucks Jan 19, 2025
d1db05a
fix(apply): only use output location if non-empty
water-sucks Jan 19, 2025
07d3e29
fix: convert map keys in lexical string order
water-sucks Jan 19, 2025
8a52bbb
feat: add charmbracelet tui dependencies
water-sucks Jan 20, 2025
40139f8
feat(generation): implement list command with table, json output
water-sucks Jan 20, 2025
0e45681
feat(generation): show interactive list of generations
water-sucks Jan 22, 2025
b008b59
feat(apply): respect specialisation flag and defaults
water-sucks Jan 22, 2025
747ebf3
feat(generation): implement switch command
water-sucks Jan 24, 2025
fef708d
feat(generation): add current indicator for list, reverse list order
water-sucks Jan 24, 2025
3345df0
fix: go mod tidy up indirect deps
water-sucks Jan 24, 2025
74ef30e
fix(generation): pass rollback variable explicitly
water-sucks Jan 24, 2025
011bec5
feat(generation): add rollback command impl
water-sucks Jan 24, 2025
60bafd8
feat(generation): implement diff command
water-sucks Jan 25, 2025
46bdd79
feat(generation): add switch, delete actions to tui
water-sucks Jan 26, 2025
098c30e
fix(apply): set profiles explicitly instead of relying on --rollback
water-sucks Jan 26, 2025
fde78b0
feat(info): implement info cmd
water-sucks Jan 27, 2025
940a9eb
feat(generation): add --profile completion
water-sucks Jan 27, 2025
f79c4ab
feat(generation): implement completion for generation numbers
water-sucks Jan 27, 2025
a7769b5
feat(enter): implement enter cmd
water-sucks Jan 28, 2025
fd741fe
feat(repl): implement repl cmd
water-sucks Jan 30, 2025
20da952
ci: remove magic nix cache
water-sucks Feb 1, 2025
05a0d51
refactor(configuration): use "union" to differentiate legacy vs. flak…
water-sucks Feb 3, 2025
e0e2897
feat(option): add initial option impl with raw search query
water-sucks Feb 3, 2025
8528b28
feat(option): render markdown with glamour
water-sucks Feb 3, 2025
e7f4fe0
feat(option): fuzzy search for options that don't exist
water-sucks Feb 3, 2025
50df7f2
feat(option): evaluate value and show when possible
water-sucks Feb 3, 2025
54ff789
feat(option): oopsies i fucked up not trimming strings
water-sucks Feb 3, 2025
1e9e2f2
docs: oops, forgot to update todo list
water-sucks Feb 3, 2025
230c8f7
feat(option): add basic completion
water-sucks Feb 3, 2025
c044fa4
refactor(option): use min_score instead of max_rank
water-sucks Feb 7, 2025
7208290
feat(option): respect option.min_score setting, add command line swit…
water-sucks Feb 7, 2025
866567e
feat(init): add templates, write them to files
water-sucks Feb 7, 2025
7b98dac
feat(init): generate the easy stuff and format strings
water-sucks Feb 8, 2025
4e2087f
feat(init): find PCI and USB devices
water-sucks Feb 12, 2025
239caa9
feat(init): detect block/mmc devices, network interfaces
water-sucks Feb 12, 2025
5b333e9
feat(init): detect bcachefs and LVM devices
water-sucks Feb 12, 2025
43602c5
feat(init): detect swap devices
water-sucks Feb 13, 2025
76b3c6a
feat(init): generate filesystems if necessary
water-sucks Feb 17, 2025
5c13626
fix: change incorrect "package cmd" decls to correct package names
water-sucks Feb 18, 2025
762238d
feat(manual): implement manual cmd
water-sucks Feb 18, 2025
82a0361
refactor: move option evaluation to configuration
water-sucks Feb 21, 2025
803d94b
fix(module): expose module and packages through default.nix
water-sucks Feb 22, 2025
3e6af52
docs: update legacy install instructions, TODOs, and sample config
water-sucks Feb 22, 2025
0f2b0d9
refactor: change "config" -> settings
water-sucks Feb 22, 2025
9af0b7e
fix: differentiate between zero-valued and unset nix options
water-sucks Feb 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ jobs:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

- name: Use magic Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v2

- name: Check for compile errors
run: |
nix develop .# -c zig build check
nix develop .# -c zig build -Dflake=false check
nix develop .# -c make
nix develop .# -c make FLAKE=false

- name: Run tests
run: nix develop .# -c zig build test
run: nix develop .# -c make test

- name: Build Nix packages
run: nix build .#{nixos,nixosLegacy}
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
result
zig-out
zig-cache
.zig-cache
.direnv
# Nix/direnv
/result
/.direnv/

# Binary destination from `make`
/nixos
75 changes: 0 additions & 75 deletions GAMEPLAN.md

This file was deleted.

34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
APP_NAME := nixos
BUILD_VAR_PKG := github.com/water-sucks/nixos/internal/build

VERSION ?= $(shell git describe --tags --always)
COMMIT_HASH ?= $(shell git rev-parse HEAD)

# Configurable parameters
FLAKE ?= true
NIXPKGS_REVISION ?= 24.11

LDFLAGS := -X $(BUILD_VAR_PKG).Version=$(VERSION)
LDFLAGS += -X $(BUILD_VAR_PKG).GitRevision=$(COMMIT_HASH)
LDFLAGS += -X $(BUILD_VAR_PKG).Flake=$(FLAKE)
LDFLAGS += -X $(BUILD_VAR_PKG).NixpkgsVersion=$(NIXPKGS_REVISION)

# Disable CGO by default. This should be a static executable.
CGO_ENABLED ?= 0

all: build

.PHONY: build
build:
@echo "building $(APP_NAME)..."
CGO_ENABLED=$(CGO_ENABLED) go build -o ./$(APP_NAME) -ldflags="$(LDFLAGS)" .

.PHONY: clean
clean:
@echo "cleaning up..."
go clean

.PHONY: test
test:
@echo "running tests..."
CGO_ENABLED=$(CGO_ENABLED) go test ./...
119 changes: 60 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
<tr>
<td>🚨</td>
<td>
This project will be undergoing a rewrite to make it more feasible to
<p>
This project is undergoing a rewrite to make it more feasible to
work on certain features, and also to make development time faster.
If you want to use this rewrite early, point to the
<a href="https://github.com/water-sucks/nixos/tree/rewrite">
<code>rewrite</code>
</a> branch.
The rewrite is here, but will be missing many features as I am rewriting
them. Use the `main` branch if you are not willing to put up with this.
</p>
<p>
The rewrite will also bring some substantial UX improvements, and
hopefully some new things on the roadmap. Stay tuned!
hopefully some new things on the roadmap. Check the [TODO](#todo)
section for a list of things that this rewrite will bring.
</p>
</td>
</tr>
Expand Down Expand Up @@ -64,7 +65,42 @@ the recommended way to use this program.
}
```

### Cache
## Legacy

This is primarily a flake-oriented package, since flakes are the future, at
least as far as can be seen. However, legacy configurations managed with
`nix-channel` and a `configuration.nix`, or any other preferred methods such
as `niv` and `npins` are maintained here as well, albeit they are a little
harder to use. The `nixos-cli` package that manages legacy configurations is
completely separated from the flake-enabled `nixos-cli`, as to not mix usage
between the two and separate concerns.

To use the NixOS module in legacy mode, import the `default.nix` provided in
this repository. An example is provided below with `fetchTarball`:

```nix
{ config, system, pkgs, ...}:

let
# Make sure to specify the full Git revision to fetch in pure evaluation mode,
# rather than using a branch.
nixos-cli = import "${builtins.fetchTarball "github:water-sucks/nixos/archive/GITREVORBRANCHDEADBEEFDEADBEEF0000.tar.gz}" {inherit pkgs;};
in {
imports = [
nixos-cli.module
];

services.nixos-cli = {
enable = true;
package = nixos-cli.nixosLegacy;
# Other configuration for nixos-cli
};

# ... rest of config
}
```

## Cache

There is a Cachix cache available. Add the following to your NixOS configuration
to avoid lengthy rebuilds and fetching extra build-time dependencies:
Expand Down Expand Up @@ -105,44 +141,6 @@ though, as this is a fairly undocumented feature!):
}
```

## Legacy

This is primarily a flake-oriented package, since flakes are the future, at
least as far as can be seen. However, legacy configurations managed with
`nix-channel` and a `configuration.nix` are maintained here as well, albeit they
are a little harder to use. The `nixos-cli` package that manages legacy
configurations is completely separated from the flake-enabled `nixos-cli`, as
to not mix usage between the two and separate concerns. In order to use the
NixOS module, one must add the following to `configuration.nix` (or wherever
`imports` are specified) in order to use the NixOS module properly:

```nix
{ config, system, pkgs, ...}:

let
# Make sure to specify the git revision to fetch the flake in pure eval mode.
nixos-cli = builtins.getFlake "github:water-sucks/nixos/GITREVDEADBEEFDEADBEEF0000";
in {
imports = [
(nixos-cli).nixosModules.nixos-cli
];

services.nixos-cli = {
enable = true;
package = nixos-cli.packages.${pkgs.system}.nixosLegacy;
# Other configuration for nixos-cli
};

nix.settings.extra-experimental-features = ["flakes"];

# ... rest of config
}
```

Note that this does involve flakes to be an enabled feature. If this is a
deal-breaker for some reason, then please file an issue; legacy configurations
are actively supported.

## Configuration

This can be configured using the NixOS module (the preferred way), which
Expand All @@ -154,32 +152,35 @@ configuration is located in [`config.sample.toml`](./config.sample.toml).

## TODO

### Implemented Commands/Flags
Checklist of what needs to happen before this rewrite can be merged back into
`main` and released (in order):

- ➖ `apply`
- ❌ `container`
- ✅ `enter`
- ✅ `info`
- ✅ `init`
- ➖ `install`
- ✅ Remove Zig/replace with Go application
- ✅ Setup CLI interface
- ✅ Setup basic completions
- ✅ Setup config
- ✅ Setup logging
- ✅ `apply`
- ✅ `generation`
- ✅ `list`
- ✅ `switch`
- ✅ `rollback`
- ✅ `delete`
- ✅ `diff`
- ✅ `manual`
- ✅ `option`
- ✅ `info`
- ✅ `enter`
- ✅ `repl`
- 🚧 `option`
- ✅ `init`
- ❌ `install`
- ✅ `manual`

### Roadmap
### Roadmap (for after rewrite)

- ❌ CLI completion
- ❌ Documentation (via man pages)
- ✅ Options search (a la https://search.nixos.org)
- ❌ Remote installation (a la [`nixos-anywhere`](https;//github.com/numtide/nixos-anywhere))
- ❌ Remote application of configurations
- ❌ Container management (Maybe? This is lower priority.)
- ❌ Remote installation (a la [`nixos-anywhere`](https;//github.com/numtide/nixos-anywhere))
- ❌ Container management (a la `nixos-container`, lower priority)

Check the [issues](https://github.com/water-sucks/nixos/issues) page for more on
this; this is just a high-level overview.
Expand Down
Loading