Skip to content

Commit

Permalink
Merge pull request #123 from DeterminateSystems/fh-resolve
Browse files Browse the repository at this point in the history
Add fh resolve command
  • Loading branch information
grahamc authored Jul 11, 2024
2 parents 57851dc + 093089c commit 0da4df0
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 90 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fh"
version = "0.1.12"
version = "0.1.13"
authors = ["Determinate Systems <[email protected]>"]
edition = "2021"
license = "Apache 2.0"
Expand Down
85 changes: 67 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Using `fh` from FlakeHub:
nix shell "https://flakehub.com/f/DeterminateSystems/fh/*.tar.gz"
```

> **Note:** This builds `fh` locally on your computer.
> [!NOTE]
> This builds `fh` locally on your computer.
> Pre-built binaries aren't yet available.
## Installation
Expand Down Expand Up @@ -43,7 +44,17 @@ To make the `fh` CLI readily available on a [NixOS] system:
}
```

## Demo
## Using `fh`

You can use `fh` to:

- [Log into FlakeHub](#log-into-flakehub)
- [Initialize a new `flake.nix`](#initialize-a-new-flakenix-from-scratch)
- [Add flake inputs to your `flake.nix`](#add-a-flake-published-to-flakehub-to-your-flakenix)
- [Resolve flake references to store paths](#resolve-flake-references-to-store-paths)
- [Search FlakeHub flakes](#searching-published-flakes)
- List available [releases](#listing-releases) and [flakes, organizations, and versions](#listing-flakes-organizations-and-versions)
- List flakes by [label](#list-by-label)

### Log into FlakeHub

Expand All @@ -68,17 +79,18 @@ Respond to the prompts it provides you and at the end `fh` will write a `flake.n

`fh init` has built-in support for the following languages:

* [Elm]
* [Go]
* [Java]
* [JavaScript]
* [PHP]
* [Python]
* [Ruby]
* [Rust]
* [Zig]

> **Note**: `fh init` operates on a best-guess basis and is opinionated in its suggestions.
- [Elm]
- [Go]
- [Java]
- [JavaScript]
- [PHP]
- [Python]
- [Ruby]
- [Rust]
- [Zig]

> [!NOTE]
> The `fh init` command operates on a best-guess basis and is opinionated in its suggestions.
> It's intended less as a comprehensive flake creation solution and more as a helpful kickstarter.
### Add a flake published to FlakeHub to your `flake.nix`
Expand All @@ -104,6 +116,41 @@ The resulting `flake.nix` would look something like this:
}
```

### Resolve flake references to store paths

You can resolve flake references on FlakeHub to Nix store paths using the `fh resolve` command:

```shell
fh resolve "omnicorp/devtools/0.1.0#packages.x86_64-linux.cli"
/nix/store/1ab797rfbdcjzissxrsf25rqy0l8mksq-cli-0.1.0
```

You can only use `fh resolve` with flake releases for which [`include-output-paths`][flakehub-push-params] has been set to `true`.
Here's an example [flakehub-push] configuration:

```yaml
- name: Publish to FlakeHub
uses: determinatesystems/flakehub-push@main
with:
visibility: "public" # or "unlisted" or "private"
include-output-paths: true
```
The `fh resolve` command is most useful when used in conjunction with [FlakeHub Cache][cache].
If the cache is enabled on the flake and the current Nix user is [logged into FlakeHub](#log-into-flakehub), then resolved store paths are also available to Nix.
Under those conditions, you can, for example, apply a NixOS configuration published to FlakeHub:

```shell
# Build the derivation
nix build \
--max-jobs 0 \
--profile /nix/var/nix/profiles/system \
$(fh resolve "my-org/my-nixos-configs#nixosConfigurations.my-dev-workstation")
# Apply the configuration
/nix/var/nix/profiles/system/bin/switch-to-configuration switch
```

### Searching published flakes

You can search publicly listed flakes using the `fh search` command and passing in a search query.
Expand Down Expand Up @@ -258,11 +305,11 @@ fh completion bash

These shells are supported:

* [Bash]
* [Elvish]
* [Fish]
* [Powershell]
* [zsh]
- [Bash]
- [Elvish]
- [Fish]
- [Powershell]
- [zsh]

## A note on automation

Expand All @@ -285,6 +332,8 @@ For support, email [email protected] or [join our Discord](https://discord.gg
[elvish]: https://elv.sh
[fish]: https://fishshell.com
[flakehub]: https://flakehub.com
[flakehub-push]: https://github.com/determinateSystems/flakehub-push
[flakehub-push-params]: https://github.com/determinateSystems/flakehub-push?tab=readme-ov-file#available-parameters
[flakes]: https://flakehub.com/flakes
[go]: https://golang.org
[inputs]: https://zero-to-nix.com/concepts/flakes#inputs
Expand Down
39 changes: 21 additions & 18 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@
src = self;

doCheck = true;
SSL_CERT_FILE = "${final.cacert}/etc/ssl/certs/ca-bundle.crt";

LIBCLANG_PATH = "${final.libclang.lib}/lib";
NIX_CFLAGS_COMPILE = final.lib.optionalString final.stdenv.isDarwin "-I${final.libcxx.dev}/include/c++/v1";

nativeBuildInputs = with final; [
pkg-config
Expand All @@ -88,35 +84,42 @@
--zsh <("$out/bin/fh" completion zsh) \
--fish <("$out/bin/fh" completion fish)
'';

env = {
SSL_CERT_FILE = "${final.cacert}/etc/ssl/certs/ca-bundle.crt";
LIBCLANG_PATH = "${final.libclang.lib}/lib";
NIX_CFLAGS_COMPILE = final.lib.optionalString final.stdenv.isDarwin "-I${final.libcxx.dev}/include/c++/v1";
};
};
};

packages = forAllSystems ({ system, pkgs, ... }: rec {
packages = forAllSystems ({ system, pkgs }: rec {
inherit (pkgs) fh;
default = pkgs.fh;
});

devShells = forAllSystems ({ system, pkgs, ... }:
devShells = forAllSystems ({ system, pkgs }:
{
default = pkgs.mkShell {
name = "dev";

LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
NIX_CFLAGS_COMPILE = pkgs.lib.optionalString pkgs.stdenv.isDarwin "-I${pkgs.libcxx.dev}/include/c++/v1";

nativeBuildInputs = with pkgs; [ pkg-config clang ];
buildInputs = with pkgs; [
(fenixToolchain stdenv.hostPlatform.system)
packages = with pkgs; [
(fenixToolchain system)
cargo-watch
rust-analyzer
nixpkgs-fmt

# For the Rust environment
pkg-config
clang
gcc.cc.lib
]
++ lib.optionals (stdenv.isDarwin) (with darwin.apple_sdk.frameworks; [
libiconv
++ lib.optionals (stdenv.isDarwin) ([ libiconv ] ++ (with darwin.apple_sdk.frameworks; [
Security
SystemConfiguration
]);
]));

env = {
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
NIX_CFLAGS_COMPILE = pkgs.lib.optionalString pkgs.stdenv.isDarwin "-I${pkgs.libcxx.dev}/include/c++/v1";
};
};
});
};
Expand Down
7 changes: 5 additions & 2 deletions src/cli/cmd/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use std::{
use url::Url;

use crate::{
cli::cmd::{init::handlers::Elm, list::FLAKEHUB_WEB_ROOT},
cli::{
cmd::{init::handlers::Elm, list::FLAKEHUB_WEB_ROOT},
error::FhError,
},
flakehub_url,
};

Expand All @@ -32,7 +35,7 @@ use self::{
template::TemplateData,
};

use super::{CommandExecute, FhError};
use super::CommandExecute;

// Nixpkgs references
const NIXPKGS_LATEST: &str = "latest stable (currently 24.05)";
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd/init/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use handlebars::Handlebars;
use serde::Serialize;
use serde_json::Value;

use crate::cli::cmd::FhError;
use crate::cli::error::FhError;

use super::{dev_shell::DevShell, handlers::Input};

Expand Down
7 changes: 5 additions & 2 deletions src/cli/cmd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ use std::process::ExitCode;
use tabled::{Table, Tabled};
use url::Url;

use super::{print_json, FhError};
use super::print_json;
use crate::{
cli::cmd::{FlakeHubClient, DEFAULT_STYLE},
cli::{
cmd::{FlakeHubClient, DEFAULT_STYLE},
error::FhError,
},
flakehub_url,
};

Expand Down
3 changes: 2 additions & 1 deletion src/cli/cmd/login/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use clap::Parser;
use tokio::io::AsyncWriteExt;

use crate::cli::cmd::FlakeHubClient;
use crate::cli::error::FhError;

use super::{CommandExecute, FhError};
use super::CommandExecute;

const CACHE_PUBLIC_KEYS: &[&str; 2] = &[
"cache.flakehub.com-1:t6986ugxCA+d/ZF9IeMzJkyqi5mDhvFIx7KA/ipulzE=",
Expand Down
Loading

0 comments on commit 0da4df0

Please sign in to comment.