From e1f82972cc73520557a69aad073334be370c5102 Mon Sep 17 00:00:00 2001
From: Padok <singulosta@gmail.com>
Date: Wed, 19 Feb 2020 09:16:45 +0100
Subject: [PATCH] own nix derivation

---
 builder.sh      |  6 ++++++
 default.nix     | 45 +++++++++++++++++++++++++++++++--------------
 fuzz.nix        | 12 ++++++++++++
 fuzz_seconds.sh |  7 +++++++
 release.nix     | 33 ---------------------------------
 sudo            |  1 +
 6 files changed, 57 insertions(+), 47 deletions(-)
 create mode 100644 builder.sh
 create mode 100644 fuzz.nix
 delete mode 100644 release.nix
 create mode 100644 sudo

diff --git a/builder.sh b/builder.sh
new file mode 100644
index 0000000..4fbed6a
--- /dev/null
+++ b/builder.sh
@@ -0,0 +1,6 @@
+cp -r $src/* ./
+
+make
+
+mkdir -p $out/bin/
+cp calc $out/bin/rpn.calculator
\ No newline at end of file
diff --git a/default.nix b/default.nix
index 4bfbba6..c21a9c6 100644
--- a/default.nix
+++ b/default.nix
@@ -1,15 +1,32 @@
-with import (import ./nixpkgs.nix) {};
-stdenv.mkDerivation {
-  name = "rpn-calculator";
-  src = ./.;
-  buildInputs = [ catch2 ];
-  nativeBuildInputs = [ afl ];
-
-  doCheck = true;
-  checkTarget = "run_test";
-
-  installPhase = ''
-    mkdir -p $out
-    find . -executable -type f -exec cp {} $out \;
-  '';
+#with import (import ./nixpkgs.nix) {};
+with import <nixpkgs> {};
+
+
+derivation {
+    name = "build";
+    builder = "${pkgs.bash}/bin/bash";
+    args = [ ./builder.sh ];
+    system = builtins.currentSystem;
+    #PATH="${pkgs.coreutils}/bin/:${pkgs.gcc}/bin/:${pkgs.gnumake}/bin/";
+    PATH=pkgs.lib.strings.concatMapStringsSep ":" (x: x + "/bin") (with pkgs;[coreutils gcc gnumake]);
+    src = ./.;
 }
+
+
+/* pkgs.stdenv.mkDerivation {
+    name = "rpn-calc";
+    src = ./.;
+
+    buildInputs = with pkgs; [ afl ];
+    nativebuildInputs = with pkgs; [ afl ];
+    checkInputs = with pkgs; [ afl ];
+
+    buildPhase = ''
+        make fuzz_calc
+    '';
+
+    installPhase = ''
+        mkdir -p $out/bin
+        cp fuzz_calc $out/bin
+    '';
+} */
\ No newline at end of file
diff --git a/fuzz.nix b/fuzz.nix
new file mode 100644
index 0000000..cdc96a1
--- /dev/null
+++ b/fuzz.nix
@@ -0,0 +1,12 @@
+with import <nixpkgs> {};
+
+derivation {
+    name = "fuzz";
+    builder = "${pkgs.bash}/bin/bash";
+    args = [ ./fuzz_seconds.sh ];
+    system = builtins.currentSystem;
+    #PATH="${pkgs.coreutils}/bin/:${pkgs.gcc}/bin/:${pkgs.gnumake}/bin/";
+    PATH=pkgs.lib.strings.concatMapStringsSep ":" (x: x + "/bin") (with pkgs;[coreutils gcc gnumake afl]);
+    src = ./.;
+
+}
\ No newline at end of file
diff --git a/fuzz_seconds.sh b/fuzz_seconds.sh
index 6d328c6..4127f83 100755
--- a/fuzz_seconds.sh
+++ b/fuzz_seconds.sh
@@ -1,5 +1,8 @@
 #!/usr/bin/env bash
 
+cp -r $src/* ./
+make fuzz_calc
+
 fuzz_seconds=${1:-10} # 10 seconds by default
 echo "Going to fuzz for $fuzz_seconds seconds."
 
@@ -10,3 +13,7 @@ afl_pid=$!
 
 sleep $fuzz_seconds
 kill $afl_pid
+
+
+#mkdir -p $out/bin/
+cp -r out/ $out/
\ No newline at end of file
diff --git a/release.nix b/release.nix
deleted file mode 100644
index 7c2c457..0000000
--- a/release.nix
+++ /dev/null
@@ -1,33 +0,0 @@
-with import (import ./nixpkgs.nix) {};
-
-let
-  rpncalc = import ./default.nix;
-  afl_rpncalc = rpncalc.overrideAttrs (_: {
-    nativeBuildInputs = [ afl ];
-    makeFlags = [ "fuzz_calc" ];
-    doCheck = false;
-  });
-in {
-  inherit rpncalc afl_rpncalc;
-  sanitized = rpncalc.overrideAttrs (_: {
-    CXXFLAGS = "-fsanitize=undefined -fsanitize=address";
-  });
-
-  fuzz_rpncalc = afl_rpncalc.overrideAttrs (o: {
-    nativeBuildInputs = o.nativeBuildInputs ++ [ gnuplot which ];
-    preConfigure = ''
-      patchShebangs fuzz_seconds.sh
-    '';
-    postBuild = ''
-      ./fuzz_seconds.sh 10
-      afl-plot out graph
-    '';
-    installPhase = ''
-      cp -r out $out
-      cp -r graph $out/
-
-      mkdir -p $out/nix-support
-      echo report testlog $out graph/index.html > $out/nix-support/hydra-build-products
-    '';
-  });
-}
diff --git a/sudo b/sudo
new file mode 100644
index 0000000..c738c14
--- /dev/null
+++ b/sudo
@@ -0,0 +1 @@
+core tee /proc/sys/kernel/core_pattern
-- 
GitLab