commit 09d7089598aed641f3e88e1dd8c34b496c5fdab8 Author: Florian Warzecha Date: Tue May 2 17:02:06 2023 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82e0cdf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/result \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..951be1d --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +docker image that allows to reuse the hosts nix store. + +Sample usage: `podman run --rm -it -v .:/workspace -v /nix/store:/nix/store:ro -v /nix/var/nix/db:/nix/var/nix/db:ro -v /nix/var/nix/daemon-socket:/nix/var/nix/daemon-socket:ro --env NIX_REMOTE=daemon --env PATH=/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:/bin nix-flake-docker` + +Push: `skopeo copy $"docker-archive://(readlink result | str trim)" docker://git.disroot.org/liketechnik/nix-flake-docker:latest` (after nix build) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7a650e0 --- /dev/null +++ b/flake.lock @@ -0,0 +1,78 @@ +{ + "nodes": { + "docker-nixpkgs": { + "flake": false, + "locked": { + "lastModified": 1678089139, + "narHash": "sha256-cK0RDcxR4eWMrdZIcqNVqnjo9k2LwVmNZO3qj1ctDXU=", + "owner": "nix-community", + "repo": "docker-nixpkgs", + "rev": "2205fb4968adf683324e6d0401b74b9d250d8f56", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "docker-nixpkgs", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1683014792, + "narHash": "sha256-6Va9iVtmmsw4raBc3QKvQT2KT/NGRWlvUlJj46zN8B8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "1a411f23ba299db155a5b45d5e145b85a7aafc42", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "docker-nixpkgs": "docker-nixpkgs", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8fca088 --- /dev/null +++ b/flake.nix @@ -0,0 +1,65 @@ +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + inputs.docker-nixpkgs = { + url = "github:nix-community/docker-nixpkgs"; + flake = false; + }; + + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { + nixpkgs, + flake-utils, + docker-nixpkgs, + ... + } @ inputs: + flake-utils.lib.eachSystem flake-utils.lib.allSystems ( + system: let + pkgs = import nixpkgs {inherit system;}; + gitReallyMinimal = + (pkgs.pkgsStatic.git.override { + perlSupport = false; + pythonSupport = false; + withManual = false; + withpcre2 = false; + }) + .overrideAttrs ( + _: { + # installCheck is broken when perl is disabled + doInstallCheck = false; + } + ); + in rec { + formatter = pkgs.alejandra; + + packages.default = pkgs.callPackage "${docker-nixpkgs}/images/nix-unstable-static" { + dockerTools = + pkgs.dockerTools + // { + buildImage = args: + # intentionally swap out buildImage with buildLayeredImage, + # otherwise podman load is unhappy + pkgs.dockerTools.buildLayeredImage (args + // { + extraCommands = + args.extraCommands + + '' + mkdir -pv -m 0755 nix/var/log/nix/drvs + mkdir -pv -m 0755 nix/var/nix/gcroots + mkdir -pv -m 0755 nix/var/nix/profiles + mkdir -pv -m 0755 nix/var/nix/temproots + mkdir -pv -m 0755 nix/var/nix/userpool + mkdir -pv -m 1777 nix/var/nix/gcroots/per-user + mkdir -pv -m 1777 nix/var/nix/profiles/per-user + mkdir -pv -m 0755 nix/var/nix/profiles/per-user/root + + cp -a ${gitReallyMinimal}/bin/* bin/ + rm_ref -t ${gitReallyMinimal} bin/git + ''; + }); + }; + }; + } + ); +}