From 2a7b36213c1b8bc9e03466bd7b99fa96abfecd8f Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Mon, 26 Sep 2022 17:50:41 -0700 Subject: feat(naersk): use naersk to build packages with rust naersk makes it simple to build rust project in nix. For this to work, `mkSystem` and `mkHomeManagerConfiguration` needs to pass naersk to my overlays. I dropped the support to run the tools with `nix run .#tools...`: I don't use this in practice and it's not making things simpler. I dropped `nix-linter` from the check, it's reporting many errors without helping me to fix them. --- flake.lock | 33 ++++++++++++++++++++++++++++++++- flake.nix | 4 ++-- nix/mkHomeManagerConfiguration.nix | 10 ++++++++-- nix/mkSystem.nix | 12 +++++++----- tools/default.nix | 2 ++ tools/sendsms/default.nix | 3 +-- 6 files changed, 52 insertions(+), 12 deletions(-) diff --git a/flake.lock b/flake.lock index cfd012e..726c936 100644 --- a/flake.lock +++ b/flake.lock @@ -105,6 +105,24 @@ "type": "github" } }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1662220400, + "narHash": "sha256-9o2OGQqu4xyLZP9K6kNe1pTHnyPz0Wr3raGYnr9AIgY=", + "owner": "nix-community", + "repo": "naersk", + "rev": "6944160c19cb591eb85bbf9b2f2768a935623ed3", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 0, @@ -134,6 +152,18 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 0, + "narHash": "sha256-eyzwPTQqB9l/viI769epK8NwGOY8v/c2TNrRmcX5u+8=", + "path": "/nix/store/gp0lyg85c6ilj65xbipkqn96crnypb0f-source", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1663707118, "narHash": "sha256-eyzwPTQqB9l/viI769epK8NwGOY8v/c2TNrRmcX5u+8=", @@ -194,7 +224,8 @@ "emacs-overlay": "emacs-overlay", "futils": "futils", "home-manager": "home-manager", - "nixpkgs": "nixpkgs_2", + "naersk": "naersk", + "nixpkgs": "nixpkgs_3", "nixpkgs-unstable": "nixpkgs-unstable", "nur": "nur", "pre-commit-hooks": "pre-commit-hooks", diff --git a/flake.nix b/flake.nix index 7e8280e..2bfcf2e 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,8 @@ emacs-overlay.url = "github:nix-community/emacs-overlay"; + naersk.url = "github:nix-community/naersk"; + agenix = { url = "github:ryantm/agenix"; inputs.nixpkgs.follows = "nixpkgs"; @@ -62,7 +64,6 @@ pre-commit-check = inputs.pre-commit-hooks.lib."${system}".run { src = ./.; hooks = { - nix-linter.enable = true; nixpkgs-fmt.enable = true; terraform-format.enable = true; trailing-whitespace = { @@ -133,7 +134,6 @@ in { inherit (inputs.futils.lib) filterPackages flattenTree; - tools = import ./tools { inherit pkgs; }; ops = import ./ops { inherit pkgs; }; users.fcuny = import ./users/fcuny { inherit pkgs; }; }); diff --git a/nix/mkHomeManagerConfiguration.nix b/nix/mkHomeManagerConfiguration.nix index bcf374a..70e875d 100644 --- a/nix/mkHomeManagerConfiguration.nix +++ b/nix/mkHomeManagerConfiguration.nix @@ -3,9 +3,11 @@ inputs@{ self, ... }: , username ? "fcuny" , hostname , stateVersion ? "22.05" -, extraModules ? [ ] , }: +let + naersk = inputs.naersk.lib."${system}"; +in inputs.home-manager.lib.homeManagerConfiguration { inherit system; inherit username; @@ -19,8 +21,12 @@ inputs.home-manager.lib.homeManagerConfiguration { overlays = [ inputs.emacs-overlay.overlay inputs.nur.overlay + inputs.naersk.overlay inputs.rust.overlays.default - (final: prev: { tools = import "${self}/tools" { pkgs = prev; }; }) + (final: prev: + { + tools = import "${self}/tools" { pkgs = prev; inherit naersk; }; + }) ]; }; configuration.imports = diff --git a/nix/mkSystem.nix b/nix/mkSystem.nix index 00b5664..4debbab 100644 --- a/nix/mkSystem.nix +++ b/nix/mkSystem.nix @@ -1,5 +1,8 @@ inputs@{ self, ... }: { system ? "x86_64-linux", hostname, }: +let + naersk = inputs.naersk.lib."${system}"; +in inputs.nixpkgs.lib.nixosSystem { inherit system; specialArgs = { inherit inputs system hostname; }; @@ -14,13 +17,12 @@ inputs.nixpkgs.lib.nixosSystem { overlays = [ inputs.nur.overlay inputs.rust.overlays.default - (final: prev: { tools = import "${self}/tools" { pkgs = prev; }; }) + (final: prev: + { + tools = import "${self}/tools" { pkgs = prev; inherit naersk; }; + }) ]; }; - # Add each input as a registry - nix.registry = inputs.nixpkgs.lib.mapAttrs' - (n: v: inputs.nixpkgs.lib.nameValuePair (n) ({ flake = v; })) - inputs; } ]; } diff --git a/tools/default.nix b/tools/default.nix index fc60a7e..9f6d273 100644 --- a/tools/default.nix +++ b/tools/default.nix @@ -10,4 +10,6 @@ pkgs.lib.makeScope pkgs.newScope (pkgs: { ipconverter = pkgs.callPackage ./ipconverter { }; git-blame-stats = pkgs.callPackage ./git-blame-stats { }; + + sendsms = pkgs.callPackage ./sendsms { }; }) diff --git a/tools/sendsms/default.nix b/tools/sendsms/default.nix index 6c9b79c..17c6b5a 100644 --- a/tools/sendsms/default.nix +++ b/tools/sendsms/default.nix @@ -1,6 +1,6 @@ { pkgs, naersk, ... }: -naersk.lib."${pkgs.system}".buildPackage { +naersk.buildPackage { src = builtins.filterSource (path: type: type != "directory" || builtins.baseNameOf path != "target") @@ -11,5 +11,4 @@ naersk.lib."${pkgs.system}".buildPackage { remapPathPrefix = true; doCheck = true; - copyLibs = true; } -- cgit 1.4.1