Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove flake-inputs; refactor and split out package #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 4 additions & 38 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 31 additions & 60 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
utils.url = "github:numtide/flake-utils";
# the rpki-client binary will be built from the flake at this URL.
rpki-cli.url = "github:asmap/rpki-client-nix";
};

outputs = {
self,
nixpkgs,
utils,
rpki-cli,
}:
# Add a kartograf module for NixOS (see module.nix for details)
{ nixosModules.kartograf = import ./module.nix self; } //
# Build for all default systems: ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]
utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
}: let
forAllSystems = nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];

rpki-client = rpki-cli.defaultPackage.${system};
pythonBuildDeps = pkgs.python311.withPackages (ps: [
ps.beautifulsoup4
ps.pandas
ps.requests
ps.tqdm
]);
nixpkgsFor = system: import nixpkgs { inherit system;};
in {
# This flake exposes the following attributes:
# * A development shell containing the rpki-client and the necessary
# Python env and packages to run kartograf. To use, run 'nix develop'
# in the current directory.
# * A default/kartograf package
# * A NixOS module
devShells.default = forAllSystems (system: let
pkgs = nixpkgsFor system;
pythonDevDeps = pkgs.python311.withPackages (ps: [
ps.beautifulsoup4
ps.pandas
Expand All @@ -35,51 +37,20 @@
ps.requests
ps.tqdm
]);
kartografDeps = [
pythonBuildDeps
rpki-client
];
in {
# This flake exposes the following attributes:
# * A development shell containing the rpki-client and the necessary
# Python env and packages to run kartograf. To use, run 'nix develop'
# in the current directory.
# * A default/kartograf package
# * A NixOS module
devShells.default = pkgs.mkShell {
packages = [rpki-client pythonDevDeps];
};
packages = {
kartograf = pkgs.stdenv.mkDerivation {
# not a python-installable package, so just manually copy files
pname = "kartograf";
version = "1.0.0";
src = ./.;
nativeBuildInputs = [pkgs.makeWrapper];
buildInputs = kartografDeps;
propagatedBuildInputs = [rpki-client];
buildPhase = ''
mkdir -p $out/lib/kartograf
cp -r ${./kartograf}/* $out/lib/kartograf/
'';
installPhase = ''
mkdir -p $out/bin
cp ${./run} $out/bin/kartograf
chmod +x $out/bin/kartograf
'';
fixupPhase = ''
wrapProgram $out/bin/kartograf \
--set PYTHONPATH $out/lib:$PYTHONPATH
wrapProgram $out/bin/kartograf \
--set PATH ${rpki-cli.defaultPackage.${system}}/bin:$PATH
'';
meta = with pkgs.lib; {
description = "Kartograf: IP to ASN mapping for everyone";
license = licenses.mit;
homepage = "https://github.com/asmap/kartograf";
};
};
default = self.packages.${system}.kartograf;
in
pkgs.mkShell {
packages = [pythonDevDeps rpki-cli.defaultPackage.${system}];
});

packages = forAllSystems (system: let
pkgs = nixpkgsFor system;
in rec {
kartograf = pkgs.callPackage ./package.nix {
rpki-client = rpki-cli.defaultPackage.${system};
};
default = kartograf;
});

nixosModules.default = import ./module.nix;
};
}
3 changes: 1 addition & 2 deletions module.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
flake: { config, pkgs, lib, ... }:
{ config, pkgs, lib, ... }:

with lib;

let
inherit (flake.packages.${pkgs.stdenv.hostPlatform.system}) kartograf;
cfg = config.services.kartograf;
postScript = pkgs.writeScriptBin "post-script" /* bash */ ''
#!/${pkgs.bash}/bin/bash
Expand Down
38 changes: 38 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{pkgs, rpki-client }:
let
pythonBuildDeps = pkgs.python311.withPackages (ps: [
ps.beautifulsoup4
ps.pandas
ps.requests
ps.tqdm
]);
in
pkgs.stdenv.mkDerivation {
# not a python-installable package, so just manually copy files
pname = "kartograf";
version = "1.0.0";
src = ./.;
nativeBuildInputs = [pkgs.makeWrapper];
buildInputs = [ pythonBuildDeps ];
propagatedBuildInputs = [ rpki-client ];
buildPhase = ''
mkdir -p $out/lib/kartograf
cp -r ${./kartograf}/* $out/lib/kartograf/
'';
installPhase = ''
mkdir -p $out/bin
cp ${./run} $out/bin/kartograf
chmod +x $out/bin/kartograf
'';
fixupPhase = ''
wrapProgram $out/bin/kartograf \
--set PYTHONPATH $out/lib:$PYTHONPATH
wrapProgram $out/bin/kartograf \
--set PATH ${rpki-client}/bin:$PATH
'';
meta = with pkgs.lib; {
description = "Kartograf: IP to ASN mapping for everyone";
license = licenses.mit;
homepage = "https://github.com/asmap/kartograf";
};
}
Loading