diff --git a/flake.nix b/flake.nix index b6726ec..4366f33 100644 --- a/flake.nix +++ b/flake.nix @@ -8,62 +8,27 @@ outputs = { self, nixpkgs, utils }: { + overlay = final: prev: + let scripts = prev.callPackage ./scripts.nix { }; in + { + inherit (scripts) format update test-develop dvt; + }; + templates = import ./templates.nix; } // utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system; }; - - inherit (pkgs) mkShell writeScriptBin; - - run = pkg: "${pkgs.${pkg}}/bin/${pkg}"; - - dvt = writeScriptBin "dvt" - '' - if [ -z $1 ]; then - echo "no template specified" - exit 1 - fi - TEMPLATE=$1 - ${run "nix"} \ - --experimental-features 'nix-command flakes' \ - flake init \ - --template \ - "github:efishery/dvt#''${TEMPLATE}" - ''; - - format = writeScriptBin "format" - '' - ${run "nixpkgs-fmt"} **/*.nix - ''; - - update = writeScriptBin "update" - '' - for dir in `ls -d */`; do - ( - cd $dir - ${run "nix"} flake update # Update flake.lock - ${run "nix"} develop $dir # Make sure this work after update - ) - done - ''; - - test-develop = writeScriptBin "test-develop" - '' - for dir in `ls -d */`; do - ( - ${run "nix"} develop $dir # Make sure this work after update - sleep 0.2 - ) - done - ''; + overlays = [ (self.overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; in { - devShells.default = mkShell { buildInputs = [ format update ]; }; + devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ format update ]; }; packages = { - default = dvt; - inherit dvt test-develop; + dvt-init = pkgs.dvt; + dvt-format = pkgs.format; + dvt-update = pkgs.update; + inherit (pkgs) test-develop; }; }); } diff --git a/scripts.nix b/scripts.nix new file mode 100644 index 0000000..b17dd52 --- /dev/null +++ b/scripts.nix @@ -0,0 +1,43 @@ +{ writeScriptBin, nix, nixpkgs-fmt }: +{ + update = writeScriptBin "update" + '' + for dir in `ls -d */`; do + ( + cd $dir + ${nix}/bin/nix flake update # Update flake.lock + ${nix}/bin/nix develop $dir # Make sure this work after update + ) + done + ''; + + test-develop = writeScriptBin "test-develop" + '' + for dir in `ls -d */`; do + ( + ${nix}/bin/nix develop $dir # Make sure this work after update + sleep 0.2 + ) + done + ''; + + format = writeScriptBin "format" + '' + ${nixpkgs-fmt}/bin/nixpkgs-fmt **/*.nix + ''; + + dvt = writeScriptBin "dvt" + '' + if [ -z $1 ]; then + echo "no template specified" + exit 1 + fi + TEMPLATE=$1 + ${nix}/bin/nix \ + --experimental-features 'nix-command flakes' \ + flake init \ + --template \ + "github:efishery/dvt#''${TEMPLATE}" + ''; +} +