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

Housekeeping #40

Merged
merged 12 commits into from
Sep 19, 2023
10 changes: 0 additions & 10 deletions .github/workflows/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,6 @@ jobs:
run: |
echo "version=$(./.github/workflows/get-crate-version.sh)" >> "$GITHUB_OUTPUT"

- name: Increment `flake.nix` version
run: |
sed -i \
-e "s/version = \"[^\"]*\"; # LOAD-BEARING COMMENT/version = \"${{ steps.new_cargo_metadata.outputs.version }}\"; # LOAD-BEARING COMMENT/" \
flake.nix

# Commit the new changes
git add flake.nix
git commit --amend --no-edit

- name: Create release PR
id: release_pr
uses: peter-evans/create-pull-request@v5
Expand Down
20 changes: 7 additions & 13 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
(
import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{src = ./.;}
)
(import (let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) {src = ./.;})
.defaultNix
112 changes: 102 additions & 10 deletions flake.lock

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

130 changes: 81 additions & 49 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,111 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
systems.url = "github:nix-systems/default";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
alejandra.url = "github:kamadorueda/alejandra";
};

outputs = {
self,
nixpkgs,
flake-utils,
flake-compat,
}:
flake-utils.lib.eachDefaultSystem (
system: let
systems,
alejandra,
...
}: let
inherit (nixpkgs) lib;
eachSystem = fn:
lib.genAttrs (import systems) (system: let
pkgs = import nixpkgs {
inherit system;
localSystem = system;
overlays = [self.overlays.default];
};
in {
packages = rec {
nix-your-shell = pkgs.nix-your-shell;
default = nix-your-shell;
in
fn pkgs system);
in {
packages = eachSystem (pkgs: system: {
nix-your-shell = pkgs.nix-your-shell;
default = self.packages.${system}.nix-your-shell;
});

checks = eachSystem (pkgs: system:
self.packages.${system}
// {
check-formatting = pkgs.stdenvNoCC.mkDerivation {
name = "check-formatting";
src = ./.;
phases = ["checkPhase" "installPhase"];
doCheck = true;
nativeCheckInputs = [
pkgs.cargo
pkgs.rustfmt
alejandra.packages.${system}.default
];
checkPhase = ''
cd $src
echo 'Checking Nix code formatting with Alejandra:'
alejandra --check .
echo 'Checking Rust code formatting with `cargo fmt`:'
cargo fmt --check
'';
installPhase = "touch $out";
};
checks = self.packages.${system};
});

# for debugging
# inherit pkgs;
# for debugging
# inherit pkgs;

devShells.default = pkgs.nix-your-shell.overrideAttrs (
old: {
# Make rust-analyzer work
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
devShells = eachSystem (pkgs: system: {
default = pkgs.nix-your-shell.overrideAttrs (old: {
# Make rust-analyzer work
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;

# Any dev tools you use in excess of the rust ones
nativeBuildInputs =
old.nativeBuildInputs;
}
);
}
)
// {
overlays.default = (
final: prev: {
nix-your-shell = final.rustPlatform.buildRustPackage {
pname = "nix-your-shell";
version = "1.3.0"; # LOAD-BEARING COMMENT. See: `.github/workflows/version.yaml`
# Any dev tools you use in excess of the rust ones
nativeBuildInputs = old.nativeBuildInputs;
});
});

cargoLock = {
lockFile = ./Cargo.lock;
};
overlays.default = final: prev: {
nix-your-shell = let
manifest = lib.importTOML ./Cargo.toml;
in
final.rustPlatform.buildRustPackage {
pname = manifest.package.name;
inherit (manifest.package) version;

src = ./.;
cargoLock = {lockFile = ./Cargo.lock;};

# Tools on the builder machine needed to build; e.g. pkg-config
nativeBuildInputs = [
final.rustfmt
final.clippy
];
src = ./.;

# Native libs
buildInputs = [];
# Tools on the builder machine needed to build; e.g. pkg-config
nativeBuildInputs = [final.rustfmt final.clippy];

postCheck = ''
cargo fmt --check && echo "\`cargo fmt\` is OK"
cargo clippy -- --deny warnings && echo "\`cargo clippy\` is OK"
'';
# Native libs
buildInputs = [];

passthru.generate-config = shell: final.runCommand "nix-your-shell-config" { } ''
preCheck = ''
cargo check --frozen
cargo clippy -- --deny warnings
'';

passthru.generate-config = shell:
final.runCommand "nix-your-shell-config" {} ''
${final.nix-your-shell}/bin/nix-your-shell ${shell} >> $out
'';

meta = {
inherit (manifest.package) description homepage;
license = lib.licenses.mit;
maintainers = [lib.maintainers._9999years];
platforms = import systems;
mainProgram = manifest.package.name;
};
}
);
};
};

formatter = eachSystem (_: system: alejandra.packages.${system}.default);
};
}
1 change: 1 addition & 0 deletions flake.systems.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux"]
20 changes: 7 additions & 13 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
(
import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{src = ./.;}
)
(import (let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) {src = ./.;})
.defaultNix