Skip to content

Commit

Permalink
nix: improve flake, versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn committed Nov 10, 2024
1 parent 6542d26 commit 6858072
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 45 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Check
run: nix build --fallback --print-build-logs '.#check-clippy'
run: nix build --fallback --print-build-logs '.#checks.x86_64-linux.clippy'

- name: Upload analysis results
uses: github/codeql-action/upload-sarif@v3
Expand All @@ -45,7 +45,7 @@ jobs:
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Check
run: nix build --fallback --print-build-logs '.#check-rustfmt'
run: nix build --fallback --print-build-logs '.#checks.x86_64-linux.rustfmt'

nixfmt:
runs-on: ubuntu-latest
Expand All @@ -61,4 +61,4 @@ jobs:
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Check
run: nix build --fallback --print-build-logs '.#check-nixfmt'
run: nix build --fallback --print-build-logs '.#checks.x86_64-linux.nixfmt'
1 change: 0 additions & 1 deletion .github/workflows/update-flake-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ jobs:
with:
pr-title: "build(deps): update flake.lock"
commit-msg: "build(deps): update flake.lock"
pr-reviewers: ryanccn
pr-labels: dependencies, nix
79 changes: 41 additions & 38 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,59 +38,68 @@
mkFlakeCheck =
{
name,
nativeBuildInputs ? [ ],
command,
extraConfig ? { },
}:
pkgs.stdenv.mkDerivation {
name = "check-${name}";
inherit nativeBuildInputs;
inherit (self.packages.${system}.nrr) src cargoDeps;

buildPhase = ''
${command}
touch "$out"
'';

doCheck = false;
dontInstall = true;
dontFixup = true;
};
pkgs.stdenv.mkDerivation (
{
name = "check-${name}";
inherit (self.packages.${system}.nrr) src;

buildPhase = ''
${command}
touch "$out"
'';

doCheck = false;
dontInstall = true;
dontFixup = true;
}
// extraConfig
);
in
{
nixfmt = mkFlakeCheck {
name = "nixfmt";
nativeBuildInputs = with pkgs; [ nixfmt-rfc-style ];
command = "nixfmt --check .";

extraConfig = {
nativeBuildInputs = with pkgs; [ nixfmt-rfc-style ];
};
};

rustfmt = mkFlakeCheck {
name = "rustfmt";

nativeBuildInputs = with pkgs; [
cargo
rustfmt
];

command = "cargo fmt --check";

extraConfig = {
nativeBuildInputs = with pkgs; [
cargo
rustfmt
];
};
};

clippy = mkFlakeCheck {
name = "clippy";

nativeBuildInputs = with pkgs; [
rustPlatform.cargoSetupHook
cargo
rustc
clippy
clippy-sarif
sarif-fmt
];

command = ''
cargo clippy --all-features --all-targets --tests \
--offline --message-format=json \
| clippy-sarif | tee $out | sarif-fmt
'';

extraConfig = {
inherit (self.packages.${system}.nrr) cargoDeps;

nativeBuildInputs = with pkgs; [
rustPlatform.cargoSetupHook
cargo
rustc
clippy
clippy-sarif
sarif-fmt
];
};
};
}
);
Expand Down Expand Up @@ -119,7 +128,6 @@

inputsFrom = [ self.packages.${system}.nrr ];

__structuredAttrs = true;
env = {
RUST_BACKTRACE = 1;
RUST_SRC_PATH = toString pkgs.rustPlatform.rustLibSrc;
Expand All @@ -132,17 +140,12 @@
system:
let
pkgs = nixpkgsFor.${system};

# re-use our overlay to call packages
packages = self.overlays.default null pkgs;
in
{
inherit (packages) nrr;
default = packages.nrr;
}
// (lib.attrsets.mapAttrs' (
name: value: lib.nameValuePair "check-${name}" value
) self.checks.${system})
);

legacyPackages = forAllSystems (
Expand Down
9 changes: 6 additions & 3 deletions nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
enableOptimizeSize ? false,
nrxAlias ? true,
}:

let
year = builtins.substring 0 4 self.lastModifiedDate;
month = builtins.substring 4 2 self.lastModifiedDate;
day = builtins.substring 6 2 self.lastModifiedDate;
in
rustPlatform.buildRustPackage rec {
pname = passthru.cargoToml.package.name;
inherit (passthru.cargoToml.package) version;
version = passthru.cargoToml.package.version + "-unstable-${year}-${month}-${day}";

__structuredAttrs = true;
strictDeps = true;

src = nix-filter.lib.filter {
Expand Down

0 comments on commit 6858072

Please sign in to comment.