diff --git a/.version b/.version new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +0.0.1 diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..f8a169d --- /dev/null +++ b/default.nix @@ -0,0 +1,9 @@ +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; } +) { + src = ./.; +}).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1cac823 --- /dev/null +++ b/flake.lock @@ -0,0 +1,39 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1603796912, + "narHash": "sha256-6ayqpH/4XiEXylNdWI3AghubqS6XuiPg3Y60jY8RTo4=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "19576c2aea7f074ff0da818b21a8b0950ff6ec86", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "narHash": "sha256-gnopQLNQVt3pWBUT9gsPWmfDaYmQF4H5+k6QJmpuZdI=", + "path": "/nix/store/ipbl0zskimmqm7zm7qrh4nbrfk3jgmvi-source", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e142833 --- /dev/null +++ b/flake.nix @@ -0,0 +1,67 @@ +{ + + inputs = { + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + outputs = { self, nixpkgs, ... }: + let + + version = builtins.replaceStrings [ "\n" ] [ "" ] + (builtins.readFile ./.version + versionSuffix); + versionSuffix = if officialRelease then + "" + else + "pre${ + nixpkgs.lib.substring 0 8 (self.lastModifiedDate or self.lastModified) + }_${self.shortRev or "dirty"}"; + + officialRelease = false; + + systems = [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" ]; + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system); + + # Memoize nixpkgs for different platforms for efficiency. + nixpkgsFor = forAllSystems (system: + import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }); + in { + overlay = final: prev: { + ifconfigio = with final; + with pkgs; + (buildGoModule { + name = "ifconfig.io-${version}"; + + src = self; + vendorSha256 = + "sha256-Xyf/K7pu87cRNGMpVQoVqiJ6s+Xpw0N7NDg7vqLFErk="; + + postInstall = '' + mkdir -p $out/usr/lib/ifconfig.io/ + cp -r ./templates $out/usr/lib/ifconfig.io + ''; + + }); + }; + packages = + forAllSystems (system: { inherit (nixpkgsFor.${system}) ifconfigio; }); + defaultPackage = + forAllSystems (system: self.packages.${system}.ifconfigio); + + nixosModules.ifconfigio = { pkgs, ... }: { + nixpkgs.overlays = [ self.overlay ]; + systemd.packages = [ pkgs.ifconfigio ]; + users.users.ifconfigio = { + description = "ifconfig.io daemon user"; + group = "ifconfigio"; + isSystemUser = true; + }; + users.groups.ifconfigio = { }; + }; + + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..b769069 --- /dev/null +++ b/shell.nix @@ -0,0 +1,9 @@ +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; } +) { + src = ./.; +}).shellNix