This commit is contained in:
Florian Warzecha 2023-05-02 17:02:06 +02:00
commit 09d7089598
Signed by: liketechnik
GPG Key ID: 4BE8C7D97F910C60
4 changed files with 149 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/result

5
README.md Normal file
View File

@ -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)

78
flake.lock Normal file
View File

@ -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
}

65
flake.nix Normal file
View File

@ -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
'';
});
};
};
}
);
}