diff --git a/default.nix b/default.nix index 91740dd..cac246f 100644 --- a/default.nix +++ b/default.nix @@ -1,51 +1,36 @@ { - pkgsAttrs ? (import ./nix/pkgs.nix), - bootstrap ? null, - releaseName ? "debug", + pkgs, + garage, + selfRev, + hostSystem, + #buildSystem, -}: let +}: rec { - pkgs = pkgsAttrs.pkgs; - -in rec { - - rootedBootstrap = pkgs.stdenv.mkDerivation { - name = "cryptic-net-rooted-bootstrap"; - - src = bootstrap; - - builder = builtins.toFile "builder.sh" '' - source $stdenv/setup - mkdir -p "$out"/share - cp "$src" "$out"/share/bootstrap.yml - ''; - }; + inherit garage; version = pkgs.stdenv.mkDerivation { name = "cryptic-net-version"; - buildInputs = [ pkgs.git pkgs.go ]; + inherit selfRev hostSystem; + src = ./version.txt; + garageVersion = garage.version; - src = ./.; - inherit releaseName; - nixPkgsVersion = pkgsAttrs.version; - nixPkgsRev = pkgsAttrs.rev; - builtByUser = builtins.getEnv "USER"; + nativeBuildInputs = [ pkgs.go ]; builder = builtins.toFile "builder.sh" '' source $stdenv/setup versionFile=version - cp -r "$src" srcCp + cat "$src" >> "$versionFile" + echo "" >> "$versionFile" - echo "Release: $releaseName" >> "$versionFile" - echo "Git Revision: $(cd srcCp && git rev-parse HEAD)" >> "$versionFile" - echo "Build date: $(date) ($(date +%s))" >> "$versionFile" - echo "Built by: $builtByUser" >> "$versionFile" - echo "Go version: $(go version)" >> "$versionFile" - echo "Nixpkgs version: $nixPkgsVersion ($nixPkgsRev)" >> "$versionFile" + echo "System: $hostSystem" >> "$versionFile" + echo "Git Revision: $selfRev" >> "$versionFile" + echo "Go Version: $(go version)" >> "$versionFile" + echo "Garage Version: $garageVersion" >> "$versionFile" mkdir -p "$out"/share cp "$versionFile" "$out"/share @@ -55,15 +40,11 @@ in rec { entrypoint = pkgs.callPackage ./entrypoint {}; dnsmasq = (pkgs.callPackage ./nix/dnsmasq.nix { - glibcStatic = pkgs.glibc.static; + stdenv = pkgs.pkgsStatic.stdenv; }); nebula = pkgs.callPackage ./nix/nebula.nix {}; - garage = (pkgs.callPackage ./nix/garage.nix {}).env; - - waitFor = pkgs.callPackage ./nix/wait-for.nix {}; - appDir = pkgs.buildEnv { name = "cryptic-net-AppDir"; paths = [ @@ -75,7 +56,7 @@ in rec { garage entrypoint - ] ++ (if bootstrap != null then [ rootedBootstrap ] else []); + ]; }; appimagetool = pkgs.callPackage ./nix/appimagetool.nix {}; @@ -84,7 +65,7 @@ in rec { name = "cryptic-net-AppImage"; src = appDir; - buildInputs = [ appimagetool ]; + nativeBuildInputs = [ appimagetool ]; ARCH = "x86_64"; @@ -92,21 +73,23 @@ in rec { source $stdenv/setup cp -rL "$src" cryptic-net chmod +w cryptic-net -R - appimagetool cryptic-net "$out" + + mkdir -p "$out/bin" + appimagetool cryptic-net "$out/bin/cryptic-net" ''; }; release = pkgs.stdenv.mkDerivation { - name = "cryptic-net-AppImage"; - inherit appImage releaseName; + name = "cryptic-net-release"; + inherit appImage; - buildInputs = [ pkgs.coreutils ]; + nativeBuildInputs = [ pkgs.coreutils ]; builder = builtins.toFile "build.sh" '' source $stdenv/setup mkdir -p "$out" - cp "$appImage" "$out"/cryptic-net-$releaseName-linux-amd64 + cp "$appImage" "$out"/cryptic-net (cd "$out" && sha256sum * > sha256.txt) ''; }; diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a701460 --- /dev/null +++ b/flake.lock @@ -0,0 +1,163 @@ +{ + "nodes": { + "cargo2nix": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "garage", + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1666087781, + "narHash": "sha256-trKVdjMZ8mNkGfLcY5LsJJGtdV3xJDZnMVrkFjErlcs=", + "owner": "Alexis211", + "repo": "cargo2nix", + "rev": "a7a61179b66054904ef6a195d8da736eaaa06c36", + "type": "github" + }, + "original": { + "owner": "Alexis211", + "repo": "cargo2nix", + "rev": "a7a61179b66054904ef6a195d8da736eaaa06c36", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "garage": { + "inputs": { + "cargo2nix": "cargo2nix", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1672666365, + "narHash": "sha256-lpNp/jw4YaczG3NM3pVWR0cZ8u/KBQCWvvfAswO4+Do=", + "ref": "main", + "rev": "76230f20282e73a5a5afa33af68152acaf732cf5", + "revCount": 1007, + "type": "git", + "url": "https://git.deuxfleurs.fr/Deuxfleurs/garage.git" + }, + "original": { + "ref": "main", + "rev": "76230f20282e73a5a5afa33af68152acaf732cf5", + "type": "git", + "url": "https://git.deuxfleurs.fr/Deuxfleurs/garage.git" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1665657542, + "narHash": "sha256-mojxNyzbvmp8NtVtxqiHGhRfjCALLfk9i/Uup68Y5q8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a3073c49bc0163fea6a121c276f526837672b555", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a3073c49bc0163fea6a121c276f526837672b555", + "type": "github" + } + }, + "pkgsSrc": { + "locked": { + "lastModified": 1672580127, + "narHash": "sha256-3lW3xZslREhJogoOkjeZtlBtvFMyxHku7I/9IVehhT8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0874168639713f547c05947c76124f78441ea46c", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-22.05", + "type": "indirect" + } + }, + "root": { + "inputs": { + "garage": "garage", + "pkgsSrc": "pkgsSrc", + "utils": "utils" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "garage", + "cargo2nix", + "flake-utils" + ], + "nixpkgs": [ + "garage", + "cargo2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1664247556, + "narHash": "sha256-J4vazHU3609ekn7dr+3wfqPo5WGlZVAgV7jfux352L0=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "524db9c9ea7bc7743bb74cdd45b6d46ea3fcc2ab", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ad7e848 --- /dev/null +++ b/flake.nix @@ -0,0 +1,53 @@ +{ + + inputs.pkgsSrc.url = "nixpkgs/nixos-22.05"; + + inputs.utils.url = "github:numtide/flake-utils"; + + # v0.8.1 + inputs.garage.url = "git+https://git.deuxfleurs.fr/Deuxfleurs/garage.git?ref=main&rev=76230f20282e73a5a5afa33af68152acaf732cf5"; + + description = "cryptic-net provides the foundation for an autonomous community +cloud infrastructure"; + + outputs = { + + self, pkgsSrc, utils, garage, + + }: let + + supportedSystems = [ + "x86_64-linux" + #"aarch64-linux" + #"armv7l-linux" # rpi, I think? + #"i686-linux" + ]; + + in utils.lib.eachSystem supportedSystems (system: let + + pkgs = import pkgsSrc { + inherit system; + + #crossSystem = { + # config = system; + #}; + + overlays = [ + (import ./nix/overlays/go_1_18.nix) + ]; + }; + + defaultAttrs = (import ./default.nix) { + inherit pkgs; + hostSystem = system; + #buildSystem = self.system; + garage = garage.packages."${system}".default; + selfRev = if self ? rev then self.rev else "UNKNOWN"; + }; + + in { + + defaultPackage = defaultAttrs.appImage; + + }); +} diff --git a/nix/dnsmasq.nix b/nix/dnsmasq.nix index debc7e9..d83dea1 100644 --- a/nix/dnsmasq.nix +++ b/nix/dnsmasq.nix @@ -1,7 +1,6 @@ { stdenv, - glibcStatic, }: stdenv.mkDerivation rec { @@ -13,11 +12,7 @@ sha256 = "sha256-rZjTgD32h+W5OAgPPSXGKP5ByHh1LQP7xhmXh/7jEvo="; }; - nativeBuildInputs = [ glibcStatic ]; - makeFlags = [ - "LDFLAGS=-static" - "DESTDIR=" "BINDIR=$(out)/bin" "MANDIR=$(out)/man" "LOCALEDIR=$(out)/share/locale" diff --git a/nix/garage.nix b/nix/garage.nix deleted file mode 100644 index 43e832a..0000000 --- a/nix/garage.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ - - fetchgit, - buildEnv, - minio-client, - -}: let - - version = "0.8.0-unstable"; - - src = fetchgit { - name = "garage-v${version}"; - url = "https://git.deuxfleurs.fr/Deuxfleurs/garage.git"; - rev = "293139a94a8911aaac1b650e4707379a972196aa"; - sha256 = "sha256-b6HHLnxMdmpngiywll6Egr8O9/4cqBN01Mj3OwVMeBc="; - }; - -in rec { - - garage = (import "${src}/default.nix") { git_version = version; }; - - minioClient = minio-client; - - env = buildEnv { - name = "cryptic-net-garage"; - paths = [ - garage.pkgs.amd64.release - minioClient - ]; - }; - -} - diff --git a/nix/overlays/go_1_18.nix b/nix/overlays/go_1_18.nix new file mode 100644 index 0000000..b8f01f0 --- /dev/null +++ b/nix/overlays/go_1_18.nix @@ -0,0 +1,21 @@ +# Make buildGoModules use static compilation by default, and use go 1.18 +# everywhere. +(final: prev: + + let + + buildArgs = { + doCheck = false; + CGO_ENABLED=0; + tags = [ "netgo" "timetzdata" ]; + ldflags = [ "-w" "-extldflags=-static" ]; + }; + + in { + + go = prev.go_1_18; + buildGoModule = args: prev.buildGo118Module (buildArgs // args); + buildGo118Module = args: prev.buildGo118Module (buildArgs // args); + + } +) diff --git a/nix/pkgs.nix b/nix/pkgs.nix deleted file mode 100644 index c17ea25..0000000 --- a/nix/pkgs.nix +++ /dev/null @@ -1,38 +0,0 @@ -rec { - - overlays = [ - - # Make buildGoModules use static compilation by default, and use go 1.18 - # everywhere. - (final: prev: - - let - - buildArgs = { - doCheck = false; - CGO_ENABLED=0; - tags = [ "netgo" "timetzdata" ]; - ldflags = [ "-w" "-extldflags=-static" ]; - }; - - in { - - go = prev.go_1_18; - buildGoModule = args: prev.buildGo118Module (buildArgs // args); - buildGo118Module = args: prev.buildGo118Module (buildArgs // args); - - } - ) - ]; - - version = "22-05"; - rev = "2aec372cdcd4d73b94863611fea70e0884270fdc"; - - src = fetchTarball { - name = "nixpkgs-${version}"; - url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; - sha256 = "1pbfhlh4v8l70p44gspsci3i6w0wk70vaisiawg3jhka2nxb8367"; - }; - - pkgs = import src { inherit overlays; }; -} diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..a8ec8d4 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +Release: 0.0.1