From 4c90a6029a24bf933582d550059ffbd293c19135 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 9 Jul 2023 11:45:03 +0200 Subject: [PATCH] flake: Init * Uses crane to build deps and code independently. Allows on development fast iterations by running `nix run` to run the program. * Implements formatting and linting as checks. --- flake.lock | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 86 ++++++++++++++++++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c50f366 --- /dev/null +++ b/flake.lock @@ -0,0 +1,132 @@ +{ + "nodes": { + "crane": { + "inputs": { + "flake-compat": [ + "flake-compat" + ], + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": [ + "rust-overlay" + ] + }, + "locked": { + "lastModified": 1688772518, + "narHash": "sha256-ol7gZxwvgLnxNSZwFTDJJ49xVY5teaSvF7lzlo3YQfM=", + "owner": "ipetkov", + "repo": "crane", + "rev": "8b08e96c9af8c6e3a2b69af5a7fa168750fcf88e", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1688679045, + "narHash": "sha256-t3xGEfYIwhaLTPU8FLtN/pLPytNeDwbLI6a7XFFBlGo=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "3c7487575d9445185249a159046cc02ff364bff8", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688870171, + "narHash": "sha256-8tD8fheWPa7TaJoxzcU3iHkCrQQpOpdMN+HYqgZ1N5A=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "5a932f10ac4bd59047d6e8b5780750ec76ea988a", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..141ee8f --- /dev/null +++ b/flake.nix @@ -0,0 +1,86 @@ +{ + description = "Download content from ilias.studium.kit.edu"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + inputs.flake-compat.follows = "flake-compat"; + inputs.rust-overlay.follows = "rust-overlay"; + }; + + # Import them even though we don't use them. Needed to allow overriding `rust-overlay` + # etc. in flakes consuming this flake. + # Temporary until https://github.com/NixOS/nix/issues/6986 is solved. + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; + flake-utils.url = "github:numtide/flake-utils"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, crane, ... }: let + systems = [ "x86_64-linux" ]; + inherit (nixpkgs) lib; + forEachSystem = lib.genAttrs systems; + craneLib = forEachSystem (system: crane.lib.${system}); + + toHydraJob = with lib; foldlAttrs + (jobset: system: attrs: recursiveUpdate jobset + (mapAttrs (const (drv: { ${system} = drv; })) + (filterAttrs (name: const (name != "default")) attrs))) + { }; + + builds = forEachSystem (system: (lib.fix (final: { + common = { + pname = "KIT-ILIAS-Downloader"; + src = craneLib.${system}.cleanCargoSource self; + }; + cargoArtifacts = craneLib.${system}.buildDepsOnly (final.common // { + doCheck = false; + }); + clippy = craneLib.${system}.cargoClippy (final.common // { + inherit (final) cargoArtifacts; + cargoClippyExtraArgs = lib.escapeShellArgs [ + "--all-targets" + "--" + "-D" + "warnings" + "-A" + "non-snake-case" + "-A" + "clippy::upper-case-acronyms" + ]; + }); + format = craneLib.${system}.cargoFmt (final.common // { + inherit (final) cargoArtifacts; + }); + kit-ilias-downloader = craneLib.${system}.buildPackage (final.common // { + inherit (final) cargoArtifacts; + doCheck = false; + meta.license = lib.licenses.gpl3Plus; + meta.platforms = systems; + }); + }))); + in { + packages = forEachSystem (system: { + default = self.packages.${system}.kit-ilias-downloader; + inherit (builds.${system}) kit-ilias-downloader; + }); + checks = forEachSystem (system: { + inherit (builds.${system}) format clippy; + }); + hydraJobs = { + packages = toHydraJob self.packages; + checks = toHydraJob self.checks; + }; + }; +}