From 127ed335af5ca9f348bd5e6cef883a85587d96fc Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 29 Jul 2022 00:42:22 +0200 Subject: [PATCH] Add helper scripts via Nix --- .envrc | 1 + dhall/flake.lock | 6 +-- dhall/flake.nix | 24 ++++++----- flake.lock | 42 +++++++++++++++++++ flake.nix | 105 +++++++++++++++++++++++++++++----------------- gleam/flake.lock | 6 +-- go1.17/flake.lock | 6 +-- go1.18/flake.lock | 6 +-- java/flake.lock | 6 +-- nix/.envrc | 1 + nix/flake.lock | 6 +-- nix/flake.nix | 18 ++++---- node/flake.lock | 6 +-- rust/flake.lock | 6 +-- scala/flake.lock | 6 +-- update.sh | 9 ---- zig/flake.lock | 6 +-- 17 files changed, 164 insertions(+), 96 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock delete mode 100755 update.sh diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/dhall/flake.lock b/dhall/flake.lock index d88584a..871676c 100644 --- a/dhall/flake.lock +++ b/dhall/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659047146, - "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "lastModified": 1659047633, + "narHash": "sha256-zeI+NkJOa665fRrKGpjscfy3Hs4K316q1q7394xbRbw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "rev": "496caa738a16d2bb3607243d9127df718bb50513", "type": "github" }, "original": { diff --git a/dhall/flake.nix b/dhall/flake.nix index c00ae90..bdaa08b 100644 --- a/dhall/flake.nix +++ b/dhall/flake.nix @@ -15,17 +15,19 @@ inherit (pkgs.lib) optionals; inherit (pkgs.stdenv) isLinux; - otherFormats = with pkgs.haskellPackages; [ - dhall-bash - dhall-docs - dhall-json - dhall-lsp-server - dhall-nix - dhall-nixpkgs - dhall-openapi - dhall-toml - dhall-yaml - ] ++ optionals isLinux (with pkgs.haskellPackages; [ dhall-csv dhall-haskell dhall-text ]); + otherFormats = with pkgs.haskellPackages; + [ + dhall-bash + dhall-docs + dhall-json + dhall-lsp-server + dhall-nix + dhall-nixpkgs + dhall-openapi + dhall-toml + dhall-yaml + ] ++ optionals isLinux + (with pkgs.haskellPackages; [ dhall-csv dhall-haskell dhall-text ]); inherit (pkgs) mkShell; in { diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d88584a --- /dev/null +++ b/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1656928814, + "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1659047146, + "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index c35cb00..6bd3379 100644 --- a/flake.nix +++ b/flake.nix @@ -2,52 +2,81 @@ description = "Ready-made templates for easily creating flake-driven environments"; - outputs = { self }: { - templates = { - gleam = { - path = ./gleam; - description = "Gleam development environment"; - }; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; - go_1_17 = { - path = ./go1.17; - description = "Go 1.17 development environment"; - }; + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + inherit (pkgs) mkShell; + format = pkgs.writeScriptBin "format" '' + ${pkgs.nixfmt}/bin/nixfmt **/*.nix + ''; + update = pkgs.writeScriptBin "update" '' + for dir in `ls -d */`; do # Iterate through all the templates + ( + cd $dir + ${pkgs.nix}/bin/nix flake update # Update flake.lock + ${pkgs.direnv}/bin/direnv reload # Make sure things work after the update + ) + done + ''; + in { + devShells = { + default = mkShell { + buildInputs = with pkgs; [ format update ]; + }; + }; + } + ) // { + templates = { + gleam = { + path = ./gleam; + description = "Gleam development environment"; + }; - go_1_18 = { - path = ./go1.18; - description = "Go 1.18 development environment"; - }; + go_1_17 = { + path = ./go1.17; + description = "Go 1.17 development environment"; + }; - java = { - path = ./java; - description = "Java development environment"; - }; + go_1_18 = { + path = ./go1.18; + description = "Go 1.18 development environment"; + }; - nix = { - path = ./nix; - description = "Nix development environment"; - }; + java = { + path = ./java; + description = "Java development environment"; + }; - node = { - path = ./node; - description = "Node.js development environment"; - }; + nix = { + path = ./nix; + description = "Nix development environment"; + }; - rust = { - path = ./rust; - description = "Rust development environment"; - }; + node = { + path = ./node; + description = "Node.js development environment"; + }; - scala = { - path = ./scala; - description = "Scala development environment"; - }; + rust = { + path = ./rust; + description = "Rust development environment"; + }; - zig = { - path = ./zig; - description = "Zig development environment"; + scala = { + path = ./scala; + description = "Scala development environment"; + }; + + zig = { + path = ./zig; + description = "Zig development environment"; + }; }; }; - }; } diff --git a/gleam/flake.lock b/gleam/flake.lock index d88584a..871676c 100644 --- a/gleam/flake.lock +++ b/gleam/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659047146, - "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "lastModified": 1659047633, + "narHash": "sha256-zeI+NkJOa665fRrKGpjscfy3Hs4K316q1q7394xbRbw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "rev": "496caa738a16d2bb3607243d9127df718bb50513", "type": "github" }, "original": { diff --git a/go1.17/flake.lock b/go1.17/flake.lock index d88584a..871676c 100644 --- a/go1.17/flake.lock +++ b/go1.17/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659047146, - "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "lastModified": 1659047633, + "narHash": "sha256-zeI+NkJOa665fRrKGpjscfy3Hs4K316q1q7394xbRbw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "rev": "496caa738a16d2bb3607243d9127df718bb50513", "type": "github" }, "original": { diff --git a/go1.18/flake.lock b/go1.18/flake.lock index d88584a..871676c 100644 --- a/go1.18/flake.lock +++ b/go1.18/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659047146, - "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "lastModified": 1659047633, + "narHash": "sha256-zeI+NkJOa665fRrKGpjscfy3Hs4K316q1q7394xbRbw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "rev": "496caa738a16d2bb3607243d9127df718bb50513", "type": "github" }, "original": { diff --git a/java/flake.lock b/java/flake.lock index d88584a..871676c 100644 --- a/java/flake.lock +++ b/java/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659047146, - "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "lastModified": 1659047633, + "narHash": "sha256-zeI+NkJOa665fRrKGpjscfy3Hs4K316q1q7394xbRbw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "rev": "496caa738a16d2bb3607243d9127df718bb50513", "type": "github" }, "original": { diff --git a/nix/.envrc b/nix/.envrc index a5dbbcb..03f8b73 100644 --- a/nix/.envrc +++ b/nix/.envrc @@ -1 +1,2 @@ use flake . +use flake . diff --git a/nix/flake.lock b/nix/flake.lock index d88584a..871676c 100644 --- a/nix/flake.lock +++ b/nix/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659047146, - "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "lastModified": 1659047633, + "narHash": "sha256-zeI+NkJOa665fRrKGpjscfy3Hs4K316q1q7394xbRbw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "rev": "496caa738a16d2bb3607243d9127df718bb50513", "type": "github" }, "original": { diff --git a/nix/flake.nix b/nix/flake.nix index bf66139..309d849 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -14,18 +14,20 @@ nix = pkgs.nixUnstable; dhallNix = pkgs.haskellPackages.dhall-nix; - helpers = with pkgs; [ cachix dhallNix lorri niv nixfmt nixpkgs-fmt statix ]; + nixRelatedTools = with pkgs; [ + cachix + dhallNix + lorri + niv + nixfmt + nixpkgs-fmt + statix + ]; inherit (pkgs) mkShell; in { devShells = { - default = pkgs.mkShell { - buildInputs = [ nix ] ++ helpers; - - shellHook = '' - ${nix}/bin/nix --version - ''; - }; + default = pkgs.mkShell { buildInputs = [ nix ] ++ nixRelatedTools; }; }; }); } diff --git a/node/flake.lock b/node/flake.lock index d88584a..871676c 100644 --- a/node/flake.lock +++ b/node/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659047146, - "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "lastModified": 1659047633, + "narHash": "sha256-zeI+NkJOa665fRrKGpjscfy3Hs4K316q1q7394xbRbw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "rev": "496caa738a16d2bb3607243d9127df718bb50513", "type": "github" }, "original": { diff --git a/rust/flake.lock b/rust/flake.lock index aa40f7f..652a69c 100644 --- a/rust/flake.lock +++ b/rust/flake.lock @@ -32,11 +32,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659047146, - "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "lastModified": 1659047633, + "narHash": "sha256-zeI+NkJOa665fRrKGpjscfy3Hs4K316q1q7394xbRbw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "rev": "496caa738a16d2bb3607243d9127df718bb50513", "type": "github" }, "original": { diff --git a/scala/flake.lock b/scala/flake.lock index d88584a..871676c 100644 --- a/scala/flake.lock +++ b/scala/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659047146, - "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "lastModified": 1659047633, + "narHash": "sha256-zeI+NkJOa665fRrKGpjscfy3Hs4K316q1q7394xbRbw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "rev": "496caa738a16d2bb3607243d9127df718bb50513", "type": "github" }, "original": { diff --git a/update.sh b/update.sh deleted file mode 100755 index c33c3e1..0000000 --- a/update.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -for dir in `ls -d */`; do # Iterate through all the templates - ( - cd $dir - nix flake update # Update flake.lock - direnv reload # Make sure things work after the update - ) -done diff --git a/zig/flake.lock b/zig/flake.lock index d88584a..871676c 100644 --- a/zig/flake.lock +++ b/zig/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659047146, - "narHash": "sha256-2qZemVRDR5oCw0Hd32LQSWC7FaEy5sUp5ih9OxqE3yU=", + "lastModified": 1659047633, + "narHash": "sha256-zeI+NkJOa665fRrKGpjscfy3Hs4K316q1q7394xbRbw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "68716026a095a765c09ec29f06ba234a0298418c", + "rev": "496caa738a16d2bb3607243d9127df718bb50513", "type": "github" }, "original": {