Skip to content

Commit

Permalink
Merge pull request #125 from DeterminateSystems/resolve-build
Browse files Browse the repository at this point in the history
Add apply command
  • Loading branch information
grahamc authored Jul 30, 2024
2 parents 514f204 + c0060a4 commit c7efb00
Show file tree
Hide file tree
Showing 23 changed files with 779 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flakehub-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- nix-system: "x86_64-linux"
runner: "ubuntu-22.04"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/flakehub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
id-token: "write"
contents: "read"
steps:
- uses: "actions/checkout@v3"
- uses: "actions/checkout@v4"
with:
ref: "${{ (inputs.tag != null) && format('refs/tags/{0}', inputs.tag) || '' }}"
- uses: "DeterminateSystems/nix-installer-action@main"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
flake-check:
runs-on: UbuntuLatest32Cores128G
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: DeterminateSystems/flake-checker-action@main
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
id-token: write # In order to request a JWT for AWS auth
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Create the artifacts directory
run: rm -rf ./artifacts && mkdir ./artifacts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
id-token: write # In order to request a JWT for AWS auth
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Create the artifacts directory
run: rm -rf ./artifacts && mkdir ./artifacts
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
rust-fmt-and-clippy:
runs-on: UbuntuLatest32Cores128G
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@main
Expand All @@ -19,3 +19,6 @@ jobs:

- name: Clippy
run: nix develop --command cargo clippy --all-targets --all-features -- -Dwarnings

- name: Test
run: nix develop --command cargo test --all-features
101 changes: 97 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fh"
version = "0.1.13"
version = "0.1.14"
authors = ["Determinate Systems <[email protected]>"]
edition = "2021"
license = "Apache 2.0"
Expand All @@ -22,10 +22,11 @@ color-eyre = { version = "0.6.2", default-features = false, features = [
"issue-url",
] }
csv = "1.3.0"
gethostname = "0.4.3"
gethostname = { version = "0.4.3", default-features = false }
handlebars = "4.4.0"
indicatif = { version = "0.17.6", default-features = false }
inquire = "0.6.2"
nix = { version = "0.29.0", default-features = false, features = ["user"] }
nix-config-parser = "0.2.0"
nixel = "5.2.0"
once_cell = "1.18.0"
Expand All @@ -39,6 +40,7 @@ semver = { version = "1.0.18", default-features = false, features = ["serde"] }
serde = { version = "1.0.188", default-features = false, features = ["derive"] }
serde_json = "1.0.105"
tabled = { version = "0.14.0", features = ["color"] }
tempfile = "3.10.1"
thiserror = { version = "1.0.44", default-features = false }
tokio = { version = "1.30.0", default-features = false, features = ["full"] }
tracing = "0.1.37"
Expand All @@ -50,6 +52,7 @@ tracing-subscriber = { version = "0.3.17", default-features = false, features =
] }
url = { version = "2.4.0", default-features = false, features = ["serde"] }
urlencoding = "2.1.3"
whoami = { version = "1.5.1", default-features = false }
xdg = "2.5.2"

[dev-dependencies]
Expand Down
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,76 @@ nix build \
/nix/var/nix/profiles/system/bin/switch-to-configuration switch
```

### Apply configurations to the current system

The `fh apply` command enables you to apply a configuration for one of the following systems to the current host:

- [NixOS](#nixos)
- [Home Manager](#home-manager)
- [nix-darwin](#nix-darwin)

For all three systems, you only need to supply a flake output reference for the configuration and `fh` does the rest.

#### NixOS

On a [NixOS] system, you can use `fh apply nixos` to apply a configuration from an output path:

```shell
fh apply nixos "my-org/system-configs/0.1#nixosConfigurations.staging-box"
```

If you don't specify a flake output path, `fh apply nixos` defaults to `nixosConfigurations.$(hostname)`.
These two commands are thus equivalent:

```shell
fh apply nixos "my-org/system-configs/0.1#nixosConfigurations.$(hostname)"
fh apply nixos "my-org/system-configs/0.1"
```

`fh apply nixos` first resolves the supplied output reference to a store path, builds the `switch-to-configuration` script for that path, and then runs `switch-to-configuration switch` by default.
You can also supply a different command from `switch` (`boot`, `test`, or `dry-activate`).
Here's an example:

```shell
fh apply nixos "my-org/system-configs/0.1" boot
```

#### Home Manager

If you're on a system that uses [Home Manager][hm], you can use `fh apply home-manager` to apply a configuration from an output path:

```shell
fh apply home-manager "my-org/home-configs/0.1#homeConfigurations.standard-home-config"
```

If you don't specify a flake output path, `fh apply home-manager` defaults to `homeConfigurations.$(whoami)`.
These two commands are thus equivalent:

```shell
fh apply home-manager "my-org/home-configs/0.1#homeConfigurations.$(whoami)"
fh apply home-manager "my-org/home-configs/0.1"
```

`fh apply home-manager` first resolves the supplied output reference to a store path, builds the `activate` script for that path, and then runs it.

#### nix-darwin

If you're on a macOS system that uses [nix-darwin], you can use `fh apply nix-darwin` to apply a configuration from an output path:

```shell
fh apply nix-darwin "my-org/macos-configs/0.1#darwinConfigurations.justme-aarch64-darwin"
```

If you don't specify a flake output path, `fh apply nix-darwin` defaults to `darwinConfigurations.${devicename}.system`, where `devicename` is the output of `scutil --get LocalHostName`.
These two commands are thus equivalent:

```shell
fh apply nix-darwin "my-org/macos-configs/0.1#darwinConfigurations.$(scutil --get LocalHostName)"
fh apply nix-darwin "my-org/macos-configs/0.1"
```

`fh apply nix-darwin` first resolves the supplied output reference to a store path, builds the `darwin-rebuild` script for that path, and then runs `darwin-rebuild activate`.

### Searching published flakes

You can search publicly listed flakes using the `fh search` command and passing in a search query.
Expand Down Expand Up @@ -336,9 +406,11 @@ For support, email [email protected] or [join our Discord](https://discord.gg
[flakehub-push-params]: https://github.com/determinateSystems/flakehub-push?tab=readme-ov-file#available-parameters
[flakes]: https://flakehub.com/flakes
[go]: https://golang.org
[hm]: https://github.com/nix-community/home-manager
[inputs]: https://zero-to-nix.com/concepts/flakes#inputs
[java]: https://java.com
[javascript]: https://javascript.info
[nix-darwin]: https://github.com/LnL7/nix-darwin
[nix-flakes]: https://zero-to-nix.com/concepts/flakes
[nixos]: https://zero-to-nix.com/concepts/nixos
[nixpkgs]: https://zero-to-nix.com/concepts/nixpkgs
Expand Down
Loading

0 comments on commit c7efb00

Please sign in to comment.