Skip to content

Commit

Permalink
Clean up flake.nix (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
bloxx12 authored Nov 9, 2024
1 parent d9cc856 commit d19a8ef
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 93 deletions.
22 changes: 2 additions & 20 deletions flake.lock

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

106 changes: 33 additions & 73 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,46 @@
description = "Steel";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # We want to use packages from the binary cache
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default";
};

outputs = {
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
fs = pkgs.lib.fileset;
systems,
}: let
eachSystem = nixpkgs.lib.genAttrs (import systems);
pkgsFor = nixpkgs.legacyPackages;
in {
packages = eachSystem (system: {
default = self.packages.${system}.steel;
steel = pkgsFor.${system}.callPackage ./nix/package.nix {
inherit (pkgsFor.${system}.darwin.apple_sdk.frameworks) Security;
};
});

formatter = eachSystem (system: pkgsFor.${system}.alejandra);

# DEPRECATED
legacyPackages = self.packages;
defaultPackage = eachSystem (system: self.packages.${system}.default);

manifest = pkgs.lib.importTOML ./Cargo.toml;
steel = with pkgs;
rustPlatform.buildRustPackage {
pname = manifest.package.name;
version = manifest.workspace.package.version;
src = fs.toSource {
root = ./.;
fileset = fs.intersection
(fs.gitTracked ./.)
(fs.fileFilter
(f: f.name == "Cargo.lock" ||
f.hasExt "rkt" ||
f.hasExt "rs" ||
f.hasExt "scm" ||
f.hasExt "toml")
./.);
};
cargoLock = {
lockFile = ./Cargo.lock;
};
cargoBuildFlags = "-p cargo-steel-lib -p steel-interpreter";
buildInputs = [openssl] ++ lib.optionals stdenv.isDarwin [darwin.apple_sdk.frameworks.Security];
nativeBuildInputs = [
pkg-config
];
# Test failing
doCheck = false;
postInstall = ''
substituteInPlace cogs/installer/download.scm --replace-warn "cargo-steel-lib" "$out/bin/cargo-steel-lib"
mkdir $out/lib
export STEEL_HOME="$out/lib"
pushd cogs
$out/bin/steel install.scm
popd
rm "$out/bin/cargo-steel-lib"
'';
meta = with lib; {
description = "An embedded scheme interpreter in Rust";
homepage = "https://github.com/mattwparas/steel";
license = with licenses; [asl20 mit];
mainProgram = "steel";
};
};
in rec {
formatter = pkgs.alejandra;
packages.steel = steel;
legacyPackages = packages;
defaultPackage = packages.steel;
devShell = with pkgs;
mkShell {
shellHook = ''
export STEEL_HOME="${steel}/lib/"
'';
buildInputs = [cargo rustc openssl libiconv] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.CoreServices
darwin.apple_sdk.frameworks.SystemConfiguration
];
nativeBuildInputs = [
pkg-config
rust-analyzer
rustfmt
];
};
apps.steel = {
devShells = eachSystem (system: {
default = pkgsFor.${system}.callPackage ./nix/shell.nix {
inherit (self.packages.${system}) steel;
inherit (pkgsFor.${system}.darwin.apple_sdk.frameworks) CoreServices SystemConfiguration;
};
});

apps = eachSystem (system: {
steel = {
type = "app";
program = "${steel}/bin/steel";
program =
pkgsFor.${system}.lib.getExe
self.packages.${system}.steel;
};
apps.default = apps.steel;
default = self.apps.${system}.steel;
});
};
}
61 changes: 61 additions & 0 deletions nix/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
lib,
stdenv,
Security,
openssl,
pkg-config,
rustPlatform,
}: let
manifest = lib.importTOML ../Cargo.toml;
fs = lib.fileset;
in
rustPlatform.buildRustPackage {
pname = manifest.package.name;
version = manifest.workspace.package.version;

src = fs.toSource {
root = ../.;
fileset =
fs.intersection
(fs.gitTracked ../.)
(fs.fileFilter
(f:
f.name
== "Cargo.lock"
|| f.hasExt "rkt"
|| f.hasExt "rs"
|| f.hasExt "scm"
|| f.hasExt "toml")
../.);
};

cargoLock = {
lockFile = ../Cargo.lock;
};
cargoBuildFlags = "-p cargo-steel-lib -p steel-interpreter";

buildInputs = [openssl] ++ lib.optionals stdenv.isDarwin [Security];
nativeBuildInputs = [
pkg-config
];

# Test failing
doCheck = false;
postInstall = ''
substituteInPlace cogs/installer/download.scm --replace-warn "cargo-steel-lib" "$out/bin/cargo-steel-lib"
mkdir $out/lib
export STEEL_HOME="$out/lib"
pushd cogs
$out/bin/steel install.scm
popd
rm "$out/bin/cargo-steel-lib"
'';

meta = {
description = "An embedded scheme interpreter in Rust";
homepage = "https://github.com/mattwparas/steel";
license = with lib.licenses; [asl20 mit];
platforms = lib.platforms.unix;
mainProgram = "steel";
};
}
31 changes: 31 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
lib,
stdenv,
mkShell,
steel,
cargo,
rustc,
libiconv,
CoreServices,
SystemConfiguration,
rust-analyzer,
rustfmt,
}:
mkShell {
shellHook = ''
export STEEL_HOME="${steel}/lib/"
'';
packages =
[
cargo
rustc
rust-analyzer
rustfmt
libiconv
]
++ lib.optionals stdenv.isDarwin [
CoreServices
SystemConfiguration
];
inputsFrom = steel;
}

0 comments on commit d19a8ef

Please sign in to comment.