diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e550649..a3cf4d7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -48,7 +48,7 @@ jobs: run: | nix develop -c \ cargo run -- \ - --condition "supportedRefs.contains(gitRef) && numDaysOld < 30 && owner == 'NixOS'" \ + --condition "supportedRefs.contains(gitRef) && numDaysOld > 30 && owner == 'NixOS'" \ ./tests/flake.cel.0.lock check-flake-dirty: diff --git a/Cargo.lock b/Cargo.lock index e739ea2..a8e5231 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -347,7 +347,7 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flake-checker" -version = "0.2.2" +version = "0.2.3" dependencies = [ "cel-interpreter", "chrono", diff --git a/Cargo.toml b/Cargo.toml index b724a01..92015a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flake-checker" -version = "0.2.2" +version = "0.2.3" edition = "2021" [workspace] diff --git a/crane.nix b/crane.nix deleted file mode 100644 index 79f3183..0000000 --- a/crane.nix +++ /dev/null @@ -1,108 +0,0 @@ -{ stdenv -, pkgs -, lib -, crane -, rust -, rust-bin -, nix-gitignore -, supportedSystems -}: - -let - inherit (stdenv.hostPlatform) system; - - nightlyVersion = "2024-06-13"; - rustNightly = pkgs.rust-bin.nightly.${nightlyVersion}.default.override { - extensions = [ "rust-src" "rust-analyzer-preview" ]; - targets = cargoTargets; - }; - - # For easy cross-compilation in devShells - # We are just composing the pkgsCross.*.stdenv.cc together - crossPlatforms = - let - makeCrossPlatform = crossSystem: - let - pkgsCross = - if crossSystem == system then pkgs - else - import pkgs.path { - inherit system crossSystem; - overlays = [ ]; - }; - - rustTargetSpec = rust.toRustTargetSpec pkgsCross.pkgsStatic.stdenv.hostPlatform; - rustTargetSpecUnderscored = builtins.replaceStrings [ "-" ] [ "_" ] rustTargetSpec; - - cargoLinkerEnv = lib.strings.toUpper "CARGO_TARGET_${rustTargetSpecUnderscored}_LINKER"; - cargoCcEnv = "CC_${rustTargetSpecUnderscored}"; # for ring - - cc = "${pkgsCross.stdenv.cc}/bin/${pkgsCross.stdenv.cc.targetPrefix}cc"; - in - { - name = crossSystem; - value = { - inherit rustTargetSpec cc; - pkgs = pkgsCross; - env = { - "${cargoLinkerEnv}" = cc; - "${cargoCcEnv}" = cc; - }; - }; - }; - systems = lib.filter (s: s == system || lib.hasInfix "linux" s) supportedSystems; - in - builtins.listToAttrs (map makeCrossPlatform systems); - - cargoTargets = lib.mapAttrsToList (_: p: p.rustTargetSpec) crossPlatforms; - cargoCrossEnvs = lib.foldl (acc: p: acc // p.env) { } (builtins.attrValues crossPlatforms); - - buildFor = system: - let - crossPlatform = crossPlatforms.${system}; - inherit (crossPlatform) pkgs; - craneLib = (crane.mkLib pkgs).overrideToolchain rustNightly; - crateName = craneLib.crateNameFromCargoToml { - cargoToml = ./Cargo.toml; - }; - - src = nix-gitignore.gitignoreSource [ ] ./.; - - commonArgs = { - inherit (crateName) pname version; - inherit src; - - buildInputs = with pkgs; [ ] - ++ lib.optionals pkgs.stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Security SystemConfiguration ]); - - nativeBuildInputs = with pkgs; [ ] - # The Rust toolchain from rust-overlay has a dynamic libiconv in depsTargetTargetPropagated - # Our static libiconv needs to take precedence - ++ lib.optionals pkgs.stdenv.isDarwin [ - libiconv - ]; - - cargoExtraArgs = "--target ${crossPlatform.rustTargetSpec}"; - - cargoVendorDir = craneLib.vendorMultipleCargoDeps { - inherit (craneLib.findCargoFiles src) cargoConfigs; - cargoLockList = [ - ./Cargo.lock - "${rustNightly.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/Cargo.lock" - ]; - }; - } // crossPlatform.env; - - crate = craneLib.buildPackage (commonArgs // { - cargoArtifacts = craneLib.buildDepsOnly commonArgs; - } // lib.optionalAttrs (!stdenv.isDarwin) { - allowedRequisites = [ ]; - }); - in - crate; -in -{ - inherit crossPlatforms cargoTargets cargoCrossEnvs rustNightly; - - flake-checker = buildFor system; -} diff --git a/flake.lock b/flake.lock index d9287a3..8b5babf 100644 --- a/flake.lock +++ b/flake.lock @@ -1,57 +1,92 @@ { "nodes": { - "crane": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1732689334, + "narHash": "sha256-yKI1KiZ0+bvDvfPTQ1ZT3oP/nIu3jPYm4dnbRd6hYg4=", + "rev": "a8a983027ca02b363dfc82fbe3f7d9548a8d3dce", + "revCount": 2090, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/nix-community/fenix/0.1.2090%2Brev-a8a983027ca02b363dfc82fbe3f7d9548a8d3dce/0193814c-7c19-7c1a-a29e-27c7d7c19316/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/nix-community/fenix/0.1.%2A" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, "locked": { - "lastModified": 1731974531, - "narHash": "sha256-z7hiGBWsbWwSnu5UMmYyfHEehlSmfB8sCA8iH4nmxm8=", - "rev": "8ff9c457d60951bdd37a05ae903423de7ff55c6e", - "revCount": 654, + "lastModified": 1733346208, + "narHash": "sha256-a4WZp1xQkrnA4BbnKrzJNr+dYoQr5Xneh2syJoddFyE=", + "rev": "378614f37a6bee5a3f2ef4f825a73d948d3ae921", + "revCount": 346, "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/ipetkov/crane/0.19.3/019341bb-a47c-7229-bccd-4586c6148192/source.tar.gz" + "url": "https://api.flakehub.com/f/pinned/nix-community/naersk/0.1.346%2Brev-378614f37a6bee5a3f2ef4f825a73d948d3ae921/0193937c-f28a-7b8d-988a-faa15e0e0a65/source.tar.gz" }, "original": { "type": "tarball", - "url": "https://flakehub.com/f/ipetkov/crane/0.19.%2A" + "url": "https://flakehub.com/f/nix-community/naersk/0.1.%2A" } }, "nixpkgs": { "locked": { - "lastModified": 1733016324, - "narHash": "sha256-8qwPSE2g1othR1u4uP86NXxm6i7E9nHPyJX3m3lx7Q4=", - "rev": "7e1ca67996afd8233d9033edd26e442836cc2ad6", - "revCount": 637020, + "lastModified": 1733064805, + "narHash": "sha256-7NbtSLfZO0q7MXPl5hzA0sbVJt6pWxxtGWbaVUDDmjs=", + "rev": "31d66ae40417bb13765b0ad75dd200400e98de84", + "revCount": 715040, "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2405.637020%2Brev-7e1ca67996afd8233d9033edd26e442836cc2ad6/01938271-595b-797a-b079-b2b4fda246ca/source.tar.gz" + "url": "https://api.flakehub.com/f/pinned/DeterminateSystems/nixpkgs-weekly/0.1.715040%2Brev-31d66ae40417bb13765b0ad75dd200400e98de84/01938b06-3358-73df-a7e1-598cb884b5d0/source.tar.gz" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1733261153, + "narHash": "sha256-eq51hyiaIwtWo19fPEeE0Zr2s83DYMKJoukNLgGGpek=", + "rev": "b681065d0919f7eb5309a93cea2cfa84dec9aa88", + "revCount": 710315, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2411.710315%2Brev-b681065d0919f7eb5309a93cea2cfa84dec9aa88/01939169-d1fd-700c-ac3b-46b9812bdcec/source.tar.gz" }, "original": { "type": "tarball", - "url": "https://flakehub.com/f/NixOS/nixpkgs/0.2405.%2A" + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.2411.%2A" } }, "root": { "inputs": { - "crane": "crane", - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "fenix": "fenix", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2" } }, - "rust-overlay": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, + "rust-analyzer-src": { + "flake": false, "locked": { - "lastModified": 1733193245, - "narHash": "sha256-nwvKoPi3S6XyliqBRuC+01QFF0k94ZOvnoZtbGi/ObM=", - "rev": "3458f7f946ba61d1a1069aedcc17d7b7616f23cd", - "revCount": 1613, - "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/oxalica/rust-overlay/0.1.1613%2Brev-3458f7f946ba61d1a1069aedcc17d7b7616f23cd/01938a5f-fd1d-7a15-b29a-f49c2e4acf7e/source.tar.gz" + "lastModified": 1732633904, + "narHash": "sha256-7VKcoLug9nbAN2txqVksWHHJplqK9Ou8dXjIZAIYSGc=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "8d5e91c94f80c257ce6dbdfba7bd63a5e8a03fa6", + "type": "github" }, "original": { - "type": "tarball", - "url": "https://flakehub.com/f/oxalica/rust-overlay/%2A" + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 66a031b..a5a4eb5 100644 --- a/flake.nix +++ b/flake.nix @@ -1,54 +1,99 @@ { inputs = { - nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2405.*"; - rust-overlay = { - url = "https://flakehub.com/f/oxalica/rust-overlay/*"; + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2411.*"; + + fenix = { + url = "https://flakehub.com/f/nix-community/fenix/0.1.*"; inputs.nixpkgs.follows = "nixpkgs"; }; - crane.url = "https://flakehub.com/f/ipetkov/crane/0.19.*"; + + naersk.url = "https://flakehub.com/f/nix-community/naersk/0.1.*"; }; outputs = { self, ... }@inputs: let + lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; + version = "${builtins.substring 0 8 lastModifiedDate}-${self.shortRev or "dirty"}"; + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - forAllSystems = f: inputs.nixpkgs.lib.genAttrs supportedSystems (system: f rec { + + forSystems = s: f: inputs.nixpkgs.lib.genAttrs s (system: f rec { + inherit system; pkgs = import inputs.nixpkgs { inherit system; - overlays = [ - inputs.rust-overlay.overlays.default - ]; - }; - - cranePkgs = pkgs.callPackage ./crane.nix { - inherit (inputs) crane; - inherit supportedSystems; + overlays = [ self.overlays.default ]; }; }); + + forAllSystems = forSystems supportedSystems; in { - packages = forAllSystems ({ cranePkgs, ... }: rec { - inherit (cranePkgs) flake-checker; + overlays.default = final: prev: + let + inherit (final.stdenv.hostPlatform) system; + + rustToolchain = with inputs.fenix.packages.${system}; + combine ([ + stable.clippy + stable.rustc + stable.cargo + stable.rustfmt + stable.rust-src + ] ++ inputs.nixpkgs.lib.optionals (system == "x86_64-linux") [ + targets.x86_64-unknown-linux-musl.stable.rust-std + ] ++ inputs.nixpkgs.lib.optionals (system == "aarch64-linux") [ + targets.aarch64-unknown-linux-musl.stable.rust-std + ]); + in + { + inherit rustToolchain; + + naerskLib = final.callPackage inputs.naersk { + cargo = rustToolchain; + rustc = rustToolchain; + }; + }; + + packages = forAllSystems ({ pkgs, system }: rec { default = flake-checker; + + flake-checker = pkgs.naerskLib.buildPackage + ({ + name = "flake-checker-${version}"; + src = self; + doCheck = true; + buildInputs = with pkgs; [ ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Security SystemConfiguration ]); + nativeBuildInputs = with pkgs; [ ] ++ lib.optionals stdenv.isDarwin [ libiconv ]; + } // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux { + CARGO_BUILD_TARGET = + if system == "x86_64-linux" then + "x86_64-unknown-linux-musl" + else if system == "aarch64-linux" then + "aarch64-unknown-linux-musl" + else + throw "Unsupported Linux system: ${system}"; + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; + }); }); - devShells = forAllSystems ({ pkgs, cranePkgs }: { + devShells = forAllSystems ({ pkgs, ... }: { default = let check-nixpkgs-fmt = pkgs.writeShellApplication { name = "check-nixpkgs-fmt"; runtimeInputs = with pkgs; [ git nixpkgs-fmt ]; text = '' - git ls-files '*.nix' | xargs nixpkgs-fmt --check + nixpkgs-fmt --check "$(git ls-files '*.nix')" ''; }; check-rustfmt = pkgs.writeShellApplication { name = "check-rustfmt"; - runtimeInputs = [ cranePkgs.rustNightly ]; + runtimeInputs = with pkgs; [ rustToolchain ]; text = "cargo fmt --check"; }; get-allowed-refs = pkgs.writeShellApplication { name = "get-allowed-refs"; - runtimeInputs = [ cranePkgs.rustNightly ]; + runtimeInputs = with pkgs; [ rustToolchain ]; text = "cargo run --features allowed-refs -- --get-allowed-refs"; }; in @@ -57,7 +102,7 @@ bashInteractive # Rust - cranePkgs.rustNightly + rustToolchain cargo-bloat cargo-edit cargo-machete @@ -77,7 +122,7 @@ env = { # Required by rust-analyzer - RUST_SRC_PATH = "${cranePkgs.rustNightly}/lib/rustlib/src/rust/library"; + RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library"; }; }; });