This commit is contained in:
Malte Tammena 2023-11-04 20:57:43 +01:00
commit ed22680db1
8 changed files with 446 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
.direnv
result*
target/
.pre-commit-config.yaml

7
Cargo.lock generated Normal file
View file

@ -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"

8
Cargo.toml Normal file
View file

@ -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]

263
flake.lock Normal file
View file

@ -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
}

133
flake.nix Normal file
View file

@ -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;
};
};
}

27
nix/packages/aba2sat.nix Normal file
View file

@ -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 = [];
};
}

3
src/main.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}