switch to flakes
9 files changed, 122 insertions(+), 141 deletions(-)
A flake.lock
@@ -0,0 +1,85 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gomod2nix": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1745875161, + "narHash": "sha256-0YkWCS13jpoo3+sX/3kcgdxBNt1VZTmvF+FhZb4rFKI=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "2cbd7fdd6eeab65c494cc426e18f4e4d2a5e35c0", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1749285348, + "narHash": "sha256-frdhQvPbmDYaScPFiCnfdh3B/Vh81Uuoo0w5TkWmmjU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3e3afe5174c561dee0df6f2c2b2236990146329f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "gomod2nix": "gomod2nix", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +}
A flake.nix
@@ -0,0 +1,25 @@ +{ + description = "A basic gomod2nix flake"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.gomod2nix.url = "github:nix-community/gomod2nix"; + inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs"; + inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils"; + + outputs = { self, nixpkgs, flake-utils, gomod2nix }: + (flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + packages.default = pkgs.callPackage ./nix/package { + inherit (gomod2nix.legacyPackages.${system}) buildGoApplication; + }; + devShells.default = pkgs.callPackage ./shell.nix { + inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix; + }; + }) + ); +}
D nix/default.nix
@@ -1,80 +0,0 @@ -# Generated by npins. Do not modify; will be overwritten regularly -let - data = builtins.fromJSON (builtins.readFile ./sources.json); - version = data.version; - - mkSource = - spec: - assert spec ? type; - let - path = - if spec.type == "Git" then - mkGitSource spec - else if spec.type == "GitRelease" then - mkGitSource spec - else if spec.type == "PyPi" then - mkPyPiSource spec - else if spec.type == "Channel" then - mkChannelSource spec - else - builtins.throw "Unknown source type ${spec.type}"; - in - spec // { outPath = path; }; - - mkGitSource = - { - repository, - revision, - url ? null, - hash, - branch ? null, - ... - }: - assert repository ? type; - # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository - # In the latter case, there we will always be an url to the tarball - if url != null then - (builtins.fetchTarball { - inherit url; - sha256 = hash; # FIXME: check nix version & use SRI hashes - }) - else - assert repository.type == "Git"; - let - urlToName = - url: rev: - let - matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url; - - short = builtins.substring 0 7 rev; - - appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; - in - "${if matched == null then "source" else builtins.head matched}${appendShort}"; - name = urlToName repository.url revision; - in - builtins.fetchGit { - url = repository.url; - rev = revision; - inherit name; - # hash = hash; - }; - - mkPyPiSource = - { url, hash, ... }: - builtins.fetchurl { - inherit url; - sha256 = hash; - }; - - mkChannelSource = - { url, hash, ... }: - builtins.fetchTarball { - inherit url; - sha256 = hash; - }; -in -if version == 3 then - builtins.mapAttrs (_: mkSource) data.pins -else - throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
D nix/overlay.nix
@@ -1,12 +0,0 @@ -{ - nixpkgs.overlays = - let - sources = import ./default.nix; - in - [ - (import "${sources.gomod2nix}/overlay.nix") - (self: super: { - elgit = super.callPackage ./package { }; - }) - ]; -}
M nix/package/default.nix → nix/package/default.nix
@@ -1,10 +1,11 @@ { pkgs ? ( let - sources = import ../default.nix; + inherit (builtins) fetchTree fromJSON readFile; + inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix; in - import sources.nixpkgs { + import (fetchTree nixpkgs.locked) { overlays = [ - (import "${sources.gomod2nix}/overlay.nix") + (import "${fetchTree gomod2nix.locked}/overlay.nix") ]; } )
D nix/sources.json
@@ -1,32 +0,0 @@ -{ - "pins": { - "gomod2nix": { - "type": "GitRelease", - "repository": { - "type": "GitHub", - "owner": "nix-community", - "repo": "gomod2nix" - }, - "pre_releases": false, - "version_upper_bound": null, - "release_prefix": null, - "version": "v1.6.0", - "revision": "5d387097aa716f35dd99d848dc26d8d5b62a104c", - "url": "https://api.github.com/repos/nix-community/gomod2nix/tarball/v1.6.0", - "hash": "1mdwyjz43nnh7gfq4rc54kql6fy65hw17w0p4gwklnfqciwrkax2" - }, - "nixpkgs": { - "type": "Git", - "repository": { - "type": "GitHub", - "owner": "nixos", - "repo": "nixpkgs" - }, - "branch": "master", - "revision": "9ccb4b4245696a98a30a8d7e28e7c6ac1892c397", - "url": "https://github.com/nixos/nixpkgs/archive/9ccb4b4245696a98a30a8d7e28e7c6ac1892c397.tar.gz", - "hash": "1ph49sllariml2996klf1kcyd332a33fp7p23scb4zvagh17hd2j" - } - }, - "version": 3 -}
M shell.nix → shell.nix
@@ -1,23 +1,25 @@ { pkgs ? ( let - sources = import ./nix/default.nix; + inherit (builtins) fetchTree fromJSON readFile; + inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix; in - import sources.nixpkgs { + import (fetchTree nixpkgs.locked) { overlays = [ - (import "${sources.gomod2nix}/overlay.nix") + (import "${fetchTree gomod2nix.locked}/overlay.nix") ]; } ) +, mkGoEnv ? pkgs.mkGoEnv +, gomod2nix ? pkgs.gomod2nix }: let - goEnv = pkgs.mkGoEnv { pwd = ./.; }; + goEnv = mkGoEnv { pwd = ./.; }; in pkgs.mkShell { packages = with pkgs; [ goEnv gomod2nix - npins modd just ];