flake-parts and new rust template
This commit is contained in:
parent
6610672cf8
commit
0c5d27a013
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
.direnv
|
||||
.pre-commit-config.yaml
|
70
flake.lock
70
flake.lock
|
@ -1,54 +1,60 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1644229661,
|
||||
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"fup": {
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils"
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1657226504,
|
||||
"narHash": "sha256-GIYNjuq4mJlFgqKsZ+YrgzWm0IpA4axA3MCrdKYj7gs=",
|
||||
"owner": "gytis-ivaskevicius",
|
||||
"repo": "flake-utils-plus",
|
||||
"rev": "2bf0f91643c2e5ae38c1b26893ac2927ac9bd82a",
|
||||
"lastModified": 1698882062,
|
||||
"narHash": "sha256-HkhafUayIqxXyHH1X8d9RDl1M2CkFgZLjKD3MzabiEo=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "8c9fa2545007b49a5db5f650ae91f227672c3877",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "gytis-ivaskevicius",
|
||||
"repo": "flake-utils-plus",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1692447944,
|
||||
"narHash": "sha256-fkJGNjEmTPvqBs215EQU4r9ivecV5Qge5cF/QDLVn3U=",
|
||||
"path": "/nix/store/s4jqyj35hii03rs7j5n6vn7gpgp6ja81-source",
|
||||
"rev": "d680ded26da5cf104dd2735a51e88d2d8f487b4d",
|
||||
"type": "path"
|
||||
"lastModified": 1699065553,
|
||||
"narHash": "sha256-j8UmH8fqXcOgL6WrlMcvV2m2XQ6OzU0IBucyuJ0vnyQ=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "8ab9c53eee434651ce170dee1d9727b974e9a6b6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"fup": "fup",
|
||||
"flake-parts": "flake-parts",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
|
|
220
flake.nix
220
flake.nix
|
@ -1,120 +1,142 @@
|
|||
{
|
||||
description = "A very basic flake";
|
||||
inputs.fup.url = "github:gytis-ivaskevicius/flake-utils-plus";
|
||||
description = "All things development";
|
||||
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs?ref=nixpkgs-unstable";
|
||||
|
||||
nixConfig = {
|
||||
nix = ["http://cache.home"];
|
||||
};
|
||||
|
||||
outputs = {
|
||||
outputs = inputs @ {
|
||||
flake-parts,
|
||||
self,
|
||||
fup,
|
||||
nixpkgs,
|
||||
...
|
||||
}:
|
||||
fup.lib.eachSystem [fup.lib.system.x86_64-linux] (system: let
|
||||
pkgs = import nixpkgs {inherit system;};
|
||||
flake-parts.lib.mkFlake {inherit inputs;} {
|
||||
systems = ["x86_64-linux"];
|
||||
perSystem = {
|
||||
config,
|
||||
self',
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
mdpls = let
|
||||
version = "30761508593d85b5743ae39c4209947740eec92d";
|
||||
in
|
||||
pkgs.rustPlatform.buildRustPackage {
|
||||
inherit version;
|
||||
pname = "mdpls";
|
||||
|
||||
mdpls = let
|
||||
version = "30761508593d85b5743ae39c4209947740eec92d";
|
||||
in
|
||||
pkgs.rustPlatform.buildRustPackage rec {
|
||||
inherit version;
|
||||
pname = "mdpls";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "euclio";
|
||||
repo = "mdpls";
|
||||
rev = version;
|
||||
sha256 = "sha256-4n1MX8hS7JmKzaL8GfMq2q3IdwE4fvMmWOYo7rY+cdY=";
|
||||
};
|
||||
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "euclio";
|
||||
repo = "mdpls";
|
||||
rev = version;
|
||||
sha256 = "sha256-4n1MX8hS7JmKzaL8GfMq2q3IdwE4fvMmWOYo7rY+cdY=";
|
||||
cargoSha256 = "sha256-J49A43BSCJGqaY7AX7XsoMwy6sgyaIx2Vz57Z1cFItc=";
|
||||
};
|
||||
|
||||
cargoSha256 = "sha256-J49A43BSCJGqaY7AX7XsoMwy6sgyaIx2Vz57Z1cFItc=";
|
||||
packagesSharedByAll = with pkgs; [
|
||||
diff-so-fancy
|
||||
];
|
||||
|
||||
scripts = {
|
||||
beste-schule-set-missing-grades = pkgs.writeShellApplication {
|
||||
name = "set-missing-grades";
|
||||
runtimeInputs = [
|
||||
pkgs.coreutils
|
||||
pkgs.jq
|
||||
pkgs.curl
|
||||
];
|
||||
text = builtins.readFile ./scripts/set-missing-grades.sh;
|
||||
};
|
||||
};
|
||||
|
||||
packagesSharedByAll = with pkgs; [
|
||||
diff-so-fancy
|
||||
];
|
||||
shells = {
|
||||
nix = {
|
||||
name = "generic nix";
|
||||
packages = with pkgs; [
|
||||
alejandra
|
||||
nil
|
||||
];
|
||||
};
|
||||
node = {
|
||||
name = "generic node";
|
||||
packages = with pkgs; [
|
||||
nodejs
|
||||
yarn
|
||||
nodePackages.vls
|
||||
nodePackages.typescript-language-server
|
||||
nodePackages.yaml-language-server
|
||||
nodePackages.vscode-json-languageserver-bin
|
||||
nodePackages.vscode-html-languageserver-bin
|
||||
nodePackages.vscode-css-languageserver-bin
|
||||
];
|
||||
};
|
||||
nodeIonic = {
|
||||
name = "generic node + ionic";
|
||||
packages =
|
||||
shells.node.packages
|
||||
++ (with pkgs; [
|
||||
android-studio
|
||||
]);
|
||||
};
|
||||
php = {
|
||||
name = "generic php";
|
||||
packages = with pkgs; [
|
||||
php
|
||||
phpPackages.composer
|
||||
];
|
||||
};
|
||||
nodePhp = {
|
||||
name = "generic node + php";
|
||||
packages = with shells; node.packages ++ php.packages;
|
||||
};
|
||||
python = {
|
||||
name = "generic python";
|
||||
packages = with pkgs; [
|
||||
python3Packages.python-lsp-server
|
||||
];
|
||||
};
|
||||
markdown = {
|
||||
name = "generic markdown";
|
||||
packages = [mdpls];
|
||||
};
|
||||
"beste-schule" = {
|
||||
name = "beste.schule";
|
||||
packages =
|
||||
[
|
||||
scripts.beste-schule-set-missing-grades
|
||||
]
|
||||
++ shells.nodePhp.packages;
|
||||
};
|
||||
};
|
||||
in {
|
||||
devShells = pkgs.lib.attrsets.mapAttrs (name: value:
|
||||
pkgs.mkShell (pkgs.lib.recursiveUpdate value {
|
||||
packages = value.packages ++ packagesSharedByAll;
|
||||
}))
|
||||
shells;
|
||||
|
||||
scripts = {
|
||||
beste-schule-set-missing-grades = pkgs.writeShellApplication {
|
||||
name = "set-missing-grades";
|
||||
runtimeInputs = [
|
||||
pkgs.coreutils
|
||||
pkgs.jq
|
||||
pkgs.curl
|
||||
];
|
||||
text = builtins.readFile ./scripts/set-missing-grades.sh;
|
||||
packages = {
|
||||
inherit mdpls;
|
||||
};
|
||||
};
|
||||
flake = {
|
||||
hydraJobs =
|
||||
builtins.mapAttrs (name: value: {
|
||||
x86_64-linux = value;
|
||||
})
|
||||
self.devShells.x86_64-linux;
|
||||
|
||||
shells = {
|
||||
nix = {
|
||||
name = "generic nix";
|
||||
packages = with pkgs; [
|
||||
alejandra
|
||||
nil
|
||||
];
|
||||
};
|
||||
node = {
|
||||
name = "generic node";
|
||||
packages = with pkgs; [
|
||||
nodejs
|
||||
yarn
|
||||
nodePackages.vls
|
||||
nodePackages.typescript-language-server
|
||||
nodePackages.yaml-language-server
|
||||
nodePackages.vscode-json-languageserver-bin
|
||||
nodePackages.vscode-html-languageserver-bin
|
||||
nodePackages.vscode-css-languageserver-bin
|
||||
];
|
||||
};
|
||||
nodeIonic = {
|
||||
name = "generic node + ionic";
|
||||
packages =
|
||||
shells.node.packages
|
||||
++ (with pkgs; [
|
||||
android-studio
|
||||
]);
|
||||
};
|
||||
php = {
|
||||
name = "generic php";
|
||||
packages = with pkgs; [
|
||||
php
|
||||
phpPackages.composer
|
||||
];
|
||||
};
|
||||
nodePhp = {
|
||||
name = "generic node + php";
|
||||
packages = with shells; node.packages ++ php.packages;
|
||||
};
|
||||
python = {
|
||||
name = "generic python";
|
||||
packages = with pkgs; [
|
||||
python3Packages.python-lsp-server
|
||||
];
|
||||
};
|
||||
markdown = {
|
||||
name = "generic markdown";
|
||||
packages = [mdpls];
|
||||
};
|
||||
"beste-schule" = {
|
||||
name = "beste.schule";
|
||||
packages = [
|
||||
scripts.beste-schule-set-missing-grades
|
||||
] ++ shells.nodePhp.packages;
|
||||
templates = {
|
||||
rust = {
|
||||
path = ./rust;
|
||||
description = "Simple Rust + Nix template";
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
devShells = pkgs.lib.attrsets.mapAttrs (name: value:
|
||||
pkgs.mkShell (pkgs.lib.recursiveUpdate value {
|
||||
packages = value.packages ++ packagesSharedByAll;
|
||||
}))
|
||||
shells;
|
||||
|
||||
hydraJobs = self.devShells.${system};
|
||||
|
||||
packages = {
|
||||
inherit mdpls;
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
1
rust/.envrc
Normal file
1
rust/.envrc
Normal file
|
@ -0,0 +1 @@
|
|||
use flake
|
4
rust/.gitignore
vendored
Normal file
4
rust/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
.direnv
|
||||
result*
|
||||
target/
|
||||
.pre-commit-config.yaml
|
7
rust/Cargo.lock
generated
Normal file
7
rust/Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "change-my-name"
|
||||
version = "0.1.0"
|
8
rust/Cargo.toml
Normal file
8
rust/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "change-my-name"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
263
rust/flake.lock
Normal file
263
rust/flake.lock
Normal 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
|
||||
}
|
128
rust/flake.nix
Normal file
128
rust/flake.nix
Normal file
|
@ -0,0 +1,128 @@
|
|||
{
|
||||
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
|
||||
];
|
||||
text = ''
|
||||
stat nix/packages/change-my-name.nix 2>/dev/null >/dev/null || echo "Can only be done once!"
|
||||
newName="$1"
|
||||
pushd "$(git rev-parse --show-toplevel)"
|
||||
fd --type f --exec sed "s/change-my-name/$newName/g" -i '{}'
|
||||
mv nix/packages/change-my-name.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.change-my-name = pkgs.callPackage ./nix/packages/change-my-name.nix {inherit rustPlatform;};
|
||||
packages.default = self'.packages.change-my-name;
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
name = "change-my-name";
|
||||
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
rust/nix/packages/change-my-name.nix
Normal file
27
rust/nix/packages/change-my-name.nix
Normal 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
rust/src/main.rs
Normal file
3
rust/src/main.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
Loading…
Reference in a new issue