Merge pull request #1 from jfroche/chore/nix-shell
Add nix shell & some checks
This commit is contained in:
commit
23e3dcf059
9 changed files with 398 additions and 27 deletions
6
.envrc
Normal file
6
.envrc
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
watch_file shell.nix
|
||||
watch_file flake.lock
|
||||
|
||||
# try to use flakes, if it fails use normal nix (ie. shell.nix)
|
||||
use flake || use nix
|
||||
eval "$shellHook"
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -6,3 +6,4 @@
|
|||
**/*.rs.bk
|
||||
|
||||
result
|
||||
.pre-commit-config.yaml
|
||||
|
|
|
|||
6
default.nix
Normal file
6
default.nix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(import
|
||||
(fetchTarball {
|
||||
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
|
||||
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
|
||||
})
|
||||
{ src = ./.; }).defaultNix
|
||||
245
flake.lock
generated
245
flake.lock
generated
|
|
@ -1,6 +1,56 @@
|
|||
{
|
||||
"nodes": {
|
||||
"devshell": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1671489820,
|
||||
"narHash": "sha256-qoei5HDJ8psd1YUPD7DhbHdhLIT9L2nadscp4Qk37uk=",
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"rev": "5aa3a8039c68b4bf869327446590f4cdf90bb634",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"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-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1642700792,
|
||||
"narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"locked": {
|
||||
"lastModified": 1667395993,
|
||||
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||
|
|
@ -15,7 +65,105 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_3": {
|
||||
"locked": {
|
||||
"lastModified": 1667395993,
|
||||
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_4": {
|
||||
"locked": {
|
||||
"lastModified": 1659877975,
|
||||
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gitignore": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"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-filter": {
|
||||
"locked": {
|
||||
"lastModified": 1666547822,
|
||||
"narHash": "sha256-razwnAybPHyoAyhkKCwXdxihIqJi1G6e1XP4FQOJTEs=",
|
||||
"owner": "numtide",
|
||||
"repo": "nix-filter",
|
||||
"rev": "1a3b735e13e90a8d2fd5629f2f8363bd7ffbbec7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "nix-filter",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1643381941,
|
||||
"narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-stable": {
|
||||
"locked": {
|
||||
"lastModified": 1673800717,
|
||||
"narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-22.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1675115703,
|
||||
"narHash": "sha256-4zetAPSyY0D77x+Ww9QBe8RHn1akvIvHJ/kgg8kGDbk=",
|
||||
|
|
@ -31,10 +179,103 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_3": {
|
||||
"locked": {
|
||||
"lastModified": 1671271357,
|
||||
"narHash": "sha256-xRJdLbWK4v2SewmSStYrcLa0YGJpleufl44A19XSW8k=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "40f79f003b6377bd2f4ed4027dde1f8f922995dd",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_4": {
|
||||
"locked": {
|
||||
"lastModified": 1665296151,
|
||||
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"pre-commit-hooks": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-utils": "flake-utils_3",
|
||||
"gitignore": "gitignore",
|
||||
"nixpkgs": "nixpkgs_3",
|
||||
"nixpkgs-stable": "nixpkgs-stable"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1675169698,
|
||||
"narHash": "sha256-C1wFiyJ+4SRvIsFkdMIN1Fa+58APmyTGKWpX9EKOehM=",
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"rev": "ce4efeec34c6eb35ba07b8fceaae87d6b46c1c5f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
"devshell": "devshell",
|
||||
"flake-utils": "flake-utils_2",
|
||||
"nix-filter": "nix-filter",
|
||||
"nixpkgs": "nixpkgs_2",
|
||||
"pre-commit-hooks": "pre-commit-hooks",
|
||||
"rust-overlay": "rust-overlay",
|
||||
"treefmt-nix": "treefmt-nix"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils_4",
|
||||
"nixpkgs": "nixpkgs_4"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1675218841,
|
||||
"narHash": "sha256-/aARbO0v7XlyFaG6vzYKp9ImG6pX5a8Ss4McQ4u9BJs=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "b86e094432c5576867b75a2834babf06aafd6c49",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"treefmt-nix": {
|
||||
"locked": {
|
||||
"lastModified": 1674470002,
|
||||
"narHash": "sha256-Tk1VaMeBTMMGEZeqv3TEwrTAdR9fYb3EH/TPI27AdKk=",
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"rev": "d5ed9a1e6793f99b2e179d5dec9639e48ef22db7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
113
flake.nix
113
flake.nix
|
|
@ -1,16 +1,119 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
|
||||
devshell.url = "github:numtide/devshell";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
nix-filter.url = "github:numtide/nix-filter";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
treefmt-nix.url = "github:numtide/treefmt-nix";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }: {
|
||||
serviceConfig = self.lib.makeServiceConfig {
|
||||
system = flake-utils.lib.system.x86_64-linux;
|
||||
outputs =
|
||||
{ self
|
||||
, nixpkgs
|
||||
, flake-utils
|
||||
, nix-filter
|
||||
, rust-overlay
|
||||
, devshell
|
||||
, treefmt-nix
|
||||
, pre-commit-hooks
|
||||
,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ (import rust-overlay) devshell.overlay ];
|
||||
};
|
||||
rust = pkgs.rust-bin.stable."1.64.0";
|
||||
llvm = pkgs.llvmPackages_latest;
|
||||
# treefmt-nix configuration
|
||||
treefmt.config = {
|
||||
projectRootFile = "flake.nix";
|
||||
programs = {
|
||||
nixpkgs-fmt.enable = true;
|
||||
rustfmt = {
|
||||
enable = true;
|
||||
package = rust.rustfmt;
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
rec {
|
||||
serviceConfig = lib.makeServiceConfig {
|
||||
inherit system;
|
||||
module = { imports = [ ./nix/modules ]; };
|
||||
};
|
||||
|
||||
lib = import ./nix/lib.nix { inherit nixpkgs; };
|
||||
|
||||
packages = rec {
|
||||
service-manager =
|
||||
pkgs.rustPlatform.buildRustPackage
|
||||
{
|
||||
pname = "service-manager";
|
||||
version = (pkgs.lib.importTOML ./Cargo.toml).package.version;
|
||||
|
||||
src = nix-filter.lib {
|
||||
root = ./.;
|
||||
include = [ "Cargo.toml" "Cargo.lock" (nix-filter.lib.inDirectory "src") ];
|
||||
};
|
||||
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
};
|
||||
default = service-manager;
|
||||
};
|
||||
devShells.default = pkgs.devshell.mkShell {
|
||||
packages = with pkgs; [
|
||||
llvm.clang
|
||||
openssl
|
||||
pkg-config
|
||||
rust.default
|
||||
(treefmt-nix.lib.mkWrapper pkgs treefmt.config)
|
||||
];
|
||||
env = [
|
||||
{
|
||||
name = "LIBCLANG_PATH";
|
||||
value = "${llvm.libclang}/lib";
|
||||
}
|
||||
{
|
||||
# for rust-anaylzer
|
||||
name = "RUST_SRC_PATH";
|
||||
value = "${rust.rust-src}";
|
||||
}
|
||||
{
|
||||
name = "RUST_BACKTRACE";
|
||||
value = "1";
|
||||
}
|
||||
{
|
||||
name = "RUST_LOG";
|
||||
value = "info";
|
||||
}
|
||||
{
|
||||
name = "DEVSHELL_NO_MOTD";
|
||||
value = "1";
|
||||
}
|
||||
];
|
||||
devshell.startup.pre-commit.text = self.checks.${system}.pre-commit-check.shellHook;
|
||||
};
|
||||
checks = {
|
||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
check-format = {
|
||||
enable = true;
|
||||
entry = "treefmt --fail-on-change";
|
||||
};
|
||||
cargo-clippy = {
|
||||
enable = true;
|
||||
description = "Lint Rust code.";
|
||||
entry = "cargo-clippy --workspace -- -D warnings";
|
||||
files = "\\.rs$";
|
||||
pass_filenames = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
|||
12
nix/lib.nix
12
nix/lib.nix
|
|
@ -3,7 +3,11 @@ let
|
|||
inherit (nixpkgs) lib;
|
||||
in
|
||||
{
|
||||
makeServiceConfig = { system, module }:
|
||||
makeServiceConfig =
|
||||
{ system
|
||||
, module
|
||||
,
|
||||
}:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
|
|
@ -12,13 +16,13 @@ in
|
|||
specialArgs = { };
|
||||
modules = [ module ];
|
||||
};
|
||||
services = lib.flip lib.genAttrs
|
||||
services =
|
||||
lib.flip lib.genAttrs
|
||||
(serviceName:
|
||||
nixosConfig.config.systemd.units."${serviceName}.service".unit)
|
||||
nixosConfig.config.service-manager.services;
|
||||
|
||||
servicesPath =
|
||||
pkgs.writeTextFile {
|
||||
servicesPath = pkgs.writeTextFile {
|
||||
name = "services";
|
||||
destination = "/services.json";
|
||||
text = lib.generators.toJSON { } services;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
{ lib, pkgs, ... }:
|
||||
|
||||
{ lib
|
||||
, pkgs
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
service-1 = "service-1";
|
||||
service-2 = "service-2";
|
||||
|
|
|
|||
8
shell.nix
Normal file
8
shell.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let
|
||||
compat = builtins.fetchTarball {
|
||||
url = "https://github.com/edolstra/flake-compat/archive/b4a34015c698c7793d592d66adbab377907a2be8.tar.gz";
|
||||
sha256 = "sha256:1qc703yg0babixi6wshn5wm2kgl5y1drcswgszh4xxzbrwkk9sv7";
|
||||
};
|
||||
in
|
||||
(import compat { src = ./.; }).shellNix.default
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
user, profile_name
|
||||
);
|
||||
|
||||
let flake_attr = "serviceConfig";
|
||||
let flake_attr = "serviceConfig.x86_64-linux";
|
||||
|
||||
let nix_build_output = run_nix_build(&args.flake_uri, flake_attr);
|
||||
|
||||
|
|
@ -69,9 +69,9 @@ fn create_gcroot(gcroot_path: &str, store_path: &StorePath) -> Result<(), Box<dy
|
|||
|
||||
fn get_store_path(nix_build_result: process::Output) -> Result<StorePath, Box<dyn Error>> {
|
||||
if nix_build_result.status.success() {
|
||||
return String::from_utf8(nix_build_result.stdout)
|
||||
String::from_utf8(nix_build_result.stdout)
|
||||
.map_err(Box::from)
|
||||
.map(StorePath::from);
|
||||
.map(StorePath::from)
|
||||
} else {
|
||||
String::from_utf8(nix_build_result.stderr).map_or_else(boxed_error(), boxed_error())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue