diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..412cbef --- /dev/null +++ b/.envrc @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# ^ make editor happy + +# +# Use https://direnv.net/ to automatically load the dev shell. +# + +if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4=" +fi + +watch_file nix/** +watch_file -- **/*.nix +# Adding files to git includes them in a flake +# But it is also a bit much reloading. +# watch_file .git/index .git/HEAD +use flake . --show-trace diff --git a/.gitignore b/.gitignore index d4eefd9..340febe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ +.direnv/ /target **/*.rs.bk *.db /.meta /build -/.vscode \ No newline at end of file +/.vscode diff --git a/README.md b/README.md index db3c387..2d73bf5 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,14 @@ cargo build --release # add or remove any features with --features cp target/release/hullcaster ~/.local/bin ``` +### NixOS / Nix + +With [flakes](https://wiki.nixos.org/wiki/Flakes) enabled, run: + +```bash +nix run github:gilcu3/hullcaster +``` + ## Running hullcaster In your terminal, run: diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b7c84fe --- /dev/null +++ b/flake.lock @@ -0,0 +1,335 @@ +{ + "nodes": { + "cachix": { + "inputs": { + "devenv": [ + "crate2nix" + ], + "flake-compat": [ + "crate2nix" + ], + "nixpkgs": "nixpkgs", + "pre-commit-hooks": [ + "crate2nix" + ] + }, + "locked": { + "lastModified": 1716549461, + "narHash": "sha256-lHy5kgx6J8uD+16SO47dPrbob98sh+W1tf4ceSqPVK4=", + "owner": "cachix", + "repo": "cachix", + "rev": "e2bb269fb8c0828d5d4d2d7b8d09ea85abcacbd4", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "latest", + "repo": "cachix", + "type": "github" + } + }, + "crate2nix": { + "inputs": { + "cachix": "cachix", + "crate2nix_stable": [ + "crate2nix" + ], + "devshell": [ + "devshell" + ], + "flake-compat": "flake-compat", + "flake-parts": [ + "flake-parts" + ], + "nix-test-runner": "nix-test-runner", + "nixpkgs": [ + "nixpkgs" + ], + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1704639602, + "narHash": "sha256-XZ3nSPC3FEOrmwOpZqqoAxf5baJRhA08/Qy1/SBaXJw=", + "owner": "nix-community", + "repo": "crate2nix", + "rev": "b1552fd27689b5997cb744de1dbf066922202805", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "crate2nix", + "type": "github" + } + }, + "devshell": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "systems": "systems_2" + }, + "locked": { + "lastModified": 1704627967, + "narHash": "sha256-XxorJ8NKO4XG1rUeGE8DLlOCE9x63c2FnC8QoudVGsg=", + "owner": "numtide", + "repo": "devshell", + "rev": "2c55ba1531bf1d4b31906914cb73fc339d0181d0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "revCount": 57, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1704152458, + "narHash": "sha256-DS+dGw7SKygIWf9w4eNBUZsK+4Ug27NwEWmn2tnbycg=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "88a2cd8166694ba0b6cb374700799cec53aef527", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "crate2nix", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nix-test-runner": { + "flake": false, + "locked": { + "lastModified": 1588761593, + "narHash": "sha256-FKJykltAN/g3eIceJl4SfDnnyuH2jHImhMrXS2KvGIs=", + "owner": "stoeffel", + "repo": "nix-test-runner", + "rev": "c45d45b11ecef3eb9d834c3b6304c05c49b06ca2", + "type": "github" + }, + "original": { + "owner": "stoeffel", + "repo": "nix-test-runner", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1715534503, + "narHash": "sha256-5ZSVkFadZbFP1THataCaSf0JH2cAH3S29hU9rrxTEqk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2057814051972fa1453ddfb0d98badbea9b83c06", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1704161960, + "narHash": "sha256-QGua89Pmq+FBAro8NriTuoO/wNaUtugt29/qqA8zeeM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63143ac2c9186be6d9da6035fa22620018c85932", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": [ + "crate2nix", + "flake-compat" + ], + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "crate2nix", + "nixpkgs" + ], + "nixpkgs-stable": [ + "crate2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703939133, + "narHash": "sha256-Gxe+mfOT6bL7wLC/tuT2F+V+Sb44jNr8YsJ3cyIl4Mo=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "9d3d7e18c6bc4473d7520200d4ddab12f8402d38", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "crate2nix": "crate2nix", + "devshell": "devshell", + "flake-parts": "flake-parts", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1704593904, + "narHash": "sha256-nDoXZDTRdgF3b4n3m011y99nYFewvOl9UpzFvP8Rb3c=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "c36fd70a99decfa6e110c86f296a97613034a680", + "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" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "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..b04a195 --- /dev/null +++ b/flake.nix @@ -0,0 +1,87 @@ +{ + description = "hullcaster"; + + inputs = { + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.flake-utils.follows = "flake-utils"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + crate2nix = { + url = "github:nix-community/crate2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-parts.follows = "flake-parts"; + inputs.crate2nix_stable.follows = "crate2nix"; + inputs.devshell.follows = "devshell"; + inputs.flake-utils.follows = "flake-utils"; + }; + + # Development + + devshell = { + url = "github:numtide/devshell"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + nixConfig = { + extra-trusted-public-keys = "eigenvalue.cachix.org-1:ykerQDDa55PGxU25CETy9wF6uVDpadGGXYrFNJA3TUs="; + extra-substituters = "https://eigenvalue.cachix.org"; + allow-import-from-derivation = true; + }; + + outputs = + inputs @ { self + , nixpkgs + , flake-parts + , rust-overlay + , crate2nix + , ... + }: flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + imports = [ + ./nix/rust-overlay/flake-module.nix + ./nix/devshell/flake-module.nix + ]; + + perSystem = { system, pkgs, lib, inputs', ... }: + let + # If you dislike IFD, you can also generate it with `crate2nix generate` + # on each dependency change and import it here with `import ./Cargo.nix`. + cargoNix = inputs.crate2nix.tools.${system}.appliedCargoNix { + name = "rustnix"; + src = ./.; + }; + in + rec { + checks = { + rustnix = cargoNix.rootCrate.build.override { + runTests = true; + }; + }; + + packages = { + rustnix = cargoNix.rootCrate.build; + default = packages.rustnix; + + inherit (pkgs) rust-toolchain; + + rust-toolchain-versions = pkgs.writeScriptBin "rust-toolchain-versions" '' + ${pkgs.rust-toolchain}/bin/cargo --version + ${pkgs.rust-toolchain}/bin/rustc --version + ''; + }; + }; + }; +} diff --git a/nix/devshell/flake-module.nix b/nix/devshell/flake-module.nix new file mode 100644 index 0000000..146490e --- /dev/null +++ b/nix/devshell/flake-module.nix @@ -0,0 +1,25 @@ +{ inputs, lib, ... }: { + imports = [ + inputs.devshell.flakeModule + ]; + + config.perSystem = + { pkgs + , ... + }: { + config.devshells.default = { + imports = [ + "${inputs.devshell}/extra/language/c.nix" + # "${inputs.devshell}/extra/language/rust.nix" + ]; + + commands = with pkgs; [ + { package = rust-toolchain; category = "rust"; } + ]; + + language.c = { + libraries = lib.optional pkgs.stdenv.isDarwin pkgs.libiconv; + }; + }; + }; +} diff --git a/nix/rust-overlay/flake-module.nix b/nix/rust-overlay/flake-module.nix new file mode 100644 index 0000000..52fa53d --- /dev/null +++ b/nix/rust-overlay/flake-module.nix @@ -0,0 +1,18 @@ +{ inputs, ... }: +let + overlays = [ + (import inputs.rust-overlay) + (self: super: assert !(super ? rust-toolchain); rec { + rust-toolchain = super.rust-bin.fromRustupToolchainFile ../../rust-toolchain.toml; + + # buildRustCrate/crate2nix depend on this. + rustc = rust-toolchain; + cargo = rust-toolchain; + }) + ]; +in +{ + perSystem = { system, ... }: { + _module.args.pkgs = import inputs.nixpkgs { inherit system overlays; config = { }; }; + }; +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..292fe49 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "stable"