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

Applying Nix best practices and useful paradigms #92

Merged
merged 29 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4a910e4
feat: Introduce flake.parts and treefmt
brianmcgee Nov 8, 2023
51a33f6
feat: Force package builds during check
brianmcgee Nov 8, 2023
6034a34
feat: Re-introduce repology packages
brianmcgee Nov 8, 2023
1d53374
feat: Re-introduce nixupdate packages
brianmcgee Nov 8, 2023
1a77835
feat: Re-introduce sbomnix package
brianmcgee Nov 8, 2023
1fad967
feat: Re-introduce vulnxscan packages
brianmcgee Nov 8, 2023
4be5beb
chore: Ignore .idea
brianmcgee Nov 8, 2023
a6058fb
feat: Move devshell config into flake
brianmcgee Nov 8, 2023
9f2d273
feat: Introduce flake-compat
brianmcgee Nov 8, 2023
6ee6107
feat: Set meta.mainProgram
brianmcgee Nov 8, 2023
429657c
feat: Set meta.mainProgram
brianmcgee Nov 8, 2023
fbf64c1
chore: Apply reuse for copyright headers
brianmcgee Nov 8, 2023
7ded5c6
feat: Add reuse lint to flake checks
brianmcgee Nov 8, 2023
fcb4c69
feat: Add nix-fast-build
brianmcgee Nov 8, 2023
5fdf547
feat: Enable shellcheck in treefmt
brianmcgee Nov 8, 2023
42f22e7
chore: Ignore .direnv directory
brianmcgee Nov 8, 2023
2bfe262
feat: Direnv check if flakes are enabled
brianmcgee Nov 8, 2023
70b62b2
chore: Update nix-fast-build input
brianmcgee Nov 8, 2023
af3f73a
fix: Remove unnecessary drv env variables
brianmcgee Nov 9, 2023
bb7f726
feat: Switch to nix-community flake-compat
brianmcgee Nov 9, 2023
6c320d9
feat: Replace nix-visualize with upstream
brianmcgee Nov 9, 2023
b991dd6
fix: Remove output packages from devshell
brianmcgee Nov 9, 2023
4478e12
feat: Simplify packages and apps
brianmcgee Nov 9, 2023
42fb4f6
feat: Replace lib.flatten with concatenation
brianmcgee Nov 10, 2023
3815c67
chore: Add context for vulnix fork
brianmcgee Nov 10, 2023
5ef104c
fix: Formatting
brianmcgee Nov 11, 2023
24a3dff
fix: Apps comment
brianmcgee Nov 11, 2023
f61703c
fix: Devshell
brianmcgee Nov 11, 2023
fbe307d
fix: Apps nix_outdated and repology_xxx
brianmcgee Nov 11, 2023
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
10 changes: 10 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2023 Technology Innovation Institute (TII)
#
# SPDX-License-Identifier: Apache-2.0

# try to use flake initially, fallback to non-flake use otherwise
if nix flake show &> /dev/null; then
use flake
else
use nix
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ result
/*.pdf
/*.dot
/*.svg
.idea
.direnv
9 changes: 9 additions & 0 deletions LICENSES/MIT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 changes: 18 additions & 26 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
# SPDX-FileCopyrightText: 2023 Technology Innovation Institute (TII)
# SPDX-FileCopyrightText: 2020-2023 Eelco Dolstra and the flake-compat contributors
#
# SPDX-License-Identifier: Apache-2.0
{
pkgs ? import <nixpkgs> {},
pythonPackages ? pkgs.python3Packages,
}:
# SPDX-License-Identifier: MIT
# This file originates from:
# https://github.com/nix-community/flake-compat
# This file provides backward compatibility to nix < 2.4 clients
{system ? builtins.currentSystem}: let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);

pythonPackages.buildPythonPackage rec {
pname = "sbomnix";
version = pkgs.lib.removeSuffix "\n" (builtins.readFile ./VERSION);
format = "setuptools";
inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;

src = ./.;
makeWrapperArgs = [
"--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.nix pkgs.graphviz ]}"
];
flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};

propagatedBuildInputs = [
pkgs.reuse
pythonPackages.colorlog
pythonPackages.graphviz
pythonPackages.numpy
pythonPackages.packageurl-python
pythonPackages.packaging
pythonPackages.pandas
pythonPackages.requests
pythonPackages.tabulate
];
pythonImportsCheck = [ "sbomnix" ];
}
flake = import flake-compat {
inherit system;
src = ./.;
};
in
flake.defaultNix
168 changes: 167 additions & 1 deletion flake.lock

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

106 changes: 44 additions & 62 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,51 @@
{
description = "Flakes file for sbomnix";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

outputs = { self, nixpkgs }:
let
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
# forEachSystem [ "x86_64-linux" ] { example = true; } -> { x86_64-linux.example = true }
forEachSystem = nixpkgs.lib.genAttrs systems;
# Imports a module expecting a system to be passed in
importExpectingSystem = module: system: import module {
pkgs = import nixpkgs { inherit system; };
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-root.url = "github:srid/flake-root";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# For preserving compatibility with non-Flake users
flake-compat = {
url = "github:nix-community/flake-compat";
flake = false;
};
nix-fast-build = {
url = "github:Mic92/nix-fast-build";
# re-use some existing inputs
inputs = {
flake-parts.follows = "flake-parts";
treefmt-nix.follows = "treefmt-nix";
};
vulnxscan = importExpectingSystem ./scripts/vulnxscan/vulnxscan.nix;
repology_cli = importExpectingSystem ./scripts/repology/repology_cli.nix;
nixupdate = importExpectingSystem ./scripts/nixupdate/nixupdate.nix;
sbomnix = importExpectingSystem ./default.nix;
sbomnix-shell = importExpectingSystem ./shell.nix;
in
{
# nix package
packages = forEachSystem (system: {
repology_cli = repology_cli system;
nixupdate = nixupdate system;
vulnxscan = vulnxscan system;
sbomnix = sbomnix system;
default = sbomnix system;
});

apps = forEachSystem (system: {
# nix run .#sbomnix
sbomnix = {
type = "app";
program = "${self.packages.${system}.sbomnix}/bin/sbomnix";
};

# nix run .#nixgraph
nixgraph = {
type = "app";
program = "${self.packages.${system}.sbomnix}/bin/nixgraph";
};

# nix run .#vulnxscan
vulnxscan = {
type = "app";
program = "${self.packages.${system}.vulnxscan}/bin/vulnxscan.py";
};

# nix run .#repology_cli
repology_cli = {
type = "app";
program = "${self.packages.${system}.repology_cli}/bin/repology_cli.py";
};

# nix run .#nix_outdated
nix_outdated = {
type = "app";
program = "${self.packages.${system}.nixupdate}/bin/nix_outdated.py";
};

});
};
nix-visualize = {
url = "github:craigmbooth/nix-visualize";
flake = false;
};
vulnix = {
url = "github:henrirosten/vulnix";
flake = false;
};
};

# nix develop
devShells = forEachSystem (system: {
default = sbomnix-shell system;
});
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake
{
inherit inputs;
} {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];

imports = [
./nix
];
};
}
1 change: 1 addition & 0 deletions githooks/check-commits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SDIR="$(realpath "$SDIR")"

TMPF="/tmp/TEMP.MSG"

# shellcheck disable=SC2317
function On_exit {
rm -f "$TMPF"
}
Expand Down
Loading