diff --git a/.gitignore b/.gitignore index cb094d2..d7eca0c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .env* !.env.example + +.direnv diff --git a/flake.lock b/flake.lock index cf24a6b..5230800 100644 --- a/flake.lock +++ b/flake.lock @@ -1,39 +1,6 @@ { "nodes": { - "naersk": { - "inputs": { - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1655042882, - "narHash": "sha256-9BX8Fuez5YJlN7cdPO63InoyBy7dm3VlJkkmTt6fS1A=", - "owner": "nix-community", - "repo": "naersk", - "rev": "cddffb5aa211f50c4b8750adbec0bbbdfb26bb9f", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "master", - "repo": "naersk", - "type": "github" - } - }, "nixpkgs": { - "locked": { - "lastModified": 1659190188, - "narHash": "sha256-LudYrDFPFaQMW0l68TYkPWRPKmqpxIFU1nWfylIp9AQ=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "a3fddd46a7f3418d7e3940ded94701aba569161d", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "nixpkgs_2": { "locked": { "lastModified": 1659190188, "narHash": "sha256-LudYrDFPFaQMW0l68TYkPWRPKmqpxIFU1nWfylIp9AQ=", @@ -51,8 +18,7 @@ }, "root": { "inputs": { - "naersk": "naersk", - "nixpkgs": "nixpkgs_2", + "nixpkgs": "nixpkgs", "utils": "utils" } }, diff --git a/flake.nix b/flake.nix index 7338eaf..e4f2ccb 100644 --- a/flake.nix +++ b/flake.nix @@ -1,46 +1,41 @@ { inputs = { - naersk.url = "github:nix-community/naersk/master"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, utils, naersk }: - utils.lib.eachDefaultSystem (system: - let - name = "vnetod"; - pkgs = import nixpkgs { inherit system; }; - naersk-lib = pkgs.callPackage naersk { }; - in - rec { - # Executes by `nix build .#` - packages = { - ${name} = naersk.lib.${system}.buildPackage { - pname = name; - root = ./.; - }; - }; - # Executes by `nix build .` - packages.default = packages.${name}; - # the same but deprecated in Nix 2.7 - defaultPackage = packages.default; + outputs = { self, nixpkgs, utils }: + let + cargoToml = with builtins; (fromTOML (readFile ./Cargo.toml)); - # Executes by `nix run .# -- ` - apps = { - ${name} = utils.lib.mkApp { - inherit name; - drv = packages.${name}; - }; - }; - # Executes by `nix run . -- ` - apps.default = apps.${name}; - # the same but deprecated in Nix 2.7 - defaultApp = apps.default; + version = "${cargoToml.package.version}_${builtins.substring 0 8 self.lastModifiedDate}_${self.shortRev or "dirty"}"; + in + utils.lib.eachDefaultSystem + (system: + let + inherit (nixpkgs) lib; + pkgs = import nixpkgs { inherit system; }; - # Used by `nix develop` - devShell = with pkgs; mkShell { - buildInputs = [ cargo rustc rustfmt pre-commit rustPackages.clippy ]; - RUST_SRC_PATH = rustPlatform.rustLibSrc; - }; - }); + vnetod = pkgs.rustPlatform.buildRustPackage { + name = "vnetod-${version}"; + + src = lib.cleanSource ./.; + cargoLock.lockFile = ./Cargo.lock; + + doCheck = true; + }; + in + { + apps.default = { + type = "app"; + program = "${vnetod}/bin/vnetod"; + }; + + packages.default = vnetod; + + devShell = pkgs.mkShell { + packages = with pkgs; [ cargo rustc rustfmt clippy rust-analyzer ]; + RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; + }; + }); }