build: don't use fetchurl to get IANA service names for Nix

As the file may change, even the latest tagged version of flake.nix
won't work to build Akvorado. Instead, rely on an unofficial Git
repository.

Fix #2043
This commit is contained in:
Vincent Bernat
2025-10-25 15:17:10 +02:00
parent 9aac56d0d1
commit af19f6de39
5 changed files with 35 additions and 22 deletions

View File

@@ -67,6 +67,6 @@ runs:
path: | path: |
orchestrator/clickhouse/data/udp.csv orchestrator/clickhouse/data/udp.csv
orchestrator/clickhouse/data/tcp.csv orchestrator/clickhouse/data/tcp.csv
key: iana-cache-${{ hashFiles('Makefile', 'nix/ianaServiceNamesHash.txt') }}-${{ github.run_id }} key: iana-cache-${{ hashFiles('Makefile', 'flake.lock') }}-${{ github.run_id }}
restore-keys: | restore-keys: |
iana-cache-${{ hashFiles('Makefile', 'nix/ianaServiceNamesHash.txt') }}- iana-cache-${{ hashFiles('Makefile', 'flake.lock') }}-

View File

@@ -15,6 +15,7 @@ jobs:
source: source:
- nixpkgs - nixpkgs
- asn2org - asn2org
- iana-assignments
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
with: with:

17
flake.lock generated
View File

@@ -35,6 +35,22 @@
"type": "github" "type": "github"
} }
}, },
"iana-assignments": {
"flake": false,
"locked": {
"lastModified": 1761359241,
"narHash": "sha256-Q/bkxeQJFELXd+4Ma50PliUimIPiMBeGhC6nFUUDOzc=",
"owner": "larseggert",
"repo": "iana-assignments",
"rev": "597006e11311b3ebee998d86ab862955c5e7d6ce",
"type": "github"
},
"original": {
"owner": "larseggert",
"repo": "iana-assignments",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1760164275, "lastModified": 1760164275,
@@ -53,6 +69,7 @@
"inputs": { "inputs": {
"asn2org": "asn2org", "asn2org": "asn2org",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"iana-assignments": "iana-assignments",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
}, },

View File

@@ -6,8 +6,12 @@
url = "github:vincentbernat/asn2org/gh-pages"; url = "github:vincentbernat/asn2org/gh-pages";
flake = false; flake = false;
}; };
iana-assignments = {
url = "github:larseggert/iana-assignments";
flake = false;
};
}; };
outputs = { self, nixpkgs, flake-utils, asn2org }: outputs = { self, nixpkgs, flake-utils, asn2org, iana-assignments }:
flake-utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = import nixpkgs { pkgs = import nixpkgs {
@@ -42,17 +46,15 @@
cp -r ../data/frontend $out/data cp -r ../data/frontend $out/data
''; '';
}; };
ianaServiceNames = pkgs.fetchurl { ianaServiceNames = pkgs.runCommand "service-names-port-numbers.csv" {} ''
url = "https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv"; > $out echo name,port,protocol
hash = l.readFile ./nix/ianaServiceNamesHash.txt; >> $out \
# There are many bogus changes in this file. To avoid updating the ${pkgs.xmlstarlet}/bin/xmlstarlet sel -t -m "_:registry/_:record[_:name and _:number]" \
# hash too often, filter the lines with a service name and a port. -v _:name -o , \
downloadToTemp = true; -v _:number -o , \
postFetch = '' -v _:protocol -o , -n \
< $downloadedFile > $out \ ${iana-assignments}/service-names-port-numbers/service-names-port-numbers.xml
awk -F, '(NR == 1) {print} ($0 !~ "^ " && $1 != "" && $2 != "" && ($3 == "tcp" || $3 == "udp")) {print}' '';
'';
};
backend = pkgs.buildGoModule.override { inherit go; } { backend = pkgs.buildGoModule.override { inherit go; } {
doCheck = false; doCheck = false;
name = "akvorado"; name = "akvorado";
@@ -103,15 +105,9 @@
| ${pkgs.gnused}/bin/sed -nE "s/\s+got:\s+(sha256-.*)/\1/p") | ${pkgs.gnused}/bin/sed -nE "s/\s+got:\s+(sha256-.*)/\1/p")
[[ -z "$sha256" ]] && echo $oldSha256 || echo $sha256 > nix/npmDepsHash.txt [[ -z "$sha256" ]] && echo $oldSha256 || echo $sha256 > nix/npmDepsHash.txt
''; '';
update-ianaServiceNamesHash = ''
sha256=$(2>&1 nix build --no-link .#ianaServiceNames \
| ${pkgs.gnused}/bin/sed -nE "s/\s+got:\s+(sha256-.*)/\1/p")
[[ -z "$sha256" ]] || echo $sha256 > nix/ianaServiceNamesHash.txt
'';
update = '' update = ''
${update-vendorHash} ${update-vendorHash}
${update-npmDepsHash} ${update-npmDepsHash}
${update-ianaServiceNamesHash}
''; '';
# Run nix build depending on TARGETPLATFORM value (for Docker). # Run nix build depending on TARGETPLATFORM value (for Docker).
build = '' build = ''
@@ -130,7 +126,7 @@
}; };
packages = { packages = {
inherit backend frontend ianaServiceNames; inherit backend frontend;
default = backend; default = backend;
} // (l.optionalAttrs (system == "x86_64-linux") } // (l.optionalAttrs (system == "x86_64-linux")
(l.attrsets.listToAttrs (l.lists.map (l.attrsets.listToAttrs (l.lists.map

View File

@@ -1 +0,0 @@
sha256-MMTJRwpFEvXDHxp+OXbpwTa6aUNd0JXvR6KMwymKiTo=