build: replace flake with npins, gomod2nix and just
Alan Pearce alan@alanpearce.eu
Sun, 30 Mar 2025 22:41:23 +0200
10 files changed, 287 insertions(+), 91 deletions(-)
M config.yaml → config.yaml
@@ -1,5 +1,5 @@ repo: - root: /tmp/gitolite + root: /Users/alan/gitolite/ readme: - readme - README
A default.nix
@@ -0,0 +1,41 @@+{ pkgs ? ( + let + sources = import ./nix/default.nix; + in + import sources.nixpkgs { + overlays = [ + (import "${sources.gomod2nix}/overlay.nix") + ]; + } + ) +}: +let + inherit (pkgs) buildGoApplication lib nixosTests; +in +buildGoApplication { + pname = "elgit"; + version = "unstable-2025-03-30"; + + src = ./.; + modules = ./nix/gomod2nix.toml; + + vendorHash = "sha256-NrJXVOfWcxm9Jt6++d2x2uS5AGEJ7plJK4ZnbFC4GTg="; + + postInstall = '' + mkdir -p $out/lib/elgit/templates + mkdir -p $out/lib/elgit/static + + cp -r $src/templates/* $out/lib/elgit/templates + cp -r $src/static/* $out/lib/elgit/static + ''; + + passthru.tests = { inherit (nixosTests) legit; }; + + meta = { + description = "Web frontend for git"; + homepage = "https://elgit.alanpearce.eu/elgit"; + license = lib.licenses.mit; + maintainers = [ lib.maintainers.alanpearce ]; + mainProgram = "elgit"; + }; +}
D flake.lock
@@ -1,26 +0,0 @@-{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1743277699, - "narHash": "sha256-po7cvIuCN/gdwye1JMfCscbg6OF/jG5bYJ0uiRfhLb0=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "9a856c9bc78008593fc53688be81549c56547467", - "type": "github" - }, - "original": { - "owner": "nixos", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -}
D flake.nix
@@ -1,63 +0,0 @@-{ - description = "web frontend for git"; - - inputs.nixpkgs.url = "github:nixos/nixpkgs"; - - outputs = - { self - , nixpkgs - , - }: - let - supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); - in - { - packages = forAllSystems (system: - let - pkgs = nixpkgsFor.${system}; - elgit = self.packages.${system}.elgit; - files = pkgs.lib.fileset.toSource { - root = ./.; - fileset = pkgs.lib.fileset.unions [ - ./config.yaml - ./static - ./templates - ]; - }; - in - { - elgit = pkgs.buildGoModule { - name = "elgit"; - rev = "master"; - src = ./.; - - vendorHash = "sha256-ynv0pBdVPIhTz7RvCwVWr0vUWwfw+PEjFXs9PdQMqm8="; - }; - docker = pkgs.dockerTools.buildLayeredImage { - name = "sini:5000/elgit"; - tag = "latest"; - contents = [ files elgit pkgs.git ]; - config = { - Entrypoint = [ "${elgit}/bin/elgit" ]; - ExposedPorts = { "5555/tcp" = { }; }; - }; - }; - }); - - defaultPackage = forAllSystems (system: self.packages.${system}.elgit); - devShells = forAllSystems (system: - let - pkgs = nixpkgsFor.${system}; - in - { - default = pkgs.mkShell { - nativeBuildInputs = with pkgs; [ - go - modd - ]; - }; - }); - }; -}
A nix/default.nix
@@ -0,0 +1,80 @@+# 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`"
A nix/gomod2nix.toml
@@ -0,0 +1,98 @@+schema = 3 + +[mod] + [mod."github.com/Microsoft/go-winio"] + version = "v0.6.2" + hash = "sha256-tVNWDUMILZbJvarcl/E7tpSnkn7urqgSHa2Eaka5vSU=" + [mod."github.com/ProtonMail/go-crypto"] + version = "v1.1.5" + hash = "sha256-N5Zn0f/NF3ezyGou2kRw9BwM25feJqnp7TPkRt6oK6I=" + [mod."github.com/acomagu/bufpipe"] + version = "v1.0.4" + hash = "sha256-gO76ADEf7bzVUhmZbRU/LNA+L9qCdb/aaAAavvj26mA=" + [mod."github.com/alecthomas/chroma/v2"] + version = "v2.14.0" + hash = "sha256-d+zcIobMS5Y0/Ym9Uxubf20uyw0aBCr0f1oEOAGHlEA=" + [mod."github.com/aymerick/douceur"] + version = "v0.2.0" + hash = "sha256-NiBX8EfOvLXNiK3pJaZX4N73YgfzdrzRXdiBFe3X3sE=" + [mod."github.com/bluekeyes/go-gitdiff"] + version = "v0.8.0" + hash = "sha256-vKRxdwRcu941/8G5ZL5CszLCpBBzvj6GaTqUPwPoUK8=" + [mod."github.com/cloudflare/circl"] + version = "v1.6.0" + hash = "sha256-a+SVfnHYC8Fb+NQLboNg5P9sry+WutzuNetVHFVAAo0=" + [mod."github.com/cyphar/filepath-securejoin"] + version = "v0.4.1" + hash = "sha256-NOV6MfbkcQbfhNmfADQw2SJmZ6q1nw0wwg8Pm2tf2DM=" + [mod."github.com/dimfeld/httptreemux/v5"] + version = "v5.5.0" + hash = "sha256-jlIAxbGCSBefloquqvMJG1KDAsSA28HYCrkmlzMABws=" + [mod."github.com/dlclark/regexp2"] + version = "v1.11.4" + hash = "sha256-1uCoCYCKyP8QZddlYfJCTWmcrKlEFNCsxWwMde9MspE=" + [mod."github.com/dustin/go-humanize"] + version = "v1.0.1" + hash = "sha256-yuvxYYngpfVkUg9yAmG99IUVmADTQA0tMbBXe0Fq0Mc=" + [mod."github.com/emirpasic/gods"] + version = "v1.18.1" + hash = "sha256-hGDKddjLj+5dn2woHtXKUdd49/3xdsqnhx7VEdCu1m4=" + [mod."github.com/go-git/gcfg"] + version = "v1.5.1-0.20230307220236-3a3c6141e376" + hash = "sha256-f4k0gSYuo0/q3WOoTxl2eFaj7WZpdz29ih6CKc8Ude8=" + [mod."github.com/go-git/go-billy/v5"] + version = "v5.6.2" + hash = "sha256-VgbxcLkHjiSyRIfKS7E9Sn8OynCrMGUDkwFz6K2TVL4=" + [mod."github.com/go-git/go-git/v5"] + version = "v5.6.1" + hash = "sha256-8HbSt4yX7B2ozSFj8Beoo05GcHb8/rBt/6ILkoTEtd8=" + replaced = "github.com/go-git/go-git/v5" + [mod."github.com/gorilla/css"] + version = "v1.0.1" + hash = "sha256-6JwNHqlY2NpZ0pSQTyYPSpiNqjXOdFHqrUT10sv3y8A=" + [mod."github.com/imdario/mergo"] + version = "v0.3.16" + hash = "sha256-gh2TEAq8YrZOEAf6SFW4AIcEEUguD68G+7/VUnBeWwM=" + [mod."github.com/jbenet/go-context"] + version = "v0.0.0-20150711004518-d14ea06fba99" + hash = "sha256-VANNCWNNpARH/ILQV9sCQsBWgyL2iFT+4AHZREpxIWE=" + [mod."github.com/kevinburke/ssh_config"] + version = "v1.2.0" + hash = "sha256-Ta7ZOmyX8gG5tzWbY2oES70EJPfI90U7CIJS9EAce0s=" + [mod."github.com/microcosm-cc/bluemonday"] + version = "v1.0.27" + hash = "sha256-EZSya9FLPQ83CL7N2cZy21fdS35hViTkiMK5f3op8Es=" + [mod."github.com/pjbgf/sha1cd"] + version = "v0.3.2" + hash = "sha256-jdbiRhU8xc1C5c8m7BSCj71PUXHY3f7TWFfxDKKpUMk=" + [mod."github.com/russross/blackfriday/v2"] + version = "v2.1.0" + hash = "sha256-R+84l1si8az5yDqd5CYcFrTyNZ1eSYlpXKq6nFt4OTQ=" + [mod."github.com/sergi/go-diff"] + version = "v1.1.0" + hash = "sha256-8NJMabldpf40uwQN20T6QXx5KORDibCBJL02KD661xY=" + replaced = "github.com/sergi/go-diff" + [mod."github.com/skeema/knownhosts"] + version = "v1.3.1" + hash = "sha256-kjqQDzuncQNTuOYegqVZExwuOt/Z73m2ST7NZFEKixI=" + [mod."github.com/xanzy/ssh-agent"] + version = "v0.3.3" + hash = "sha256-l3pGB6IdzcPA/HLk93sSN6NM2pKPy+bVOoacR5RC2+c=" + [mod."go.alanpearce.eu/gomponents"] + version = "v1.4.0" + hash = "sha256-Q8YN8eNouMnW/JaBJpjUmaOZ5cfBj5gFURgVlbnaiDM=" + [mod."golang.org/x/crypto"] + version = "v0.33.0" + hash = "sha256-U+a1nWirvCWHR5FDzXZZSCa/lUCHkmJoStbdjd8DnVY=" + [mod."golang.org/x/net"] + version = "v0.35.0" + hash = "sha256-kCLhhvzHQCvUqC8kGhgMbVLUROG4ZeZNVGOVVv6tSAE=" + [mod."golang.org/x/sys"] + version = "v0.30.0" + hash = "sha256-BuhWtwDkciVioc03rxty6G2vcZVnPX85lI7tgQOFVP8=" + [mod."gopkg.in/warnings.v0"] + version = "v0.1.2" + hash = "sha256-ATVL9yEmgYbkJ1DkltDGRn/auGAjqGOfjQyBYyUo8s8=" + [mod."gopkg.in/yaml.v3"] + version = "v3.0.1" + hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU="
A nix/sources.json
@@ -0,0 +1,32 @@+{ + "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 +}
A shell.nix
@@ -0,0 +1,24 @@+{ pkgs ? ( + let + sources = import ./nix/default.nix; + in + import sources.nixpkgs { + overlays = [ + (import "${sources.gomod2nix}/overlay.nix") + ]; + } + ) +}: + +let + goEnv = pkgs.mkGoEnv { pwd = ./.; }; +in +pkgs.mkShell { + packages = with pkgs; [ + goEnv + gomod2nix + npins + modd + just + ]; +}