From 759483247eab2ceee46ff64a3e73daa2a908e016 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Tue, 14 Jun 2022 17:35:19 +0800 Subject: [PATCH] Align flake template with recent API changes and improvements --- shell.nix | 10 ++-------- templates/app/default.nix | 18 ++++++++++++++---- templates/app/shell.nix | 18 ++++++++++++++++-- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/shell.nix b/shell.nix index 62be6c2..a33b65d 100644 --- a/shell.nix +++ b/shell.nix @@ -1,14 +1,8 @@ { pkgs ? ( let - inherit (builtins) fromJSON readFile; - flakeLock = fromJSON (readFile ./flake.lock); - locked = flakeLock.nodes.nixpkgs.locked; - nixpkgs = assert locked.type == "github"; builtins.fetchTarball { - url = "https://github.com/${locked.owner}/${locked.repo}/archive/${locked.rev}.tar.gz"; - sha256 = locked.narHash; - }; + inherit (builtins) fetchTree fromJSON readFile; in - import nixpkgs { + import (fetchTree (fromJSON (readFile ./flake.lock)).nodes.nixpkgs.locked) { overlays = [ (import ./overlay.nix) ]; diff --git a/templates/app/default.nix b/templates/app/default.nix index 17efdcd..2c29bbc 100644 --- a/templates/app/default.nix +++ b/templates/app/default.nix @@ -1,10 +1,20 @@ -{ buildGoApplication, go, lib }: +{ pkgs ? ( + let + inherit (builtins) fetchTree fromJSON readFile; + inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix; + in + import (fetchTree nixpkgs.locked) { + overlays = [ + (import "${fetchTree gomod2nix.locked}/overlay.nix") + ]; + } + ) +}: -buildGoApplication { - inherit go; +pkgs.buildGoApplication { pname = "myapp"; version = "0.1"; + pwd = ./.; src = ./.; modules = ./gomod2nix.toml; - subPackages = [ "." ]; } diff --git a/templates/app/shell.nix b/templates/app/shell.nix index 8fcd820..b8e49a9 100644 --- a/templates/app/shell.nix +++ b/templates/app/shell.nix @@ -1,8 +1,22 @@ -{ pkgs ? import { } }: +{ pkgs ? ( + let + inherit (builtins) fetchTree fromJSON readFile; + inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix; + in + import (fetchTree nixpkgs.locked) { + overlays = [ + (import "${fetchTree gomod2nix.locked}/overlay.nix") + ]; + } + ) +}: +let + goEnv = pkgs.mkGoEnv { pwd = ./.; }; +in pkgs.mkShell { packages = [ - pkgs.go + goEnv pkgs.gomod2nix ]; }