From 6764080cc7b2c5e0cfdf22cdcff1f8670ac70324 Mon Sep 17 00:00:00 2001 From: Louis Bettens Date: Sat, 23 Apr 2022 13:41:43 +0200 Subject: [PATCH] refactor nix flake --- .envrc | 2 +- default.nix | 3 +- flake.lock | 44 +++++++++++++++++-- flake.nix | 58 ++++++++++++++++---------- nix/devshell.nix | 3 ++ devshell.toml => nix/devshell.toml | 0 lib/compat.nix => nix/flake-compat.nix | 5 ++- shell.nix | 3 +- 8 files changed, 86 insertions(+), 32 deletions(-) create mode 100644 nix/devshell.nix rename devshell.toml => nix/devshell.toml (100%) rename lib/compat.nix => nix/flake-compat.nix (52%) diff --git a/.envrc b/.envrc index aba87b4..5effaa2 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1,2 @@ -watch_file devshell.toml use flake || use nix +watch_file flake.nix nix/devshell.* diff --git a/default.nix b/default.nix index a65e7d9..56ace42 100644 --- a/default.nix +++ b/default.nix @@ -1 +1,2 @@ -(import lib/compat.nix).defaultNix +# This file allows nix-build to find the flake +(import nix/flake-compat.nix).defaultNix diff --git a/flake.lock b/flake.lock index ec734ea..29076ae 100644 --- a/flake.lock +++ b/flake.lock @@ -15,13 +15,29 @@ "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": 1623875721, - "narHash": "sha256-A8BU7bjS5GirpAUv4QA+QnJ4CceLHkcXdRp4xITDB0s=", + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", "owner": "numtide", "repo": "flake-utils", - "rev": "f7e004a55b120c02ecb6219596820fcd32ca8772", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", "type": "github" }, "original": { @@ -30,6 +46,25 @@ "type": "github" } }, + "fup": { + "inputs": { + "flake-utils": "flake-utils" + }, + "locked": { + "lastModified": 1638172912, + "narHash": "sha256-jxhQGNEsZTdop/Br3JPS+xmBf6t9cIWRzVZFxbT76Rw=", + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "rev": "166d6ebd9f0de03afc98060ac92cba9c71cfe550", + "type": "github" + }, + "original": { + "owner": "gytis-ivaskevicius", + "ref": "v1.3.1", + "repo": "flake-utils-plus", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1624553300, @@ -47,7 +82,8 @@ "root": { "inputs": { "devshell": "devshell", - "flake-utils": "flake-utils", + "flake-compat": "flake-compat", + "fup": "fup", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index 8c2dc17..7e549c3 100644 --- a/flake.nix +++ b/flake.nix @@ -12,33 +12,45 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# The flake file is the entry point for nix commands { description = "guest NixOS images with minimal footprint"; + # Inputs are how Nix can use code from outside the flake during evaluation. inputs.devshell.url = "github:numtide/devshell"; - inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.fup.url = "github:gytis-ivaskevicius/flake-utils-plus/v1.3.1"; + inputs.flake-compat.url = "github:edolstra/flake-compat"; + inputs.flake-compat.flake = false; - outputs = inputs@{ self, nixpkgs, devshell, flake-utils }: - with flake-utils.lib; - let - overlay = import tool/overlay.nix; - in - { - nixosModules.core = import ./core; - nixosModules.declarative = import ./declarative inputs; - inherit overlay; - defaultTemplate = { - description = "Example guest configurations"; - path = ./template; + # Outputs are the public-facing interface to the flake. + outputs = inputs@{ self, devshell, fup, nixpkgs, ... }: fup.lib.mkFlake { + + inherit self inputs; + + sharedOverlays = [ + devshell.overlay + self.overlay + ]; + + overlay = import tool/overlay.nix; + + nixosModules.core = import ./core; + nixosModules.declarative = import ./declarative inputs; + + defaultTemplate = { + description = "Example guest configurations"; + path = ./template; + }; + + outputsBuilder = channels: rec { + packages = rec { + inherit (channels.nixpkgs) miniguest; + default = miniguest; }; - } // eachDefaultSystem (system: - let pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; }; - in - { - packages.miniguest = pkgs.miniguest; - defaultPackage = pkgs.miniguest; - defaultApp = mkApp { drv = pkgs.miniguest; }; - devShell = devshell.legacyPackages.${system}.fromTOML ./devshell.toml; - checks = import ./checks inputs system; - }); + defaultPackage = packages.default; + defaultApp = fup.lib.mkApp { drv = packages.default; }; + devShell = channels.nixpkgs.callPackage nix/devshell.nix { }; + checks = import ./checks inputs channels.nixpkgs.system; + }; + }; } diff --git a/nix/devshell.nix b/nix/devshell.nix new file mode 100644 index 0000000..94f2f99 --- /dev/null +++ b/nix/devshell.nix @@ -0,0 +1,3 @@ +{ devshell }: + +devshell.fromTOML ./devshell.toml diff --git a/devshell.toml b/nix/devshell.toml similarity index 100% rename from devshell.toml rename to nix/devshell.toml diff --git a/lib/compat.nix b/nix/flake-compat.nix similarity index 52% rename from lib/compat.nix rename to nix/flake-compat.nix index 61eae4b..99417d7 100644 --- a/lib/compat.nix +++ b/nix/flake-compat.nix @@ -1,8 +1,9 @@ let - rev = "99f1c2157fba4bfe6211a321fd0ee43199025dbf"; + lock = builtins.fromJSON (builtins.readFile ../flake.lock); + inherit (lock.nodes.flake-compat.locked) rev narHash; flake-compat = fetchTarball { url = "https://github.com/edolstra/flake-compat/archive/${rev}.tar.gz"; - sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; + sha256 = narHash; }; in import flake-compat { src = ./..; } diff --git a/shell.nix b/shell.nix index e45069f..e83e18c 100644 --- a/shell.nix +++ b/shell.nix @@ -1 +1,2 @@ -(import lib/compat.nix).shellNix +# This file allows nix-shell to find the flake +(import nix/flake-compat.nix).shellNix