From 1be0e51b91befa69596de8ee29b7911c9fc35db2 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Wed, 13 Sep 2023 14:24:26 -0400 Subject: [PATCH] separate out container, add shell --- VERSION.txt | 1 + container.nix | 13 +++++++++++++ flake.nix | 30 +++++++++++------------------- shell.nix | 5 +++++ 4 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 VERSION.txt create mode 100644 container.nix create mode 100644 shell.nix diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +0.1.0 diff --git a/container.nix b/container.nix new file mode 100644 index 0000000..7da1c9a --- /dev/null +++ b/container.nix @@ -0,0 +1,13 @@ +{ pkgs, package }: + +pkgs.dockerTools.buildImage { + name = package.pname; + tag = [ "latest" "0.1.0" ]; #package.version + created = "now"; + copyToRoot = pkgs.buildEnv { + name = "image-root"; + paths = [ package ]; + pathsToLink = [ "/bin" ]; + }; + config.Cmd = [ "${package}/bin/hello" ]; +} diff --git a/flake.nix b/flake.nix index 3598d45..59fec95 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,10 @@ { - description = "An over-engineered Hello World in C"; + description = "A Nix Flake example for ANSI C using GNU Autoconf"; + + nixConfig = { + bash-prompt = "\\[\\e[34;1m\\]flake.nix ~ \\[\\e[0m\\]"; + }; - # Nixpkgs / NixOS version to use. inputs = { nixpkgs.url = "github:nixos/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; @@ -11,8 +14,8 @@ let lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; - # Generate a user-friendly version number for our target. - version = builtins.substring 0 8 lastModifiedDate; + # Generate a user-friendly version number (e.g. "1.2.3-20231027-DIRTY"). + version = "${builtins.readFile ./VERSION.txt}.${builtins.substring 0 8 (self.lastModifiedDate or "19700101")}.${self.shortRev or "DIRTY"}"; # System types to support. supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; @@ -40,25 +43,14 @@ }) ]; }; - in rec { + in rec { packages = { inherit (pkgs) hello; }; packages.default = self.packages.${system}.hello; - packages.container = pkgs.dockerTools.buildImage { - name = "hello"; - tag = "0.1.0"; - created = "now"; - copyToRoot = pkgs.buildEnv { - name = "image-root"; - paths = [ packages.default ]; - pathsToLink = [ "/bin" ]; - }; - config.Cmd = [ "${packages.default}/bin/hello" ]; - }; - - apps.hello = flake-utils.lib.mkApp { drv = packages.hello; }; + packages.container = pkgs.callPackage ./container.nix { package = packages.default; }; + apps.hello = flake-utils.lib.mkApp { drv = packages.default; }; defaultApp = apps.hello; - # devShells.default = import ./shell.nix { inherit pkgs; }; +# devShells.default = import ./shell.nix { inherit pkgs; }; } ); } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..d25767b --- /dev/null +++ b/shell.nix @@ -0,0 +1,5 @@ +{ pkgs ? import {} }: +pkgs.mkShell { + # nativeBuildInputs is usually what you want -- tools you need to run + #nativeBuildInputs = with pkgs.buildPackages; [ ]; +}