summary refs log tree commit diff
path: root/flake.nix
diff options
context:
space:
mode:
authorSophie Forrest <git@sophieforrest.com>2024-10-04 23:25:44 +1300
committerSophie Forrest <git@sophieforrest.com>2024-10-04 23:25:44 +1300
commit1f82a90833990db8efe6111f89a9126a2fde74c5 (patch)
treeba7783a34a51fa710e332b00f824cef93abc2436 /flake.nix
parentd58a4d4ec245ea336b0e8b93e5ae3907b39395b4 (diff)
feat: refactor tooling
Diffstat (limited to '')
-rw-r--r--flake.nix104
1 files changed, 67 insertions, 37 deletions
diff --git a/flake.nix b/flake.nix
index 7fda700..376233c 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,74 +1,104 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
 {
-  description = "Logic table generator on the command line.";
+  description = "A MOS6502 emulator written in Rust.";
 
   inputs = {
     nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
 
-    flake-parts.url = "github:hercules-ci/flake-parts";
+    crane.url = "github:ipetkov/crane";
 
-    nci = {
-      inputs.nixpkgs.follows = "nixpkgs";
-      url = "github:yusdacra/nix-cargo-integration";
+    # devenv dependencies
+    devenv-root = {
+      url = "file+file:///dev/null";
+      flake = false;
     };
+    flake-parts.url = "github:hercules-ci/flake-parts";
+    devenv.url = "github:cachix/devenv";
+    devenv.inputs.nixpkgs.follows = "nixpkgs";
+    nix2container.url = "github:nlewo/nix2container";
+    nix2container.inputs.nixpkgs.follows = "nixpkgs";
+    mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
 
+    # Custom template dependencies
     treefmt-nix.url = "github:numtide/treefmt-nix";
+    treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
   };
 
   outputs = inputs @ {
-    self,
+    crane,
     flake-parts,
-    nixpkgs,
-    nci,
-    treefmt-nix,
+    devenv-root,
+    ...
   }:
     flake-parts.lib.mkFlake {inherit inputs;} {
       imports = [
-        nci.flakeModule
-        treefmt-nix.flakeModule
+        inputs.devenv.flakeModule
+        inputs.treefmt-nix.flakeModule
       ];
 
-      systems = [
-        "x86_64-linux"
-      ];
+      systems = ["x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
 
       perSystem = {
         config,
         pkgs,
-        system,
-        lib,
         ...
       }: let
-        crateOutputs = config.nci.outputs."mos6502";
+        craneLib = crane.mkLib pkgs;
+        src = craneLib.cleanCargoSource ./.;
+
+        commonArgs = {
+          inherit src;
+          strictDeps = true;
+        };
+
+        cargoArtifacts = craneLib.buildDepsOnly commonArgs;
+
+        mos6502 = craneLib.buildPackage (commonArgs // {inherit cargoArtifacts;});
       in {
-        nci.projects.mos6502.path = ./.;
+        checks = {
+          inherit mos6502;
+          mos6502-clippy = craneLib.cargoClippy (commonArgs
+            // {
+              inherit cargoArtifacts;
+            });
+          mos6502-nextest = craneLib.cargoNextest (commonArgs
+            // {
+              inherit cargoArtifacts;
+              partitions = 1;
+              partitionType = "count";
+            });
+        };
 
-        # configure crates
-        nci.crates.mos6502 = {
-          depsDrvConfig.env = {
-            RUSTFLAGS = "-A missing-docs";
+        packages.default = mos6502;
+
+        devenv.shells.default = {
+          devenv.root = let
+            devenvRootFileContent = builtins.readFile devenv-root.outPath;
+          in
+            pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;
+
+          imports = [./nix/devenv.nix];
+
+          pre-commit.hooks.treefmt = {
+            enable = true;
+            packageOverrides.treefmt = config.treefmt.build.wrapper;
           };
+
+          name = "my-project";
         };
 
         treefmt = {
-          projectRootFile = "flake.nix";
+          # Checked by pre-commit.
+          flakeCheck = false;
+          flakeFormatter = true;
           programs = {
-            rustfmt = {
-              enable = true;
-              package = config.nci.toolchains.shell;
-            };
+            alejandra.enable = true;
+            rustfmt.enable = true;
+            statix.enable = true;
             taplo.enable = true;
           };
+          projectRootFile = "flake.nix";
         };
-
-        devShells.default = crateOutputs.devShell.overrideAttrs (_: {
-          buildInputs = with pkgs; [
-            bacon
-            gcc
-            mold
-          ];
-        });
-
-        packages.default = crateOutputs.packages.release;
       };
     };
 }