From 59864de6bd918b4016050f7380e77e1ce47045ee Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Thu, 9 Jan 2025 21:27:41 +0100 Subject: [PATCH] flake: Limit hydra jobs to x86 and aarch64 --- flake.nix | 195 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 102 insertions(+), 93 deletions(-) diff --git a/flake.nix b/flake.nix index bccbc67..90dd4d7 100644 --- a/flake.nix +++ b/flake.nix @@ -20,107 +20,116 @@ flake-utils, ... }: - flake-utils.lib.eachDefaultSystem ( - system: - let - pkgs = nixpkgs.legacyPackages.${system}; + let + packageOutputs = flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; - craneLib = crane.mkLib pkgs; + craneLib = crane.mkLib pkgs; - dbMigrationsFilter = path: _type: builtins.match ".*sql$" path != null; - dbMigrationsOrCargoFilter = - path: type: (dbMigrationsFilter path type) || (craneLib.filterCargoSources path type); + dbMigrationsFilter = path: _type: builtins.match ".*sql$" path != null; + dbMigrationsOrCargoFilter = + path: type: (dbMigrationsFilter path type) || (craneLib.filterCargoSources path type); - dbMigrations = pkgs.lib.cleanSourceWith { - src = craneLib.path ./db-migrations; # The original, unfiltered source - filter = dbMigrationsFilter; - }; - - # Common arguments can be set here to avoid repeating them later - # Note: changes here will rebuild all dependency crates - commonArgs = rec { - strictDeps = true; # When this is not set, all dependency crates will be compiled again - src = pkgs.lib.cleanSourceWith { - src = craneLib.path ./.; # The original, unfiltered source - filter = dbMigrationsOrCargoFilter; + dbMigrations = pkgs.lib.cleanSourceWith { + src = craneLib.path ./db-migrations; # The original, unfiltered source + filter = dbMigrationsFilter; }; - # Add icons.toml to $src when compiling dependencies (needed by relm4-icons) - extraDummyScript = '' - cp --no-preserve=mode,ownership ${./icons.toml} $out/icons.toml - ''; + # Common arguments can be set here to avoid repeating them later + # Note: changes here will rebuild all dependency crates + commonArgs = rec { + strictDeps = true; # When this is not set, all dependency crates will be compiled again + src = pkgs.lib.cleanSourceWith { + src = craneLib.path ./.; # The original, unfiltered source + filter = dbMigrationsOrCargoFilter; + }; - nativeBuildInputs = with pkgs; [ pkg-config ]; - - buildInputs = - with pkgs; - [ - gtk4 - xournalpp # not needed for building - ] - ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ - # Additional darwin specific inputs can be set here - pkgs.libiconv - ]; - }; - - # Build *just* the cargo dependencies, so we can reuse - # all of that work (e.g. via cachix) when running in CI - cargoArtifacts = craneLib.buildDepsOnly (commonArgs); - - # Run clippy (and deny all warnings) on the crate source, - # reusing the dependency artifacts (e.g. from build scripts or - # proc-macros) from above. - # - # Note that this is done as a separate derivation so it - # does not impact building just the crate by itself. - myCrateClippy = craneLib.cargoClippy ( - commonArgs - // { - # Again we apply some extra arguments only to this derivation - # and not every where else. In this case we add some clippy flags - inherit cargoArtifacts; - cargoClippyExtraArgs = "--all-targets -- --deny warnings"; - } - ); - - # Build the actual crate itself, reusing the dependency - # artifacts from above. - myCrate = craneLib.buildPackage ( - commonArgs - // { - inherit cargoArtifacts; - } - // { - postInstall = '' - mkdir -p $out/share/applications - cp ${./sheet-organizer.desktop} $out/share/applications/sheet-organizer.desktop - - mkdir -p $out/share/icons - cp ${./sheet-organizer.png} $out/share/icons/sheet-organizer.png + # Add icons.toml to $src when compiling dependencies (needed by relm4-icons) + extraDummyScript = '' + cp --no-preserve=mode,ownership ${./icons.toml} $out/icons.toml ''; - } - ); - # Also run the crate tests under cargo-tarpaulin so that we can keep - # track of code coverage - myCrateCoverage = craneLib.cargoTarpaulin (commonArgs // { inherit cargoArtifacts; }); + nativeBuildInputs = with pkgs; [ pkg-config ]; - in - { - packages.default = myCrate; - checks = { - inherit - # Build the crate as part of `nix flake check` for convenience - myCrate - myCrateClippy - myCrateCoverage - ; - }; + buildInputs = + with pkgs; + [ + gtk4 + xournalpp # not needed for building + ] + ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv + ]; + }; - hydraJobs = { - "sheet-organizer" = myCrate; - }; - } - ); + # Build *just* the cargo dependencies, so we can reuse + # all of that work (e.g. via cachix) when running in CI + cargoArtifacts = craneLib.buildDepsOnly (commonArgs); + + # Run clippy (and deny all warnings) on the crate source, + # reusing the dependency artifacts (e.g. from build scripts or + # proc-macros) from above. + # + # Note that this is done as a separate derivation so it + # does not impact building just the crate by itself. + myCrateClippy = craneLib.cargoClippy ( + commonArgs + // { + # Again we apply some extra arguments only to this derivation + # and not every where else. In this case we add some clippy flags + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + + # Build the actual crate itself, reusing the dependency + # artifacts from above. + myCrate = craneLib.buildPackage ( + commonArgs + // { + inherit cargoArtifacts; + } + // { + postInstall = '' + mkdir -p $out/share/applications + cp ${./sheet-organizer.desktop} $out/share/applications/sheet-organizer.desktop + + mkdir -p $out/share/icons + cp ${./sheet-organizer.png} $out/share/icons/sheet-organizer.png + ''; + } + ); + + # Also run the crate tests under cargo-tarpaulin so that we can keep + # track of code coverage + myCrateCoverage = craneLib.cargoTarpaulin (commonArgs // { inherit cargoArtifacts; }); + + in + { + packages.default = myCrate; + checks = { + inherit + # Build the crate as part of `nix flake check` for convenience + myCrate + myCrateClippy + myCrateCoverage + ; + }; + + # hydraJobs = { + # "sheet-organizer" = myCrate; + # }; + } + ); + in + packageOutputs + // { + hydraJobs = { + x86_64-linux.sheet-organizer = packageOutputs.packages.x86_64-linux; + aarch64-linux.sheet-organizer = packageOutputs.packages.aarch64-linux; + }; + }; }