Skip to content

Commit

Permalink
Merge pull request #144 from DeterminateSystems/revert-143-revert-140…
Browse files Browse the repository at this point in the history
…-fix-macos-build

Revert "Revert "Fix macOS build""
  • Loading branch information
lucperkins authored Jun 27, 2024
2 parents ace2c95 + c5785ba commit 09afa27
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 84 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: DeterminateSystems/flake-checker-action@main

- uses: DeterminateSystems/nix-installer-action@main

- uses: DeterminateSystems/magic-nix-cache-action@main

- uses: DeterminateSystems/flake-checker-action@main

- name: "Nix formatting"
run: git ls-files '*.nix' | nix develop --command xargs nixpkgs-fmt --check

Expand All @@ -32,7 +32,7 @@ jobs:
run: nix develop --command cargo clippy --all-targets --all-features -- -Dwarnings

- name: "Nix Flake Check"
run: nix flake check --print-build-logs
run: nix flake check --all-systems --print-build-logs

- name: Build package
run: "nix build .# -L --fallback"
Expand All @@ -44,3 +44,23 @@ jobs:
name: flakehub-push-X64-Linux
path: result/bin/flakehub-push
retention-days: 1

# For local development purposes
build-artifacts-macos:
runs-on: ${{ matrix.systems.runner }}
strategy:
matrix:
systems:
- nix-system: aarch64-darwin
runner: macos-latest-xlarge
- nix-system: x86_64-darwin
runner: macos-12
steps:
- uses: actions/checkout@v3

- uses: DeterminateSystems/nix-installer-action@main

- uses: DeterminateSystems/magic-nix-cache-action@main

- name: Build package
run: "nix build .# -L --fallback"
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/dist
/src
pnpm-lock.yaml
flake.lock
101 changes: 47 additions & 54 deletions flake.lock

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

58 changes: 33 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
url = "https://flakehub.com/f/ipetkov/crane/0.14.1.tar.gz";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
fenix = {
url = "https://flakehub.com/f/nix-community/fenix/0.1.1885.tar.gz";
inputs.nixpkgs.follows = "nixpkgs";
};
};
Expand All @@ -24,42 +24,50 @@
inherit system;
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.self.overlays.default
inputs.rust-overlay.overlays.default
];
overlays = [ inputs.self.overlays.default ];
};
lib = pkgs.lib;
});
in
{
overlays.default = final: prev: {
overlays.default = final: prev: rec {
system = final.stdenv.hostPlatform.system;

rustToolchain = with inputs.fenix.packages.${system};
combine ([
stable.clippy
stable.rustc
stable.cargo
stable.rustfmt
stable.rust-src
] ++ final.lib.optionals (system == "x86_64-linux") [
targets.x86_64-unknown-linux-musl.stable.rust-std
] ++ final.lib.optionals (system == "aarch64-linux") [
targets.aarch64-unknown-linux-musl.stable.rust-std
]);

craneLib = (inputs.crane.mkLib final).overrideToolchain rustToolchain;

flakehub-push = inputs.self.packages.${final.stdenv.system}.flakehub-push;
};

packages = forAllSystems ({ system, pkgs, lib, ... }:
let
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
targets = [ "x86_64-unknown-linux-musl" ];
};
in
rec {
default = flakehub-push;
packages = forAllSystems ({ system, pkgs, ... }: rec {
default = flakehub-push;

flakehub-push = craneLib.buildPackage {
flakehub-push = pkgs.craneLib.buildPackage
({
pname = "flakehub-push";
version = "0.1.0";
src = craneLib.path ./.;
src = pkgs.craneLib.path ./.;

CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";

buildInputs = lib.optionals (pkgs.stdenv.isDarwin) (with pkgs; [
buildInputs = pkgs.lib.optionals (pkgs.stdenv.isDarwin) (with pkgs; [
libiconv
darwin.apple_sdk.frameworks.SystemConfiguration
]);
};
});
} // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
});
});

devShells = forAllSystems ({ system, pkgs, ... }: {
default = pkgs.mkShell {
Expand Down
11 changes: 9 additions & 2 deletions src/flake_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ impl FlakeMetadata {
.prefix("flakehub_push_outputs")
.tempdir()
.wrap_err("Creating tempdir")?;
// NOTE(cole-h): Work around the fact that macOS's /tmp is a symlink to /private/tmp.
// Otherwise, Nix is unhappy:
// error:
// … while fetching the input 'path:/tmp/nix-shell.q1H8OB/flakehub_push_outputsfG1YvC'
//
// error: path '/tmp' is a symlink
let tempdir_path = tempdir.path().canonicalize()?;

let flake_contents = include_str!("mixed-flake.nix")
.replace(
Expand All @@ -264,14 +271,14 @@ impl FlakeMetadata {
},
);

let mut flake = tokio::fs::File::create(tempdir.path().join("flake.nix")).await?;
let mut flake = tokio::fs::File::create(tempdir_path.join("flake.nix")).await?;
flake.write_all(flake_contents.as_bytes()).await?;

let mut cmd = tokio::process::Command::new("nix");
cmd.arg("eval");
cmd.arg("--json");
cmd.arg("--no-write-lock-file");
cmd.arg(format!("{}#contents", tempdir.path().display()));
cmd.arg(format!("{}#contents", tempdir_path.display()));
let output = cmd.output().await.wrap_err_with(|| {
eyre!(
"Failed to get flake outputs from tarball {}",
Expand Down

0 comments on commit 09afa27

Please sign in to comment.