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

nix via inputs and bump to 1.21 #101

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 10 additions & 38 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,28 @@ jobs:
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: cache
uses: FrancisRussell/[email protected]
with:
command: cache
- name: toolchain
uses: FrancisRussell/[email protected]
with:
command: install-rustup
toolchain: stable
- name: install Nix
uses: cachix/install-nix-action@v23
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: test
uses: FrancisRussell/[email protected]
with:
command: cargo test
run: nix develop --command cargo test

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: cache
uses: FrancisRussell/[email protected]
with:
command: cache
- name: toolchain
uses: FrancisRussell/[email protected]
with:
command: install-rustup
toolchain: stable
components: clippy
- name: test
uses: FrancisRussell/[email protected]
with:
command: cargo clippy
args: --all-targets -- --deny warnings
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: clippy
run: nix develop --command cargo clippy --all-targets -- --deny warnings

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: toolchain
uses: FrancisRussell/[email protected]
with:
command: install-rustup
toolchain: stable
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: fmt
uses: FrancisRussell/[email protected]
with:
command: cargo fmt
args: --check
run: nix develop --command cargo fmt --check

release:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
Expand Down
73 changes: 73 additions & 0 deletions flake.lock

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

7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
inputs.fenix.url = "github:nix-community/fenix";
inputs.flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.nix.url = "github:NixOS/nix/latest-release";

outputs = {
self,
crane,
fenix,
flake-compat,
flake-utils,
nix,
nixpkgs,
}: let
inherit (nixpkgs.lib) optional;
Expand All @@ -21,6 +24,7 @@
pkgs = nixpkgs.legacyPackages.${system};
toolchain = fenix.packages.${system}.stable.completeToolchain;
craneLib = crane.lib.${system}.overrideToolchain toolchain;
NIX_CMD_PATH = "${nix.packages.${system}.nix}/bin/nix";

commonArgs = {
src = craneLib.cleanCargoSource (craneLib.path ./.);
Expand All @@ -32,7 +36,7 @@
packages.default = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
inherit cargoArtifacts NIX_CMD_PATH;
nativeCheckInputs = [pkgs.nix];
# 1. integration tests execute `nix`, which fails creating `/nix/var`
# 2. integration tests require `/dev/ptmx`
Expand All @@ -41,6 +45,7 @@
);

devShells.default = craneLib.devShell {
inherit NIX_CMD_PATH;
inputsFrom = [self.packages.${system}.default];
packages = [
toolchain
Expand Down
18 changes: 2 additions & 16 deletions src/app/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl State {
acc.push(ch.into());
let string = String::from_utf8(strip_ansi_escapes::strip(acc)?)?;

if string == "nix-repl> " {
if string.ends_with("nix-repl> ") {
session_live.expecting = ReplSessionExpecting::Nothing;
self.next_query(&id)?
} else {
Expand All @@ -158,7 +158,7 @@ impl State {
expected_result: expected_result.clone(),
}
} else {
ReplSessionExpecting::BlankLine { saw_cr: false }
ReplSessionExpecting::Prompt(String::new())
};
vec![]
} else {
Expand Down Expand Up @@ -188,20 +188,6 @@ impl State {
session_live.expecting = ReplSessionExpecting::Prompt(String::new());
vec![]
}
ReplSessionExpecting::BlankLine { saw_cr: false } => {
anyhow::ensure!(
ch == b'\r',
"expecting carriage return, got {:?}",
ch as char,
);
session_live.expecting = ReplSessionExpecting::BlankLine { saw_cr: true };
vec![]
}
ReplSessionExpecting::BlankLine { saw_cr: true } => {
anyhow::ensure!(ch == b'\n', "expecting line feed, got {:?}", ch as char,);
session_live.expecting = ReplSessionExpecting::Prompt(String::new());
vec![]
}
};

Ok(output)
Expand Down
3 changes: 0 additions & 3 deletions src/app/state/repl_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ pub(crate) enum ReplSessionExpecting {
acc: String,
expected_result: ExpectedResult,
},
BlankLine {
saw_cr: bool,
},
}

impl ReplSessionLive {
Expand Down
8 changes: 2 additions & 6 deletions src/expression/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub(crate) struct ExpressionDriver {
ExampleId,
futures::future::LocalBoxFuture<'static, std::io::Result<std::process::Output>>,
)>,
nix_path: camino::Utf8PathBuf,
}

#[derive(Debug)]
Expand All @@ -23,16 +22,13 @@ pub(crate) enum ExpressionEvent {
}

impl ExpressionDriver {
pub(crate) fn new(
nix_path: camino::Utf8PathBuf,
) -> (
pub(crate) fn new() -> (
Self,
futures::stream::LocalBoxStream<'static, ExpressionEvent>,
) {
let (sender, receiver) = futures::channel::mpsc::unbounded();
let driver = Self {
sender,
nix_path,
nix_processes: Vec::new(),
};
(driver, receiver.boxed_local())
Expand Down Expand Up @@ -75,7 +71,7 @@ impl ExpressionDriver {
}

async fn spawn_nix(&mut self, example: ExpressionExample) {
let task = tokio::process::Command::new(&self.nix_path)
let task = tokio::process::Command::new(env!("NIX_CMD_PATH"))
.args(["eval", "--expr"])
.arg(example.expression)
.output();
Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ use crate::{
#[derive(Debug, clap::Parser)]
#[command(version, about)]
struct Cli {
/// Path to a `nix` executable
nix_path: camino::Utf8PathBuf,
/// pattern (`glob` crate) of markdown filespaths
sources: String,
}
Expand All @@ -35,8 +33,8 @@ async fn main() -> anyhow::Result<()> {
if examples.is_empty() {
anyhow::bail!("could not find any examples");
}
let (repl_driver, repl_events) = ReplDriver::new(cli.nix_path.clone());
let (expression_driver, expression_events) = ExpressionDriver::new(cli.nix_path);
let (repl_driver, repl_events) = ReplDriver::new();
let (expression_driver, expression_events) = ExpressionDriver::new();
let (eprintln_driver, eprintln_events) = EprintlnDriver::new();

let inputs = Inputs {
Expand Down
8 changes: 2 additions & 6 deletions src/repl/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,14 @@ pub(crate) enum ReplEvent {
pub(crate) struct ReplDriver {
sessions: std::collections::BTreeMap<ExampleId, (pty_process::Pty, tokio::process::Child)>,
sender: futures::channel::mpsc::UnboundedSender<ReplEvent>,
nix_path: camino::Utf8PathBuf,
}

impl ReplDriver {
pub(crate) fn new(
nix_path: camino::Utf8PathBuf,
) -> (Self, futures::stream::LocalBoxStream<'static, ReplEvent>) {
pub(crate) fn new() -> (Self, futures::stream::LocalBoxStream<'static, ReplEvent>) {
let (sender, receiver) = futures::channel::mpsc::unbounded::<ReplEvent>();
let driver = Self {
sessions: Default::default(),
sender,
nix_path,
};
(driver, receiver.boxed_local())
}
Expand Down Expand Up @@ -140,7 +136,7 @@ impl ReplDriver {
}
};

let child = pty_process::Command::new(&self.nix_path)
let child = pty_process::Command::new(env!("NIX_CMD_PATH"))
.args(["repl", "--quiet"])
.spawn(&pts);

Expand Down
9 changes: 7 additions & 2 deletions tests/expression.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod util;

use std::os::unix::fs::PermissionsExt;

use assert_fs::fixture::FileWriteStr;
use indoc::indoc;
use predicates::{
Expand Down Expand Up @@ -59,14 +61,17 @@ fn io_error() {
"})
.unwrap();

let mut perms = file.metadata().unwrap().permissions();
perms.set_mode(0o000);
std::fs::set_permissions(&file, perms).unwrap();

let mut eelco = assert_cmd::Command::cargo_bin("eelco").unwrap();

eelco.arg("brix");
eelco.arg(file.as_os_str());

eelco
.assert()
.failure()
.stderr("Error: No such file or directory (os error 2)\n");
.stderr(predicates::str::starts_with("Error: "));
});
}
1 change: 0 additions & 1 deletion tests/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub fn with_eelco(f: impl FnOnce(&mut NamedTempFile, &mut assert_cmd::Command))
let mut tmpfile = NamedTempFile::new("we-dont-particularly-mind.md").unwrap();
let mut command = assert_cmd::Command::cargo_bin("eelco").unwrap();

command.arg("nix");
command.arg(tmpfile.as_os_str());
f(&mut tmpfile, &mut command);
drop(tmpfile);
Expand Down