From ed22680db1421a88912e9d1fd293980a8787128e Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Sat, 4 Nov 2023 20:57:43 +0100 Subject: [PATCH] init --- .envrc | 1 + .gitignore | 4 + Cargo.lock | 7 ++ Cargo.toml | 8 ++ flake.lock | 263 +++++++++++++++++++++++++++++++++++++++ flake.nix | 133 ++++++++++++++++++++ nix/packages/aba2sat.nix | 27 ++++ src/main.rs | 3 + 8 files changed, 446 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/packages/aba2sat.nix create mode 100644 src/main.rs diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2328d65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.direnv +result* +target/ +.pre-commit-config.yaml diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..a9af3f3 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aba2sat" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..162ce0e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "aba2sat" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8b8ed0a --- /dev/null +++ b/flake.lock @@ -0,0 +1,263 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1699078825, + "narHash": "sha256-Np1XuKxZG1J4AdMm6m9PogFTWHnvKvmyoILvAXUahFM=", + "owner": "nix-community", + "repo": "fenix", + "rev": "ec493cf412f94155daac4b95c95eb11ddcb347e5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "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-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1698882062, + "narHash": "sha256-HkhafUayIqxXyHH1X8d9RDl1M2CkFgZLjKD3MzabiEo=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8c9fa2545007b49a5db5f650ae91f227672c3877", + "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" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks-nix", + "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" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1699065553, + "narHash": "sha256-j8UmH8fqXcOgL6WrlMcvV2m2XQ6OzU0IBucyuJ0vnyQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8ab9c53eee434651ce170dee1d9727b974e9a6b6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1698611440, + "narHash": "sha256-jPjHjrerhYDy3q9+s5EAsuhyhuknNfowY6yt6pjn9pc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0cbe9f69c234a7700596e943bfae7ef27a31b735", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1689261696, + "narHash": "sha256-LzfUtFs9MQRvIoQ3MfgSuipBVMXslMPH/vZ+nM40LkA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "df1eee2aa65052a18121ed4971081576b25d6b5c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1695644571, + "narHash": "sha256-asS9dCCdlt1lPq0DLwkVBbVoEKuEuz+Zi3DG7pR/RxA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6500b4580c2a1f3d0f980d32d285739d8e156d92", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks-nix": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1698852633, + "narHash": "sha256-Hsc/cCHud8ZXLvmm8pxrXpuaPEeNaaUttaCvtdX/Wug=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "dec10399e5b56aa95fcd530e0338be72ad6462a0", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "pre-commit-hooks-nix": "pre-commit-hooks-nix", + "treefmt-nix": "treefmt-nix" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1698994377, + "narHash": "sha256-PY6A0JiJmv5ef0uf10ediOznKbqCKlqgT3Vtu+Z5fRQ=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "0fec61aabf62faab0c9f9b33b40ea5d5977792c8", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "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" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1698438538, + "narHash": "sha256-AWxaKTDL3MtxaVTVU5lYBvSnlspOS0Fjt8GxBgnU0Do=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "5deb8dc125a9f83b65ca86cf0c8167c46593e0b1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9a79222 --- /dev/null +++ b/flake.nix @@ -0,0 +1,133 @@ +{ + inputs.flake-parts.url = "github:hercules-ci/flake-parts"; + inputs.treefmt-nix.url = "github:numtide/treefmt-nix"; + inputs.pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = inputs @ { + self, + flake-parts, + treefmt-nix, + pre-commit-hooks-nix, + fenix, + ... + }: + flake-parts.lib.mkFlake {inherit inputs self;} { + imports = [ + treefmt-nix.flakeModule + pre-commit-hooks-nix.flakeModule + ]; + + systems = [ + "x86_64-linux" + ]; + + flake.hydraJobs.packages.x86_64-linux = self.packages.x86_64-linux; + flake.hydraJobs.devShells.x86_64-linux = self.devShells.x86_64-linux; + flake.hydraJobs.checks.x86_64-linux = self.checks.x86_64-linux; + + perSystem = { + self', + pkgs, + config, + system, + ... + }: let + rustToolchain = with fenix.packages.${system}; + combine [ + (complete.withComponents [ + "cargo" + "clippy" + "rust-src" + "rustc" + "rustfmt" + ]) + rust-analyzer + ]; + + rustPlatform = pkgs.makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; + }; + + rename = pkgs.writeShellApplication { + name = "rename"; + runtimeInputs = [ + pkgs.fd + pkgs.coreutils + pkgs.nixFlakes + pkgs.jq + ]; + text = '' + newName="$1" + pushd "$(nix flake metadata --json 2>/dev/null | jq .original.path -r)" + # This is only used to prevent the literal name from appearing here, as the rename would find it! + oldName=$(echo 'change_my_name' | sed 's/_/-/g') + stat "nix/packages/$oldName.nix" 2>/dev/null >/dev/null || echo -e "\033[31mCan only be done once\033[0m" + stat "nix/packages/$oldName.nix" 2>/dev/null >/dev/null || exit 1 + fd --type f --exec sed "s/aba2sat/$newName/g" -i '{}' + mv nix/packages/aba2sat.nix "nix/packages/$newName.nix" + ''; + }; + in { + pre-commit.check.enable = true; + pre-commit.settings.hooks.markdownlint.enable = true; + pre-commit.settings.hooks.nil.enable = true; + pre-commit.settings.hooks.format = { + enable = true; + entry = "${self'.formatter}/bin/fmt"; + pass_filenames = false; + }; + pre-commit.settings.hooks.my-clippy = { + enable = true; + name = "clippy"; + description = "Lint Rust code."; + entry = "${rustToolchain}/bin/cargo-clippy clippy --offline -- -D warnings"; + files = "\\.rs$"; + pass_filenames = false; + }; + pre-commit.settings.hooks.my-cargo-check = { + enable = true; + description = "check the cargo package for errors."; + entry = "${rustToolchain}/bin/cargo check --offline"; + files = "\\.rs$"; + pass_filenames = false; + }; + + treefmt.projectRootFile = "flake.nix"; + treefmt.programs = { + rustfmt.enable = true; + alejandra.enable = true; + }; + treefmt.flakeFormatter = true; + + packages.aba2sat = pkgs.callPackage ./nix/packages/aba2sat.nix {inherit rustPlatform;}; + packages.default = self'.packages.aba2sat; + + devShells.default = pkgs.mkShell { + name = "aba2sat"; + shellHook = '' + ${config.pre-commit.installationScript} + # This is only used to prevent the literal name from appearing here, as the rename would find it! + oldName=$(echo 'change_my_name' | sed 's/_/-/g') + echo -e 1>&2 "\n\n Welcome to the development shell!" + stat "nix/packages/$oldName.nix" 2>/dev/null >/dev/null && echo -e 1>&2 "\n \033[31mChange this projects name with \033[1mrename NEW-NAME\033[0m" + echo -e 1>&2 "\n" + ''; + nativeBuildInputs = [ + config.treefmt.package + pkgs.cargo-workspaces + pkgs.nil + rustToolchain + rename + ]; + RUST_LOG = "trace"; + }; + devShells.pre-commit = config.pre-commit.devShell; + }; + }; +} diff --git a/nix/packages/aba2sat.nix b/nix/packages/aba2sat.nix new file mode 100644 index 0000000..85dadc7 --- /dev/null +++ b/nix/packages/aba2sat.nix @@ -0,0 +1,27 @@ +{ + rustPlatform, + lib, +}: let + config = lib.trivial.importTOML ../../Cargo.toml; +in + rustPlatform.buildRustPackage { + pname = config.package.name; + version = config.package.version; + + src = lib.sources.cleanSource ../..; + + cargoDeps = { + lockFile = "../../Cargo.lock"; + }; + + cargoLock = { + lockFile = ../../Cargo.lock; + }; + + meta = { + # description = "Awesome program description"; + # homepage = "https://your.new.homepage"; + # license = licenses.mit; + # maintainers = []; + }; + } diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}